Hello,
I am trying to make a youtube exclusions script that looks at the last 30 days of data on the account level and adds certain youtube channels to an exclusion list based on the following criteria:
1. channel title does not contain latin or germanic characters
2. channel contains certain children's keywords such as "minecraft"
I keep getting an error like this:
Ga: 'ad_group_id' is not a valid field in AD_PERFORMANCE_REPORT. Please check your spelling and casing. at main (Code:22:27) I've tried puling the group view field as well. here is my code:
function main() {
const keywords = ['minecraft', 'skibidi', 'cocomelon', 'peppa pig', 'roblox'];
const channels = [];
const dateRangeStart = getDateNDaysAgo(30);
const dateRangeEnd = getFormattedDate(new Date());
// Query for YouTube channel placements over the last 30 days
const query = `
SELECT
ad_group_id,
ad_group_name,
creative_id,
creative_name,
placement_url
FROM
AD_PERFORMANCE_REPORT
WHERE
placement_type = 'YOUTUBE_CHANNEL'
AND segments.date >= '${dateRangeStart}'
AND segments.date <= '${dateRangeEnd}'`;
const report = AdsApp.report(query);
const rows = report.rows();
while (rows.hasNext()) {
const row = rows.next();
const channelName = row.creative_name;
const placementUrl = row.placement_url;
// Check if the channel name contains non-Latin or non-Germanic characters
if (containsNonLatinCharacters(channelName) || containsKeywords(channelName, keywords)) {
channels.push({
name: channelName,
url: placementUrl
});
}
}
// Output the results
if (channels.length > 0) {
Logger.log('YouTube Channels Meeting Criteria:');
channels.forEach(channel => {
Logger.log(`Name: ${channel.name}, URL: ${channel.url}`);
});
} else {
Logger.log('No YouTube channels found matching the criteria.');
}
}
// Function to get the date N days ago in YYYY-MM-DD format
function getDateNDaysAgo(n) {
const date = new Date();
date.setDate(date.getDate() - n);
return getFormattedDate(date);
}
// Function to format a date in YYYY-MM-DD format
function getFormattedDate(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are zero-based
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}
// Function to check if a string contains non-Latin or non-Germanic characters
function containsNonLatinCharacters(str) {
// Regular expression for non-Latin characters
const nonLatinRegex = /[^\u0000-\u007F]+/;
return nonLatinRegex.test(str);
}
// Function to check if the channel name contains any specified keywords
function containsKeywords(str, keywords) {
return keywords.some(keyword => str.toLowerCase().includes(keyword.toLowerCase()));
}
Hi,
Thank you for reaching out to the Google Ads Scripts support team.
@Nils - thank you for providing your insights to the user.
I would like to inform you that the metrics “creative_id and creative_name” are not supported fields in the Google Ads Scripts. Kindly refer to the Google Ads Query Builder to add or remove fields. I would suggest that you use the query provided by Nils and get back to us with the below details if you still face any issues.
![]() |
Google Ads Scripts Team |
--
-- 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 the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/Beno3000000000000000000000000000000000000000000000SKME3X00-0aCO_eaTOSvYwFVu3mviQ%40sfdc.net.