Hello,
Is it possible to have google automatically add YouTube placement exclusions based on certain criteria in the channel names?
I am trying to make a script that excludes channels with characters in their title that do not match latin or germanic.
I am also trying to have it filter our children's keywords.
It keeps breaking with 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 have tried various placement group fields from google's API doc.
Here is my code currently: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()));
}