function main() {
const CUSTOMER_ID = 'my-account-id';
const DEMAND_GEN_CAMPAIGN_ID = my-demand-gen-campaign-id;
const VIDEO_CAMPAIGN_ID = my-video-campaign-id;
const query =
`SELECT
campaign.id,
asset.youtube_video_asset.youtube_video_id,
asset.youtube_video_asset.youtube_video_title
FROM ad_group_ad_asset_view
WHERE
campaign.id IN (${ACTIVE_CAMPAIGN_ID}, ${PAUSED_CAMPAIGN_ID})
AND asset.type = 'YOUTUBE_VIDEO'`
;
// 1) pick and select your child account
const accountIt = AdsManagerApp
.accounts()
.withIds([ CUSTOMER_ID ])
.get();
if (!accountIt.hasNext()) {
Logger.log('No such account: ' + CUSTOMER_ID);
return;
}
AdsManagerApp.select(accountIt.next());
// 2) run the query
const rows = AdsApp.search(query); // returns a SearchRowIterator :contentReference[oaicite:0]{index=0}
// 3) build a plain array of results
const result = [];
while (rows.hasNext()) {
const row = rows.next();
// SearchRow fields are nested JS objects; use dot‐notation:
// row.asset.youtubeVideoAsset.youtubeVideoId etc :contentReference[oaicite:1]{index=1}
const youtube = row.asset && row.asset.youtubeVideoAsset;
if (youtube) {
result.push({
campaignId:
row.campaign.id,
id: youtube.youtubeVideoId,
title: youtube.youtubeVideoTitle
});
}
}
// 4) now JSON.stringify the *array*, not the iterator
Logger.log(JSON.stringify(result, null, 2));
}
so when I running this from Google Ads Script, it only can returns youtube video id and title for my Demand-gen campaigns, and simply returns empty array for my Video campaigns.
Why it happened, and is there a way to get Youtube videos assets of my campaigns regardless of their type?