How do I fetch ads targeted to a subset of ad targeting criteria?
As explained in the article on custom ad targeting, you can use custom data to target ads more accurately by passing custom parameters in the targeting flags of your ad call.
By default, when you pass parameters in multiple targeting flags, the ad servers will only show ads that match at least one parameter in each of the flags you set.
However if you need to fetch ads that match only a subset of the targeting flags, then you need to add a wildcard parameter i.e. * to the optional flags .
For example, consider this scenario:
- Ad 1 is targeted to users in Ohio, United States, who are interested in cars, and to pages with the toyota keyword.
- Ad 2 is targeted to users in Canada, who are interested in cars, and to pages with the ford keyword.
- Ad 3 is targeted to Everyone.
| Ad 1 | Ad 2 | Ad 3 | ||
|---|---|---|---|---|
| geographics | US/OH | CA | ||
| interest | cars | cars | ||
| keywords | toyota | ford |
interests=["cars"]; keywords=["toyota"]; - will show ads 1 and 3
interests=["cars"]; keywords=["ford", "*"]; - will show ads 1, 2 and 3
interests=["cars"]; - will show ads 1, 2 and 3
interests=["*"]; keywords=["ford"]; - will show ads 2, 1, and 3 (Note: Ad 2 will be assigned the highest relevancy rating)
interests=["cars"]; keywords=["mercedes"]; - will show ad 3 only
interests=["cars"]; geographics=["us"]; - will show ads 1 and 3