Script error for performance max result

128 views
Skip to first unread message

Acquisition EG

unread,
May 9, 2023, 3:35:18 PM5/9/23
to Google Ads Scripts Forum
Hi team, 

I am trying to run thisscript to get performance max result per network but I keep getting an error message:
function main() {
  var report = AdsApp.report(
    'SELECT AdNetworkType2, Clicks, Impressions, Cost ' +
    'FROM AD_PERFORMANCE_REPORT ' +
    'WHERE CampaignStatus = ENABLED ' +
    'AND AdvertisingChannelType = "DISPLAY" ' +
    'AND CampaignStatus = ENABLED ' +
    'AND Status = ENABLED ' +
    'DURING LAST_7_DAYS');

  var rows = report.rows();
  while (rows.hasNext()) {
    var row = rows.next();
    var networkType = row['AdNetworkType2'];
    var clicks = row['Clicks'];
    var impressions = row['Impressions'];
    var cost = row['Cost'];

    Logger.log(networkType + ': ' + clicks + ' clicks, ' +
        impressions + ' impressions, $' + cost);
  }
}

Could you please help?
Thank you, 

Nils Rooijmans

unread,
May 10, 2023, 4:09:02 AM5/10/23
to Google Ads Scripts Forum
unfortunately, a lot of the data in PMax is hidden from us.
AdvertisingChannelType  , or Network type in the new API, only returns "cross network" which won't help you very much.

The best script currently out there that I know of is the PMax insights script by Mike Rhodes.

see https://github.com/agencysavvy/pmax


Hope this helps,

Nils Rooijmans
https://nilsrooijmans.com
See my Google Ads Scripts FAQ to avoid the same mistakes I made: https://nilsrooijmans.com/google-ads-scripts-faq/

Google Ads Scripts Forum Advisor

unread,
May 10, 2023, 4:31:12 AM5/10/23
to adwords...@googlegroups.com

Hello,

 

Thank you for reaching out to the Google Ads Scripts Team's Forum Channel.

 

Upon checking, I've observed that the query the script is using still conforms to the AdWords Query Language which the legacy version makes use of. Please do note that the legacy version is deprecated, and scripts still conforming to the said version will not perform as expected. Kindly note that, currently, Google Ads Scripts' reporting infrastructure is backed by the Google Ads API and uses the Google Ads Query Language. With this, we would recommend you migrate the script to the new script experience version to ensure continued functionality.

 

You may do so by following our migration guide. I've also included a link below for a report example. I believe the resource mapping documentation and our query migration tool are helpful when migrating queries, as it lists which Google Ads API field each resource field maps to. Since you're using the AD_PERFORMANCE_REPORT, this maps to the ad_group_ad report. Also, I've noticed that there are two fields for CampaignStatus which both filter to ENABLED; kindly only make use of one. After migrating your query, it results to the one below:

SELECT segments.ad_network_type, metrics.clicks, metrics.impressions, metrics.cost_micros FROM ad_group_ad WHERE campaign.status = 'ENABLED' AND campaign.advertising_channel_type = 'DISPLAY' AND ad_group_ad.status = 'ENABLED' AND segments.date DURING LAST_7_DAYS

 

Kindly make use of this query instead and let us know if an issue would persist along with your Google Ads account ID and the name of the script in the account so we're able to further investigate.

 

Reference links:

 

Best regards,

 

Google Logo Google Ads Scripts Team


ref:_00D1U1174p._5004Q2lC5tK:ref

aswini kumar palo

unread,
May 11, 2023, 1:56:11 AM5/11/23
to Acquisition EG via Google Ads Scripts Forum
Hi,

In the provided code, there is an error in the query string of the AdsApp.report() method. The error is that the query string is missing a space before the "DURING" keyword. To fix the error, you should add a space before "DURING" keyword in the query string. Here's the corrected code:


function main() {
  var report = AdsApp.report(
    'SELECT AdNetworkType2, Clicks, Impressions, Cost ' +
    'FROM AD_PERFORMANCE_REPORT ' +
    'WHERE CampaignStatus = ENABLED ' +
    'AND AdvertisingChannelType = "DISPLAY" ' +
    'AND CampaignStatus = ENABLED ' +
    'AND Status = ENABLED ' +
    'DURING LAST_7_DAYS');

  var rows = report.rows();
  while (rows.hasNext()) {
    var row = rows.next();
    var networkType = row['AdNetworkType2'];
    var clicks = row['Clicks'];
    var impressions = row['Impressions'];
    var cost = row['Cost'];

    Logger.log(networkType + ': ' + clicks + ' clicks, ' +
        impressions + ' impressions, $' + cost);
  }
}

Let me know, if it works for you.

--
-- 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/145e6f7d-6e84-4d46-8462-26c3013da6e6n%40googlegroups.com.

Google Ads Scripts Forum

unread,
May 12, 2023, 5:34:17 AM5/12/23
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/LhiQ1NLwRg8) from the forum as it wasn't routed to our support queue.

Regards,
Google Ads Scripts Team

Google Ads Scripts Forum Advisor

unread,
May 12, 2023, 7:19:42 AM5/12/23
to adwords...@googlegroups.com

Hi All,

 

@Aswinik - Thank you for your insights. However, it appears that the error is not due to not placing a whitespace before DURING as the initial post has a whitespace before it, but rather the usage of the field `AdvertisingChannelType`. In order to resolve it, I would recommend utilizing the query in our team's previous response as it also conforms to the Google Ads Query Language.

 

If further assistance from our team is needed, please let us know. If an error would be encountered, kindly provide your Google Ads account ID or CID, the name of the script and a screenshot of the error so that we may be able to investigate further.

Reply all
Reply to author
Forward
0 new messages