'Google Ads script to find multiple campaigns of a keyword

I am working on Google Ads using Ads Scripts. Is there any way to find if a keyword is bid on 'more than one campaigns'. If it is then how to find which are those keywords and to which campaigns do they belong.

A script for that would be very useful.



Solution 1:[1]

So I found a workaround and created a script which would print in how many campaigns a keyword is used(if used at multiple campaigns) and which are those campaigns. Thought of sharing it for others.

function main() {
  findCampaignForKeyword();
}

function findCampaignForKeyword() {
  var keywordIterator = AdsApp.keywords()
    .withCondition("Status = ENABLED")
    .withCondition("AdGroupStatus = ENABLED")
    .withCondition("CampaignStatus = ENABLED")
    .get();

  var dict = {};

  while (keywordIterator.hasNext()) {
    var keyword = keywordIterator.next();
    var key = keyword.getText();
    dict[key] = [];
  }

  var keywordIterator2 = AdsApp.keywords()
    .withCondition("Status = ENABLED")
    .withCondition("AdGroupStatus = ENABLED")
    .withCondition("CampaignStatus = ENABLED")
    .get();

  while (keywordIterator2.hasNext()) {
    var keyword = keywordIterator2.next();
    var key = keyword.getText();
    var campaign = keyword.getCampaign().getName();
    dict[key].push(campaign);
  }

  for (var key in dict) {
    if (dict[key].length > 1) {
      console.log(
        `Keyword "${key}" has ${dict[key].length} campaigns i.e.\n ${dict[key]}`
      );
    }
  }
}

Run the following script into your Google Ads Scripts and it might help you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Devansh Sharma