Hi,
Thank you for reaching out to the Google Ads Scripts support team.
I would like to inform you that the "AdsApp.search()" method you are using will only support search and display type of campaigns. I would suggest that you create a script by referring to the documents “AdsApp.VideoPlacement”, “AdsApp.VideoPlacementSelector”, and “columns” and you can exclude a placement list by referring to the sample code in the “document”.
I hope this helps. Kindly get back to us if you still face any issues.
![]() |
Google Ads Scripts Team |
HI Team,
I have modified the script as per your suggestion, could you please check why is it not fetching the data in log while it is executed without any error.
Here is the code-
function main() {
var CAMPAIGN_NAME_CONTAINS = ''; // Leave empty to target all campaigns
var MIN_IMPRESSIONS = 100;
var MIN_VIEW_RATE = 0.10; // 10%
// Calculate date range for last 6 months
var endDate = new Date();
var startDate = new Date();
startDate.setDate(endDate.getDate() - 180);
// Format dates as required by the API
var formattedStartDate = formatDate(startDate);
var formattedEndDate = formatDate(endDate);
var campaignIterator = AdsApp.videoCampaigns()
.withCondition("CampaignStatus IN ['ENABLED', 'PAUSED']");
if (CAMPAIGN_NAME_CONTAINS) {
campaignIterator = campaignIterator
.withCondition("CampaignName CONTAINS '" + CAMPAIGN_NAME_CONTAINS + "'");
}
campaignIterator = campaignIterator.get();
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
var videoTargeting = campaign.videoTargeting();
var placementIterator = videoTargeting.youTubeChannels() // Changed from placements() to youTubeChannels()
.forDateRange(formattedStartDate, formattedEndDate)
.withCondition("Impressions >= " + MIN_IMPRESSIONS)
.get();
while (placementIterator.hasNext()) {
var placement = placementIterator.next();
var stats = placement.getStatsFor(formattedStartDate, formattedEndDate);
var impressions = stats.getImpressions();
var views = stats.getViews();
var viewRate = views / impressions;
if (viewRate < MIN_VIEW_RATE) {
try {
videoTargeting.excludeYouTubeChannel(placement.getChannelId()); // Changed to excludeYouTubeChannel
Logger.log('Excluded channel ' + placement.getChannelName() + ' (ID: ' + placement.getChannelId() + ') from campaign ' + campaign.getName() +
' (Status: ' + campaign.getStatus() + ') due to low view rate: ' +
(viewRate * 100).toFixed(2) + '%');
} catch (e) {
Logger.log('Failed to exclude channel ' + placement.getChannelName() + ' (ID: ' + placement.getChannelId() + ') from campaign ' + campaign.getName() +
' (Status: ' + campaign.getStatus() + '). Error: ' + e.toString());
}
}
}
}
}
// Helper function to format date as required by the API
function formatDate(date) {
return {
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate()
};
}
Output Ref-
Best regards
Rahul (RULK)
|
From: Google Ads Scripts Forum on behalf of adsscripts <adwords...@googlegroups.com>
Sent: Wednesday, June 26, 2024 5:10 PM
To: adwords...@googlegroups.com
Subject: RE: google ad script to exclude those placements that have more than 100 impressions & less than 10% of view rate
Caution: This email originated from outside of the Novo Nordisk email system. Use caution when clicking on links or opening attachments.
--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit
https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/adwords-scripts/ZCWOFtgM00M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
adwords-scrip...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-scripts/3McK9000000000000000000000000000000000000000000000SFOR3600NWeWYKbsQcKXTwTyE_aQMw%40sfdc.net.
Hi
@Sigurd - Thanks for the insights.
I would suggest that you follow the Sigurd’s suggestion and try executing the script. If you still face any issues, kindly get back to us with the below details.
Hi Team,
Here is the details:
CID - 960-878-5592
Script Name: Exclude placement
Best regards
Rahul (RULK)
|