Search Audiences

Add search audience to an ad group

function addSearchAudienceToAdGroup() {
  var AUDIENCE_LIST_ID = INSERT_AUDIENCE_ID_HERE;
  var CAMPAIGN_NAME = 'INSERT_CAMPAIGN_NAME_HERE';
  var ADGROUP_NAME = 'INSERT_ADGROUP_NAME_HERE';

  // Retrieve the ad group.
  var adGroup = AdWordsApp.adGroups()
      .withCondition('Name = "' + ADGROUP_NAME + '"')
      .withCondition('CampaignName = "' + CAMPAIGN_NAME + '"')
      .get()
      .next();

  // Create the search audience.
  var searchAudience = adGroup.targeting()
      .newUserListBuilder()
      .withAudienceId(AUDIENCE_LIST_ID)
      .withBidModifier(1.3)
      .build()
      .getResult();

  // Display the results.
  Logger.log('Search audience with name = %s and ID = %s was added to ad ' +
      'group ID: %s', searchAudience.getName(),
      searchAudience.getId().toFixed(0), adGroup.getId().toFixed(0));
}

Get ad group search audience by name

function getAdGroupSearchAudienceByName() {
  var CAMPAIGN_NAME = 'INSERT_CAMPAIGN_NAME_HERE';
  var ADGROUP_NAME = 'INSERT_ADGROUP_NAME_HERE';
  var AUDIENCE_NAME = 'INSERT_AUDIENCE_NAME_HERE';

  // Retrieve the search audience.
  var searchAudience = AdWordsApp.adGroupTargeting().audiences()
      .withCondition('CampaignName = ' + CAMPAIGN_NAME)
      .withCondition('AdGroupName = ' + ADGROUP_NAME)
      .withCondition('UserListName = "' + AUDIENCE_NAME + '"')
      .get()
      .next();

  // Display the results.
  Logger.log('Search audience with name = %s and ID = %s was found.',
      searchAudience.getName(), searchAudience.getId());
}

Filter ad group search audience by stats

function filterAdGroupAudienceByStats() {
  var CAMPAIGN_NAME = 'INSERT_CAMPAIGN_NAME_HERE';
  var ADGROUP_NAME = 'INSERT_ADGROUP_NAME_HERE';

  // Retrieve top performing search audiences.
  var topPerformingAudiences = AdWordsApp.adGrouptargeting().audiences()
      .withCondition('CampaignName = ' + CAMPAIGN_NAME)
      .withCondition('AdGroupName = ' + ADGROUP_NAME)
      .withCondition('Clicks > 30')
      .forDateRange('LAST_MONTH')
      .get();

  while (topPerformingAudiences.hasNext()) {
    var audience = topPerformingAudiences.next();
    Logger.log('Search audience with ID = %s, name = %s and audience list ' +
        'ID = %s has %s clicks.', audience.getId().toFixed(0),
        audience.getName(), audience.getAudienceId(),
        audience.getStatsFor('THIS_MONTH').getClicks());
  }
}

Exclude search audience from a campaign

function addExcludedAudienceToCampaign() {
  var CAMPAIGN_NAME = INSERT_CAMPAIGN_NAME_HERE;
  var AUDIENCE_LIST_ID = INSERT_AUDIENCE_ID_HERE;

  // Retrieve the campaign.
  var campaign = AdWordsApp.campaigns()
      .withCondition('Name = "' + CAMPAIGN_NAME + '"')
      .get()
      .next();

  // Create the excluded audience.
  var audience = campaign.targeting()
      .newUserListBuilder()
      .withAudienceId(AUDIENCE_LIST_ID)
      .exclude()
      .getResult();
  Logger.log('Excluded audience with ID = %s and audience list ID = %s was ' +
      'created for campaign: "%s".', audience.getId(),
       audience.getAudienceId(), campaign.getName());
}

Get excluded search audiences for a campaign

function getExcludedAudiencesForCampaign() {
  var CAMPAIGN_NAME = INSERT_CAMPAIGN_NAME_HERE;

  // Retrieve the campaign.
  var campaign = AdWordsApp.campaigns()
      .withCondition('Name = "' + CAMPAIGN_NAME + '"')
      .get()
      .next();

  var excludedAudiences = campaign.targeting().excludedAudiences().get();

  while (excludedAudiences.hasNext()) {
    var audience = excludedAudiences.next();
    Logger.log('Excluded audience with ID = %s, name = %s and audience list ' +
        'ID = %s was found.', audience.getId(), audience.getName(),
         audience.getAudienceId());
  }
}

Set AdGroup targeting setting

function setAdGroupTargetSetting() {
  var CAMPAIGN_NAME = 'INSERT_CAMPAIGN_NAME_HERE';
  var ADGROUP_NAME = 'INSERT_ADGROUP_NAME_HERE';

  // Retrieve the ad group.
  var adGroup = AdWordsApp.adGroups()
      .withCondition('Name = "' + ADGROUP_NAME + '"')
      .withCondition('CampaignName = "' + CAMPAIGN_NAME + '"')
      .get()
      .next();

  // Change the target setting to TARGET_ALL.
  adGroup.targeting().setTargetingSetting('USER_INTEREST_AND_LIST',
      'TARGET_ALL_TRUE');
}

Update audience bid modifier

function updateAudienceBidModifer() {
  var CAMPAIGN_NAME = 'INSERT_CAMPAIGN_NAME_HERE';
  var ADGROUP_NAME = 'INSERT_ADGROUP_NAME_HERE';
  var AUDIENCE_NAME = 'INSERT_AUDIENCE_NAME_HERE';

  // Create the search audience.
  var searchAudience = AdWordsApp.adGrouptargeting().audiences()
      .withCondition('CampaignName = ' + CAMPAIGN_NAME)
      .withCondition('AdGroupName = ' + ADGROUP_NAME)
      .withCondition('UserListName = "' + AUDIENCE_NAME + '"')
      .get()
      .next();

  searchAudience.bidding().setBidModifier(1.6);

  // Display the results.
  Logger.log('Bid modifier for Search Audience with Name = "%s" in ' +
      'Ad Group ID: "%s" was set to %s.',
       searchAudience.getName(),
       adGroup.getId().toFixed(0),
       searchAudience.bidding().getBidModifier());
}

Send feedback about...

AdWords Scripts
AdWords Scripts
Need help? Visit our support page.