Harness the power of predicates in your reports
December 10th, 2010 | Published in Google Adwords API
The reporting services of the AdWords API are designed to allow you to download large amounts of data, but it can often be useful to filter out certain rows from the start to cut down on processing and transfer time. DefinedReportJobs created using the v13 ReportService supported a limited set of filtering options, primarily on IDs and statuses. Filtering on a more complex set of criteria would require post processing the report client-side. The ReportDefinitionService introduced in v201003 supports Predicates, a more flexible system of filters that can be used to create very targeted reports.
A predicate is composed of three parts: the field, the operator, and the values. Predicates can be created for almost every field available, indicated by
There are a fixed set of operators that can be used to compare the value of the field selected.
The values used in the predicate depend heavily on the field being operated on. Numerical values should be used for
If multiple predicates are used within a Selector they will be combined using AND logic, so that the resulting report will only contain rows that satisfies all of the predicates. It’s not possible to combine predicates using OR logic at this time, but some common use cases can be handled using a single predicate and the
When combined together, predicates can be quite powerful. Consider the following example: I own an electronics shop that is starting to sell a wider array of tablet computers, and I want to drive more traffic to that section of my website. I’d like to start by finding all my current keywords that include the word "tablet" and have a high CTR, and then use them to generate new keyword ideas using the TargetingIdeaService. I’m only interested in keywords with greater than a 10% CTR, that have at least 100 impressions, and that are in enabled or paused ad groups.
Using predicates I can create a
Predicates are one of many new improvements introduced in the ReportDefinitionService, and if you aren’t using the service yet, now is a great time to start looking into migrating. The service is fully supported in all our client libraries, and we’re available on the forum to answer any questions you may have.
- Eric Koleda, AdWords API Team
A predicate is composed of three parts: the field, the operator, and the values. Predicates can be created for almost every field available, indicated by
canFilter
set to "true" in the results returned from getReportFields()
.
Clicks
Clicks
clicks
Long
true
true
There are a fixed set of operators that can be used to compare the value of the field selected.
EQUALS
can be used to filter for an exact match, while IN can be used to match any of a set of values. GREATER_THAN
and LESS_THAN
are available for comparing numerical values, and CONTAINS
is useful when working with strings. Only one operator can be used per predicate, but multiple predicates can be created for the same field to create more complex logic.The values used in the predicate depend heavily on the field being operated on. Numerical values should be used for
Long
, Double
, and Integer
fields, and arbitrary strings can be used for String
fields. The values for Money
and Bid
fields must always be specified in micros, even if the report is eventually downloaded with whole currency amounts. Although percentage fields like Ctr are returned as whole numbers, the values used in predicates should be the decimal equivalents. Predicates on Enum
fields must only use the values of the enum, as outlined in the documentation and in the enumValues
property returned by getReportFields()
.
CampaignStatus
Campaign state
campaignState
CampaignStatus
ACTIVE
DELETED
PAUSED
true
true
If multiple predicates are used within a Selector they will be combined using AND logic, so that the resulting report will only contain rows that satisfies all of the predicates. It’s not possible to combine predicates using OR logic at this time, but some common use cases can be handled using a single predicate and the
IN
operator. For example, to match keywords with either the PHRASE
or EXACT
match type you could use the following predicate:
KeywordMatchType
IN
PHRASE
EXACT
When combined together, predicates can be quite powerful. Consider the following example: I own an electronics shop that is starting to sell a wider array of tablet computers, and I want to drive more traffic to that section of my website. I’d like to start by finding all my current keywords that include the word "tablet" and have a high CTR, and then use them to generate new keyword ideas using the TargetingIdeaService. I’m only interested in keywords with greater than a 10% CTR, that have at least 100 impressions, and that are in enabled or paused ad groups.
Using predicates I can create a
KEYWORDS_PERFORMANCE_REPORT
that only returns me the exact data I am interested in:
CampaignId
EQUALS
123456789
AdGroupStatus
IN
ENABLED
PAUSED
KeywordText
CONTAINS
tablet
Ctr
GREATER_THAN
0.10
Impressions
GREATER_THAN_EQUALS
100
Predicates are one of many new improvements introduced in the ReportDefinitionService, and if you aren’t using the service yet, now is a great time to start looking into migrating. The service is fully supported in all our client libraries, and we’re available on the forum to answer any questions you may have.
- Eric Koleda, AdWords API Team