fetching impressions, click and conversions for headlines and descriptions

105 views
Skip to first unread message

Yaniv Lev-Ari

unread,
Aug 20, 2024, 11:23:22 AM8/20/24
to Google Ads Scripts Forum
Hello,

I am trying to fetch all headlines and descriptions from my search ads,
to show impressions, clicks and conversions of each one,
but when I run this code :

function main(){  
var campaignName = "my search campaign";
 
  var campaign = AdsApp.campaigns()
    .withCondition("Name = '" + campaignName + "'")
    .get().next();


  // Get ad groups within the campaign
  var adGroups = campaign.adGroups().get();

  // Iterate through ad groups
  while (adGroups.hasNext()) {
    var adGroup = adGroups.next();
    var adGroupIterator = adGroup.ads().withCondition("Status = ENABLED").get();

    // Iterate through ads
    while (adGroupIterator.hasNext()) {
      var ad = adGroupIterator.next();
      var adStats = ad.getStatsFor('TODAY'); // Adjust date range as needed
   

      Logger.log('Ad ID: ' + ad.getId());
      Logger.log('Headline 1: ' + ad.getHeadline());
      // Note: Commenting out access to non-existent headline function
      // Logger.log('Headline 2: ' + ad.getHeadline2());
      Logger.log('Description1: ' + ad.getDescription1());
      Logger.log('Description1: ' + ad.getDescription2());
     
      Logger.log('Impressions: ' + adStats.getImpressions());
      Logger.log('Clicks: ' + adStats.getClicks());
      Logger.log('Conversions: ' + adStats.getConversions());
      Logger.log('--------------------');
    }
  }
}

I get null results: 

Ad ID: 643574125150

Headline 1: null

Description1: null

Description1: null

Impressions: 10

Clicks: 4

Conversions: 0


Please advise

Google Ads Scripts Forum Advisor

unread,
Aug 20, 2024, 3:43:04 PM8/20/24
to adwords...@googlegroups.com
Hi,

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

In order to investigate the issue further, please share with us the following details
  • Google Ads account ID or CID
  • Name of the affected script
You can send the details via Reply privately to the author option, or direct private reply to this email.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02vFANo:ref" (ADR-00264043)

Thanks,
 
Google Logo Google Ads Scripts Team


Message has been deleted

Yaniv Lev-Ari

unread,
Aug 22, 2024, 5:18:43 AM8/22/24
to Google Ads Scripts Forum
It seems I have no permission to reply privately or send direct reply. 
What can we do about it so I can get some help? 

ב-יום שלישי, 20 באוגוסט 2024 בשעה 22:43:04 UTC+3, Google Ads Scripts Forum Advisor כתב/ה:

Phuong Le

unread,
Aug 22, 2024, 10:58:48 PM8/22/24
to Yaniv Lev-Ari דרך Google Ads Scripts Forum
hello

--
-- 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/4389f20b-cb1f-4442-817f-0147deae4cf5n%40googlegroups.com.

Yaniv Lev-Ari

unread,
Aug 25, 2024, 8:49:48 AM8/25/24
to Google Ads Scripts Forum
Hello :)

ב-יום שישי, 23 באוגוסט 2024 בשעה 05:58:48 UTC+3, Phuong Le כתב/ה:

Google Ads Scripts Forum Advisor

unread,
Aug 26, 2024, 3:12:29 AM8/26/24
to adwords...@googlegroups.com

Hi,

In order to investigate the issue further,kindly provide us with the below details

Yaniv Lev-Ari

unread,
Aug 26, 2024, 5:32:26 AM8/26/24
to Google Ads Scripts Forum
sent by email
Thanks

ב-יום שלישי, 20 באוגוסט 2024 בשעה 22:43:04 UTC+3, Google Ads Scripts Forum Advisor כתב/ה:
Hi,

Yaniv Lev-Ari

unread,
Aug 31, 2024, 9:01:42 AM8/31/24
to Google Ads Scripts Forum

Any news?
ב-יום שני, 26 באוגוסט 2024 בשעה 12:32:26 UTC+3, Yaniv Lev-Ari כתב/ה:

Google Ads Scripts Forum Advisor

unread,
Sep 2, 2024, 4:49:01 AM9/2/24
to adwords...@googlegroups.com

Hi Yaniv,

As informed earlier, the getHeadline() method is returning a null value because the ad type is text ad. As you are trying to get the headline and description for responsive search ads (RSA), you may use the getHeadlines and getDescriptions methods from the AdsApp.​ResponsiveSearchAd.

Additionally, you may use the ad_group_ad_asset_view report to fetch the headline and description. Please check the below query:

SELECT campaign.namead_group_ad.ad.id, 
ad_group_ad.ad.responsive_search_ad.headlines, ad_group_ad.ad.responsive_search_ad.descriptions, 
metrics.clicks, metrics.impressions, 
metrics.conversions 
FROM ad_group_ad_asset_view 
WHERE metrics.impressions > 0 AND 
segments.date DURING LAST_30_DAYS

Hope this clarifies! Let us know if you have any further questions. 

Yaniv Lev-Ari

unread,
Sep 2, 2024, 3:56:49 PM9/2/24
to Google Ads Scripts Forum
I tried this solution like this:

function main() {
  var query = `
    SELECT
    campaign.name,
    ad_group_ad.ad.id,
    ad_group_ad_asset_view.asset,
    ad_group_ad_asset_view.field_type,
    ad_group_ad.ad.responsive_search_ad.headlines,
    metrics.impressions,
    metrics.clicks,
    metrics.conversions
    FROM
      ad_group_ad_asset_view
    WHERE
      metrics.clicks > 0
      AND segments.date DURING LAST_30_DAYS
      AND campaign.name = '????????????'
  `;

  var report = AdsApp.report(query);
  var rows = report.rows();

  while (rows.hasNext()) {
    var row = rows.next();
    Logger.log('Campaign: ' + row['campaign.name']);
    Logger.log('Ad ID: ' + row['ad_group_ad.ad.id']);
    Logger.log('Field Type: ' + row['ad_group_ad_asset.field_type']);
    Logger.log('headlines: ' + row['ad_group_ad.ad.responsive_search_ad.headlines']);
    Logger.log('Text: ' + row['ad_group_ad_asset.asset.text']);
    Logger.log('Impressions: ' + row['metrics.impressions']);
    Logger.log('Clicks: ' + row['metrics.clicks']);
    Logger.log('Conversions: ' + row['metrics.conversions']);
    Logger.log('--------------------');
  }
}

and got this:

Campaign: ***********

Ad ID: 3282........

Field Type: undefined

headlines: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Text: undefined

Impressions: 203

Clicks: undefined

Conversions: undefined


What do I need to change, to view how many impressions, clicks, and conversions got each headline from my responsive ads? 


ב-יום שני, 2 בספטמבר 2024 בשעה 11:49:01 UTC+3, Google Ads Scripts Forum Advisor כתב/ה:

Google Ads Scripts Forum Advisor

unread,
Sep 3, 2024, 4:32:39 AM9/3/24
to adwords...@googlegroups.com

Hi Yaniv,

Unfortunately, it is not possible in the Google Ads API to pull the performance data except impressions for RSA assets. The “ad_group_ad_asset_view” only exposes metrics.impressions for assets that are part of an ad_group_ad of type RESPONSIVE_SEARCH_AD (RSA). This means that if several metrics are included in the search query, only “metrics.impressions” will be returned for rows that correspond to an RSA. I would recommend that you use the below code to display the headlines data.

while (rows.hasNext()) {

    var row = rows.next();

    const jsonString = JSON.stringify(row);

    const data = JSON.parse(jsonString);

    findHeadlinesAndDescriptions(data);

  }

  }

function findHeadlinesAndDescriptions(obj, context) {

  if (typeof obj === 'object') {

    for (const key in obj) {

      if (Array.isArray(obj[key])) {

        for (const item of obj[key]) {

          findHeadlinesAndDescriptions(item, key);

        }

      } else if (typeof obj[key] === 'object') {

        findHeadlinesAndDescriptions(obj[key], key);

      } else if (key === 'text') {

        console.log(`${context === 'headlines' ? 'Headline' : 'Description'}: ${obj[key]}`);

      } else if (key === 'assetPerformanceLabel') {

        console.log(`Asset Performance Label: ${obj[key]}`);

      }

    }

  }

}

I hope this helps! Kindly get back to us if you still face any issues.



ref:!00D1U01174p.!5004Q02vFANo:ref
Reply all
Reply to author
Forward
0 new messages