Hide

Location targeting

For an AdWords campaign to be successful, it should be targeted towards your audience. This guide will explore geo targeting in more detail. We will examine how you can use AdWords API to add, retrieve, and update geo targeting for your campaigns. We will also examine advanced geo targeting concepts like Location of Presence and Area of Interest as well as how to run reports and evaluate your campaign's geo performance.

Code examples in this guide use the AdWords API Java library. If you are looking for a client library in another programming language, you can check our complete list of client libraries. Also, the use of a client library is recommended but optional; you may use any SOAP kit in the programming language of your choice to make calls to the API.

Why is geo targeting important?

For an AdWords campaign to be successful, it should be targeted towards your audience. Geo targeting allows you to limit your ads to users of a particular geographical region. For example, assume you are advertising for a chain of supermarkets. Without geo targeting, your ads would show in all regions worldwide, and your ads may receive clicks from users in regions where your supermarket chains are not available, thus costing you advertising budget without returns. It is more effective to geo target your advertisement campaigns to show only in regions where your supermarkets provide service. This approach also allows you to reach out to customers who search locally for supermarkets.

AdWords API allows you to target your ads by country, region, or proximity around a geo point. We will now examine each of these options. If you are not familiar about these options in AdWords, you can read about them at this help center article .

Geo target campaigns for a region

The AdWords API allows you to geo target your campaigns for a region. A region can be any geographical region for which AdWords supports geo targeting, for instance, a country, a state, a city, or a postal region. Each targetable location is uniquely identified by a Criterion ID.

You can add geo targets to your campaigns using the CampaignCriterionService. The following code snippet shows how to target your campaigns to California (USA) and Mexico.

// Create locations. The IDs can be found in the documentation or
// retrieved with the LocationCriterionService.
Location california = new Location();
california.setId(21137L);
Location mexico = new Location();
mexico.setId(2484L);

List operations = new ArrayList();
for (Criterion criterion : new Criterion[] {california, mexico}) {
  CampaignCriterionOperation operation = new CampaignCriterionOperation();
  CampaignCriterion campaignCriterion = new CampaignCriterion();
  campaignCriterion.setCampaignId(campaignId);
  campaignCriterion.setCriterion(criterion);
  operation.setOperand(campaignCriterion);
  operation.setOperator(Operator.ADD);
  operations.add(operation);
}

CampaignCriterionReturnValue result = campaignCriterionService.mutate(operations
   .toArray(new CampaignCriterionOperation[operations.size()]));

As shown in the code, you need to create Location objects for each region you want to target and add them using CampaignCriteronService.mutate. 21137 is the code for California, whereas 2484 is the code for Mexico.

Google may phase out some location criteria for a number of reasons: the location may be restructured into smaller (or larger areas), geo-political changes, etc. You can refer to the targetingStatus field of a Location object to determine if a location is ACTIVE, OBSOLETE, or PHASING_OUT. You can refer to this blog post for more details about phasing out location targets.

Look up location codes for a region

As mentioned in the previous section, you need to create a Location object with an appropriate code to geo target a region. You can use the LocationCriterionService to look up the criterion ID for a location. The following code example shows how you can look up a location criterion ID by location name.

String[] locationNames = new String[] {"Quebec"};

Selector selector = new Selector();
selector.setFields(new String[] {"Id", "LocationName", "CanonicalName", "DisplayType",
   "ParentLocations", "Reach"});

selector.setPredicates(new Predicate[] {
  // Location names must match exactly, only EQUALS and IN are
  // supported.
  new Predicate("LocationName", PredicateOperator.IN, locationNames),
  // Set the locale of the returned location names.
  new Predicate("Locale", PredicateOperator.EQUALS, new String[] {"en"})
});

// Make the get request.
LocationCriterion[] locationCriteria = locationCriterionService.get(selector);

// Display the resulting location criteria.
for (LocationCriterion locationCriterion : locationCriteria) {
 String parentString =
     getParentLocationString(locationCriterion.getLocation().getParentLocations());
 System.out.printf("The search term '%s' returned the location '%s (%d)' of type '%s' "
     + "with parent locations '%s' and reach '%d'.\n",
    locationCriterion.getSearchTerm(),
    locationCriterion.getLocation().getLocationName(),
    locationCriterion.getLocation().getId(),
    locationCriterion.getLocation().getDisplayType(), parentString,
    locationCriterion.getReach());
}

/**
  * Helper function to format a string for parent locations.
  *
  * @param parents List of parent locations.
  * @return Formatted string representing parent locations.
  */
 public static String getParentLocationString(Location[] parents) {
   StringBuilder sb = new StringBuilder();
   if (parents != null) {
     for (Location parent : parents) {
       if (sb.length() > 0) {
         sb.append(", ");
       }
       sb.append(String.format("%s (%s)", parent.getLocationName(),
           parent.getDisplayType()));
     }
   } else {
     sb.append("N/A");
   }
   return sb.toString();
 }

The code example above will result in the following output:

The search term 'Quebec' returned the location 'Quebec'(20123) of type 'Province'
with parent locations 'Canada (Country)' and reach '5070000'. The search term
'Quebec' returned the location 'Quebec City'(1002624) of type 'City' with parent
locations 'Quebec (Province), Canada (Country), ' and reach '356000'.

You can now target Quebec (Province) using location code 20123, and Quebec City using the location code 1002624.

LocationCriterionService allows for retrieval of a location's parents. This is done by adding ParentLocations to the list of selector fields. For example, our previous code returned the location (Quebec city) as well as its parent location (Canada). This feature is useful if you want to display a hierarchical list of locations to your customers, or if you want to add inclusion or exclusion logic for geo locations while targeting your campaigns.

An important thing to keep in mind while working with parent locations is that you should not make any assumptions about a location's displayType in a hierarchy. For example, USA may be divided into states and further into cities, but this may not necessarily be true for every country in the world.

You can use LocationCriterionService effectively if you know the location name somewhat accurately. The lookup will try to match the name you give it as best as it can. If you want to retrieve the location codes for a large number of regions, it may be more efficient to save the list locally in a database and write your own location lookup logic. You can easily look up the codes for a location or download the list of all codes from our targets table which is periodically updated with the latest geo targets.

Geo target campaigns for proximity to a location

Targeting your campaigns by location allows you to target your campaigns by geographical locations effectively, but there are times when you might want to target even more precisely. For example, you may want to advertise your supermarkets within 10 kilometers of your shop location. In such cases, you can use Proximity targeting for your campaigns. The code to create a proximity target is similar to how you add a location target, except that you have to create a Proximity object instead of a Location object.

Proximity proximity = new Proximity();
proximity.geoPoint = myGeoPoint;
proximity.radiusDistanceUnits = ProximityDistanceUnits.KILOMETERS;
proximity.radiusInUnits = 10;

Look up coordinates of an address

To use a Proximity target, you need the coordinates of the address you wish to target. You can use GeoLocationService to look up the coordinates of an address.

GeoLocationServiceInterface geoLocationService =
    new AdWordsServices().get(session, GeoLocationServiceInterface.class);

// Lookup the geo point for 38 avenue de l'Opéra, 75002 Paris, FR.
Address address = new Address();
address.setStreetAddress("38 avenue de l'Opéra");
address.setCityName("Paris");
address.setPostalCode("75002");
address.setCountryCode("FR");

// Create geo location selector.
GeoLocationSelector selector = new GeoLocationSelector();
selector.setAddresses(new Address[] {address});

// Get geo location.
GeoLocation[] geoLocationResult = geoLocationService.get(selector);
GeoPoint geoPoint = geoLocationResult[0].getGeoPoint();

As in the case of LocationCriterionService, it may be more feasible to store the coordinates of your geo targets in a local database instead of looking them up using GeoLocationService if you have to target a large number addresses in your campaigns.

Geo target campaigns for a polygon region

In the past, AdWords allowed you to target your campaigns to a polygon region. However, polygon targets have been deprecated in favor of proximity regions, so you can no longer add a polygon target using the AdWords API. However, if you are retrieving geo targets for an existing campaign, you may encounter one. You can remove an existing polygon target using the AdWords API.

Retrieve geo targets

You can retrieve the geo targets for a campaign using the CampaignCriterionService.get method. You can filter your results by CriteriaType to restrict the results to Location alone, and use paging to limit the number of targets you retrieve.

int offset = 0;

// Create selector.
Selector selector = new Selector();
selector.setFields(new String[] {"CampaignId", "Id", "CriteriaType", "LocationName"});
selector.setOrdering(new OrderBy[] {new OrderBy("Name", SortOrder.ASCENDING)});
selector.setPredicates(new Predicate[] {new Predicate("CriteriaType",
    PredicateOperator.EQUALS, new String[] {"LOCATION"})});
selector.setPaging(new Paging(offset, PAGE_SIZE));
CampaignCriterionPage page = null;
do {
  page = campaignCriterionService.get(selector);

  if (page.getEntries() != null) {
    // Display campaigns.
    for (CampaignCriterion campaignCriterion : page.getEntries()) {
      System.out.printf("Campaign criterion with campaign id '%s', criterion id '%s', "
          + "and type '%s' was found.\n", campaignCriterion.getCampaignId(),
        campaignCriterion.getCriterion().getId(),
        campaignCriterion.getCriterion().getCriterionType());
    }
    Thread.sleep(1000);
  } else {
    System.out.println("No campaign criteria were found.");
  }
  offset += PAGE_SIZE;
  selector.getPaging().setStartIndex(offset);
} while (offset < page.getTotalNumEntries());

Note that if your campaign is targeting all countries and regions, you'll get an empty list of location targets.

Update geo targets

To update geo targets for a campaign, you need to retrieve the list of existing geo targets and compare it with the list of new geo targets. You can then use the REMOVE operator to remove the geo targets you don't need, and the ADD operator to add the new geo targets you need (but are missing in the existing campaign). In the past, the AdWords API allowed you to overwrite the geo targeting of a campaign using the SET operator. However, this behavior is no longer supported and you will need to use the REMOVE + ADD combination when updating geo targets for your campaign.

Exclude geo targets

The AdWords API also allows you to exclude a region for geo targeting. This feature is most useful if you want to target a region, but exclude a sub-region (e.g. target the entire US, except for New York city). To exclude a region, you can create a NegativeCampaignCriterion, with its criterion as the location to exclude.

// Add a negative campaign geo target.
NegativeCampaignCriterion negativeCriterion = new NegativeCampaignCriterion();
negativeCriterion.campaignId = campaignId;
negativeCriterion.criterion = locationToExclude;

Advanced geotargeting settings

AdWords allows you to specify whether to show your ads to users by their physical Location of Presence (LOP) or by their Area of Interest (AOI). To understand this better, assume you run a campaign for a flower shop, and target only New York City. Additionally, let us assume that "flowers" is a keyword in your campaign. Consider a user located in California, searching for "flowers in new york". In this case, California is the LOP for the user, whereas New York is the AOI.

You can add a GeoTargetTypeSetting to your campaign to decide whether to show your ads to users based on their LOP or AOI, or both.

Geo performance reporting

You can analyze the effectiveness of geo targeting in your campaigns by running reports. The AdWords API provides you two report types to get geo performance data:

  1. You can use the geo performance report.
  2. You can use the criteria report, and filter by CriteriaType=LOCATION or PROXIMITY to get geo performance data for a particular geo target.

Refer to this guide for more details on how to run a report using the AdWords API.

Send feedback about...

AdWords API