I want to add new columns to the Account Summary Report: https://developers.google.com/google-ads/scripts/docs/solutions/account-summary

But I'm getting an error.

'report_fields': [ {'columnName': 'metrics.cost_micros', 'displayName': 'Cost'}, {'columnName': 'metrics.average_cpc', 'displayName': 'Avg. CPC'}, {'columnName': 'metrics.ctr', 'displayName': 'CTR'}, {'columnName': 'metrics.search_impression_share', 'displayName': 'Search Impr. share'}, {'columnName': 'metrics.impressions', 'displayName': 'Impressions'}, {'columnName': 'metrics.clicks', 'displayName': 'Clicks'}, {'columnName': 'metrics.conversions', 'displayName': 'Conversions'}, {'columnName': 'metrics.conversions_value', 'displayName': 'Revenue'}, {'columnName': 'metrics.cost_per_conversion', 'displayName': 'CPA'}, {'columnName': 'metrics.conversions_from_interactions_rate', 'displayName': 'CVR'} 

--- Error---

Error: Unknown field metrics.conversions     at format (Code:174:13)     at Code:97:33     at Array.map (<anonymous>)     at main (Code:96:55) 

Tag:google-ads-api, google-ads-script

4 comments.

  1. dorian

    The Ads Script code you linked to contains a function which correctly formats the different metrics being downloaded:

    function format(column, value) { switch (column) { case 'metrics.clicks': case 'metrics.impressions': return value; case 'metrics.ctr': return formatPercentage(value); case 'metrics.average_cpc': case 'metrics.cost_micros': return formatMicros(value); case 'metrics.search_impression_share': return formatImpressionShare(value); default: throw new Error(`Unknown field ${column}`); } }

    You'll notice that every metric is individually listed. If you add metrics.conversions to the set of fields being downloaded, you'll need to adjust the format function as well—otherwise you'll encounter the "Error: Unknown field metrics.conversions" exception which is thrown in the default case.

    As metrics.conversions is a regular number, you can just add a case for it at the top:

    function format(column, value) { switch (column) { case 'metrics.clicks': case 'metrics.impressions': case 'metrics.conversions': return value; case 'metrics.ctr': return formatPercentage(value); case 'metrics.average_cpc': case 'metrics.cost_micros': return formatMicros(value); case 'metrics.search_impression_share': return formatImpressionShare(value); default: throw new Error(`Unknown field ${column}`); } }
    1. viovco

      Perfect thanks @dorian, it works, the script runs fine, but it logs a TypeError. TypeError: newValue.indexOf is not a function at formatChangeString (Code:366:33) at emailRow (Code:314:11) at Code:285:15 at Array.forEach () at sendEmail (Code:284:17) at main (Code:106:7) Do you know what this could be?

    2. dorian

      Please create a new question for this problem. This will make it easier to see the full stack trace, for example.

    3. viovco

      It's here: stackoverflow.com/questions/73627493/… // Hope you can help :)

Add a new comment.