Filtering API driven report (ReportQuery) for a specific custom targeting key

567 views
Skip to first unread message

Joseph Ercole

unread,
Jan 9, 2019, 7:27:30 PM1/9/19
to Google Ad Manager API Forum
Hi, 

My network is 4644. 

I've seen that requested each time I've found this question in this forum. 

I'm looking to filter an API driven report for a specific custom targeting key. They key is simply, "kw". 

I'm able to do this using an ad manager query in the GUI just fine by filtering "key-values" by "kw=". 

As far as I Can tell, the key ID is: 321484. 

I'm doing something along these lines but have tried several approaches. 

===============================================================================

statementBuilder = (ad_manager.StatementBuilder()
#.Where('CUSTOM_TARGETING_VALUE_ID in (321484)')
#.WithBindVariable('crit', long(321484))
.Limit(None) # No limit or offset for reports
.Offset(None)
)

report_job = {
'reportQuery': {
'dimensions': ['DATE',
# No dartUserID
'PROPOSAL_ID',
'PROPOSAL_LINE_ITEM_ID',
'PACKAGE_ID'
'ORDER_ID',
'LINE_ITEM_ID',
'CUSTOM_CRITERIA'
],
'statement':statementBuilder.ToStatement(),
'contentMetadataKeyHierarchyCustomTargetingKeyIds':[321484],
'columns': ['AD_SERVER_TARGETED_IMPRESSIONS', 'AD_SERVER_TARGETED_CLICKS'],
# 'dateRangeType': 'LAST_MONTH'
'dateRangeType': 'CUSTOM_DATE',
'startDate': {'year': incrementStartDate.year, 'month': incrementStartDate.month,
'day': incrementStartDate.day},
'endDate': {'year': incrementEndDate.year, 'month': incrementEndDate.month, 'day': incrementEndDate.day}
}
}


===============================================================================

If I leave off the part that does this:

'contentMetadataKeyHierarchyCustomTargetingKeyIds':[321484],

My report is broken out by all of the keywords. 

I'm not sure where I'm going wrong, but the code above produces this error:

googleads.errors.GoogleAdsServerFault: [ReportError.INVALID_CONTENT_HIERARCHY_DIMENSIONS @ ]

Any help would be appreciated.

Vincent Racaza (DFP API Team)

unread,
Jan 10, 2019, 12:57:32 AM1/10/19
to Google Ad Manager API Forum
Hi Joseph,

The API equivalent of key-values is CUSTOM_CRITERIA, however as you can see in its description, this dimension is not filterable and you should use CUSTOM_TARGETING_VALUE_ID as the filter instead of contentMetadataKeyHierarchyCustomTargetingKeyIds as this is different. You my use CustomTargetingService to get all the custom targeting value IDs under a key. 

Let me know if you have further clarifications.

Thanks,
Vincent Racaza, Ad Manager API Team

Joseph Ercole

unread,
Jan 10, 2019, 9:45:24 AM1/10/19
to Google Ad Manager API Forum
Hi Vincent, 

If you look above in the "statementBuilder" I have that commented out. That's because when I tried this:

statementBuilder = (ad_manager.StatementBuilder()
.Where('CUSTOM_TARGETING_VALUE_ID in (:crit)')

.WithBindVariable('crit', long(321484))
.Limit(None) # No limit or offset for reports
.Offset(None)
)

Or even:
statementBuilder = (ad_manager.StatementBuilder()
.Where('CUSTOM_TARGETING_VALUE_ID in (321484)')

.Limit(None) # No limit or offset for reports
.Offset(None)
)

I return empty files. That is because the filtering is off.


Seeing that it works, but just returns nothing, I then took off the filter from the statementBuilder. My hunch is that filtering the value is actually filtering the ID that represents the combination of the key Id and the value.

This returned rows.

Here is an exerpt: 

Dimension.CUSTOM_CRITERIA Dimension.CUSTOM_TARGETING_VALUE_ID
pos=1 51367119964
plat=sf5 447921127044
plat=dep 447921273176
plat=dep 447921273176
plat=sf5 447921127044
plat=dep 447921273176

As you can see, my assumption above is correct.
plat=sf5 always has a VALUE_ID of : 447921127044

plat=dep always has a VALUE_ID of: 447921273176

That filter was simply filtering this field with with the ID for the key. This field you suggested is the ID of the Key Value pair. 

For instance, if I now added that filter back, like so:

statementBuilder = (ad_manager.StatementBuilder()
.Where('CUSTOM_TARGETING_VALUE_ID in (:crit)')
.WithBindVariable('crit', long(447921273176))

.Limit(None) # No limit or offset for reports
.Offset(None)
)

My assumption is that I'll only get "plat=dep" rows. 

Running the code, that is exactly what happens. 4 rows are returned. 

Just to reiterate, what I'm looking to return are just the rows that have the CUSTOM_CRITERIA containing "kw=".

Using CUSTOM_TARGETING_VALUE_ID is a much more granular filter as it picks a specific value.

Joseph Ercole

unread,
Jan 10, 2019, 9:49:37 AM1/10/19
to Google Ad Manager API Forum
Just adding to this:



Searching for "CUSTOM_TARGETING_KEY", I found as a paramter to ReportQuery, this:

- - - - - - -

The list of content metadata hierarchy custom targeting key IDs being requested in this report. Each of these IDs must have been defined in the content metadata key hierarchy. This will include dimensions in the form of CONTENT_HIERARCHY_CUSTOM_TARGETING_KEY[id]_ID and CONTENT_HIERARCHY_CUSTOM_TARGETING_KEY[id]_VALUE where where ID is the ID of thecustom targeting value and VALUE is the name.

To add IDs, you must include Dimension.CONTENT_HIERARCHY in dimensions, and specify a non-empty list of custom targeting key IDs. The order of content hierarchy columns in the report correspond to the place of Dimension.CONTENT_HIERARCHY in dimensions. For example, if dimensions contains the following dimensions in the order: Dimension.ADVERTISER_NAME,Dimension.CONTENT_HIERARCHY and Dimension.COUNTRY_NAME, and contentMetadataKeyHierarchyCustomTargetingKeyIds contains the following IDs in the order: 1001 and 1002. The order of dimensions in the report will be: Dimension.ADVERTISER_NAME, Dimension.CONTENT_HIERARCHY_CUSTOM_TARGETING_KEY[1001]_VALUE, Dimension.CONTENT_HIERARCHY_CUSTOM_TARGETING_KEY[1002]_VALUE, Dimension.COUNTRY_NAME, Dimension.ADVERTISER_ID, Dimension.CONTENT_HIERARCHY_CUSTOM_TARGETING_KEY[1001]_ID, Dimension.CONTENT_HIERARCHY_CUSTOM_TARGETING_KEY[1002]_ID, Dimension.COUNTRY_CRITERIA_ID


-----------

Just to make sure I was looking in the right place, if you click on the "IDs" link from that blurb, it takes you to here:



id
xsd:long

The ID of the CustomTargetingKey. This value is readonly and is populated by Google.

This gives me confidence that putting contentmetadatakeyhierarchycustomtargetingkeyids in the ReportQuery definition is what is necessary.

In order to make this work, it seems I'm meant to add "Dimension.CONTENT_HIERARCHY" to the dimensions. 

I've attempted to do that to no avail. 

Joseph Ercole

unread,
Jan 10, 2019, 10:13:42 AM1/10/19
to Google Ad Manager API Forum
Just another bit of info: 

Under network 4644, the current query achieving this is:

rid=11090408921

Thanks,
Joe
Message has been deleted

Vincent Racaza (DFP API Team)

unread,
Jan 11, 2019, 3:22:05 AM1/11/19
to Google Ad Manager API Forum
Hi Joseph,

The contentMetadataKeyHierarchyCustomTargetingKeyIds is for video content metadata (this is equivalent to content metadata dimensions as you can see in the attached screenshot), and not for the standard key-values which you can see as dimension in the UI. The documentation for that field links to the CustomTargetingService because they are also defined in that service same as the standard key-values (Key-values dimension in the UI).

Also, since you mentioned that you have already use the CUSTOM_TARGETING_VALUE_ID as your filter and yet, it returned empty results, then, can you provide your query ID (qid instead or rid) of the query (or a screenshot of the query perhaps) you created in the UI together with email address used in creating that query? You may use the Reply privately to author option in providing these details.

Thanks,
Vincent Racaza, Ad Manager API Team

contentmetadata.png

Joseph Ercole

unread,
Jan 11, 2019, 11:46:43 AM1/11/19
to Google Ad Manager API Forum
Hi Vincent, 

Would you confirm that you received the QID that I sent privately?

Thanks,
Joe
Reply all
Reply to author
Forward
0 new messages