Cannot get Youtube video asset of VIDEO campaign, but it can for DEMAND GEN campaign

64 views
Skip to first unread message

Ngoc Tien Tran

unread,
Jun 16, 2025, 1:55:31 AM6/16/25
to Google Ads Scripts Forum
I have this code:
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? 

Thankyou

Google Ads Scripts Forum Advisor

unread,
Jun 16, 2025, 4:17:20 AM6/16/25
to adwords...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads Scripts support team.

The reason you're seeing data for your Demand Gen campaigns is the ad_group_ad_asset_view resource. This resource supports data retrieval for App Ads, Demand Gen campaigns, and Responsive Search Ads.

Currently, it's not possible to fetch YouTube video assets for campaigns using this resource. If you need to retrieve YouTube video assets, you need to use the 'asset' resource. Note that this resource does not include campaign-related fields and does not contain metrics. You can try the following GAQL query:
SELECT asset.id, asset.name, asset.type, 
asset.policy_summary.approval_status, asset.policy_summary.review_status, 
asset.youtube_video_asset.youtube_video_title, asset.youtube_video_asset.youtube_video_id 
FROM asset WHERE asset.type = 'YOUTUBE_VIDEO' 
Additionally, you can utilize the Query Builder and Query Validator to build and validate your queries.

If you encounter any issues, please share the details below:
  • CID of the Google Ads account 
  • Script name 
You can send the details via Reply privately to the author option, or direct private reply to this email.
 
Thanks,
 
Google Logo Google Ads Scripts Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-06-16 08:16:40Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01rfL5z:ref" (ADR-00314475)



Reply all
Reply to author
Forward
0 new messages