Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new AdTargetingAnalyticsStream stream #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mjn
Copy link

@mjn mjn commented Sep 18, 2024

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 of AdAnalyticsStream, and leverages the bulk of the parent class code; however, it has a custom post_process method that transforms the record returned by the API so that it more closely resembles the rows produced by the AdAnalyticsStream. For example, the following is an example of a record returned by the API:

{
  "targeting_type": "KEYWORD",
  "targeting_value": "christmas decor ideas",
  "metrics": {
    "AD_GROUP_ID": 2680067996745,
    "DATE": "2022-04-26",
    "SPEND_IN_DOLLAR": 240
  }
}

The post_process function flattens the metrics 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 current AdAnalyticsStream columns):

{
  "TARGETING_TYPE": "KEYWORD",
  "TARGETING_VALUE": "christmas decor ideas",
  "AD_GROUP_ID": 2680067996745,
  "DATE": "2022-04-26",
  "SPEND_IN_DOLLAR": 240
}

The parent_stream_type property of the AdTargetingAnalyticsStream is set to AdStream as the targeting_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, the ad_id is set in the context that is passed to the child stream, allowing the stream to query the targeting analytics for each ad extracted by the AdStream.

Comment on lines +226 to +230
AD_ANALYTICS_REACH_COLUMNS = [
"TOTAL_IMPRESSION_FREQUENCY",
"TOTAL_IMPRESSION_USER",
]

Copy link
Author

@mjn mjn Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The targeting analytics API endpoint does not support querying of reach metrics (even though they are listed in the set of available columns in the API docs, when querying these columns the API returns an error), so I have extracted those columns into a separate array and updated the AdStream to get AD_ANALYTICS_COLUMNS + AD_ANALYTICS_REACH_COLUMNS while AdTargetingAnalyticsStream only gets AD_ANALYTICS_COLUMNS.

@mjn mjn changed the title Add new AdTargetingAnalytics stream Add new AdTargetingAnalyticsStream stream Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant