Add new AdTargetingAnalyticsStream
stream
#24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What was done?
The Pinterest Ads API supports getting targeting analytics for ads, allowing for reporting on various breakdowns such as country, region, etc. However, the
tap-pinterest-ads
tap does not currently have a stream to pull this data.This PR adds a new stream -
AdTargetingAnalyticsStream
- that fetches data for all currently supported targeting types (AGE_BUCKET_AND_GENDER
targeting type has been omitted as it is in beta and not currently available to all users).The
AdTargetingAnalyticsStream
is a subclass ofAdAnalyticsStream
, and leverages the bulk of the parent class code; however, it has a custompost_process
method that transforms the record returned by the API so that it more closely resembles the rows produced by theAdAnalyticsStream
. For example, the following is an example of a record returned by the API:The
post_process
function flattens themetrics
structure into the root document, so that it looks like the following (Note: All column names have been capitalized to match the naming convention of the currentAdAnalyticsStream
columns):The
parent_stream_type
property of theAdTargetingAnalyticsStream
is set toAdStream
as thetargeting_analytics
API endpoint requires that at least one ad ID be passed as a parameter when querying the API. Thus, once an ad has been extracted in the parent stream, thead_id
is set in thecontext
that is passed to the child stream, allowing the stream to query the targeting analytics for each ad extracted by theAdStream
.