google-ads-apigoogle-ads-script

Error: Unknown field metrics.conversions - Google Ads Scripts Account Summary Report - Adding new columns


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)

Solution

  • 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}`);
      }
    }