keyword_match_type field in v17 Campaign Report

42 views
Skip to first unread message

Q Florence

unread,
Jun 26, 2024, 8:28:22 PM (6 days ago) Jun 26
to Google Ads Scripts Forum
Hi, 

I'm using the script below to pull just campaign data with the aim of including keyword match type. This seems to be a new addition in v17 but when I include v17 in the query, I still don't get any output for keyword match type. All other fields are outputting fine. Any help would be greatly appreciated. Thank you. 

script: 

function main() {
  let ss = SpreadsheetApp.openByUrl("sheet_url");
  let dealer_sheet = ss.getSheetByName('accounts');
  let sheet = ss.getSheetByName('raw_adwords');
 
  dataPull(sheet, dealer_sheet);
}

function dataPull(sheet, dealerSheet) {
  sheet.getRange("A:J").clearContent();

  let headerRow = ["Customer ID", "Account Name", "Campaign Name", "Bidding Strategy", "Budget Name", "Match Type", "Impressions", "Clicks", "Conversions", "Cost"];
  sheet.getRange("A1:J1").setValues([headerRow]).setFontWeight("bold");

  let accountIDs = dealerSheet.getRange(1, 1, dealerSheet.getLastRow()).getValues();

  let data = [];
  for (var i = 1; i < accountIDs.length; i++) {
    if (accountIDs[i][0] == "") {
      break;
    }

    let customerId = accountIDs[i][0];
    let customerName = accountIDs[i][1];

    let accounts = AdsManagerApp.accounts().withIds([customerId]).get();
    while (accounts.hasNext()) {
      AdsManagerApp.select(accounts.next());  

      let custId = AdsApp.currentAccount().getCustomerId();
      let custName = AdsApp.currentAccount().getName();
      Logger.log(custName + ' complete');

      try {
        let report = AdsApp.search(
          `SELECT
            campaign.name,
            campaign.bidding_strategy_type,
            campaign_budget.name,
            campaign.keyword_match_type,
            metrics.impressions,
            metrics.clicks,
            metrics.conversions,
            metrics.cost_micros
          FROM campaign
          WHERE
            campaign.status = 'ENABLED'
          AND segments.date DURING THIS_MONTH`,
          {apiVersion: 'v17'}
        );

        while (report.hasNext()) {
          let query = report.next();
          let campaignName = query.campaign.name;
          let biddingStrategy = query.campaign.biddingStrategyType;
          let budgetName = query.campaignBudget.name;
          let matchType = query.campaign.keywordMatchType;
          let impressions = query.metrics.impressions;
          let clicks = query.metrics.clicks;
          let conversions = query.metrics.conversions;
          let cost = query.metrics.costMicros;
          data.push([custId, custName, campaignName, biddingStrategy, budgetName, matchType, impressions, clicks, conversions, cost / 1e6]);
        }
      } catch (error) {
        Logger.log("Error fetching report: " + error);
      }
    }
  }
  if (data.length > 0) {
    sheet.getRange(2, 1, data.length, data[0].length).setValues(data);
  }
}

Sigurd Fabrin

unread,
Jun 27, 2024, 7:42:16 AM (6 days ago) Jun 27
to Google Ads Scripts Forum
Yeah, that looks like an error. I get the same result here with this new feature from v17 https://developers.google.com/google-ads/api/fields/v17/campaign#campaign.keyword_match_type (Don't know why anybody would use that setting though)

You can still get match type on keyword level though.

Keyword match type v campaign match type - only the former returns data
    const queries = [
      `SELECT
        ad_group_criterion.keyword.text,
        ad_group_criterion.keyword.match_type  
      FROM
        ad_group_criterion
      LIMIT 10`,
      `SELECT
        campaign.name,
        campaign.keyword_match_type
       FROM
        campaign
      LIMIT 10`];
  for (i in queries) {
    const response = AdsApp.search(queries[i],{'apiVersion':'v17'}); // using v16 or v15 and it says: "Unrecognized field in the query: 'campaign.keyword_match_type'"
    while (response.hasNext()) {
      const row = response.next()
      console.log(JSON.stringify(row))
    }
    console.log(`\n\n*\n\n`);
  }


Sigurd

Google Ads Scripts Forum Advisor

unread,
Jun 27, 2024, 12:34:08 PM (6 days ago) Jun 27
to adwords...@googlegroups.com

Hi,

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

By reviewing your query, I understand that you're encountered with an issue while executing the query. Please provide the below details for further investigation.

  • Google Ads account ID, or CID.
  • Name of the script.
  • Error details or a screenshot of the issue (if any).

Also, if the script uses a spreadsheet, please provide a shareable link to the spreadsheet. You can follow this guide to share a file publicly.

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.!5004Q02tJUp1:ref" (ADR-00244363)

Thanks,
 
Google Logo Google Ads Scripts Team


Q Florence

unread,
Jun 27, 2024, 8:06:03 PM (5 days ago) Jun 27
to Google Ads Scripts Forum
My end goal was to get a roll up of metrics by campaign & keyword match type without having to actually pull keyword data. I just so happened to be looking at the reports in the API & noticed the new field & figured that would make the task easier. 
Message has been deleted

Q Florence

unread,
Jun 28, 2024, 3:41:03 AM (5 days ago) Jun 28
to Google Ads Scripts Forum
Hi, 

I responded to this thread via email but didn't realize the CID & sheet url would be displayed, so I deleted that response from the thread. The 'Reply to Author' option is greyed out & states I don't have permission. 

Google Ads Scripts Forum Advisor

unread,
Jun 28, 2024, 3:48:44 AM (5 days ago) Jun 28
to adwords...@googlegroups.com

Hi,

I would suggest that you send the requested details directly to our email address “googleadsscr...@google.com”. 

Sigurd Fabrin

unread,
Jun 28, 2024, 6:42:14 AM (5 days ago) Jun 28
to Google Ads Scripts Forum
"[...] get a roll up of metrics by campaign & keyword match type without having to actually pull keyword data"

You won't accomplice that looking at this setting.
It is there to allow people to turn all their keywords into broad match in one go. So you'd only be able to see if it had been activated or not.


Sigurd

Google Ads Scripts Forum Advisor

unread,
Jun 28, 2024, 8:20:32 AM (5 days ago) Jun 28
to adwords...@googlegroups.com

Hi,

@sigurd - Thanks for the insights.

You may follow the suggestion provided by Sigurd. I would like to inform you that the keyword match type you are using is added in V17 and currently scripts do not support the V17 version. It might be rolled out in the coming days. I would recommend that you follow the blog post for further updates on this version.

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

Q Florence

unread,
Jun 28, 2024, 10:18:10 PM (4 days ago) Jun 28
to Google Ads Scripts Forum
Ahh got it. Thanks Sigurd & Google team
Reply all
Reply to author
Forward
0 new messages