-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from fishtown-analytics/fix/ad-creative-url-pa…
…rsing Fix: ad creative url parsing--child links
- Loading branch information
Showing
6 changed files
with
167 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{% macro nested_field(field, subfields) %} | ||
|
||
{{ adapter_macro('facebook_ads.nested_field', field, subfields) }} | ||
|
||
{% endmacro %} | ||
|
||
|
||
{% macro default__nested_field(field, subfields) %} | ||
|
||
{{field}}__{{ subfields|join('__') }} | ||
|
||
{% endmacro %} | ||
|
||
|
||
{% macro bigquery__nested_field(field, subfields) %} | ||
|
||
{{field}}.{{ subfields|join('.') }} | ||
|
||
{% endmacro %} | ||
|
||
|
||
{% macro snowflake__nested_field(field, subfields) %} | ||
|
||
{{field ~ "['" ~ subfields|join("']['") ~ "']" }} | ||
|
||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
macros/stitch/base/stitch_fb_ad_creatives__child_links.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
-- There are cases where ads can have multiple links attached to them. | ||
-- This model was created to extract all the child links and return the first | ||
-- instance where a URL contains utm parameters. | ||
|
||
|
||
{% macro stitch_fb_ad_creatives__child_links() %} | ||
|
||
{{ adapter_macro('facebook_ads.stitch_fb_ad_creatives__child_links') }} | ||
|
||
{% endmacro %} | ||
|
||
{% macro default__stitch_fb_ad_creatives__child_links() %} | ||
|
||
|
||
with base as ( | ||
|
||
select * from {{ var('ad_creatives__child_links_table') }} | ||
|
||
), | ||
|
||
child_attachment_links as ( | ||
|
||
select | ||
|
||
_sdc_source_key_id as creative_id, | ||
_sdc_batched_at, | ||
link as child_link | ||
|
||
from base | ||
where child_link ilike '%utm%' | ||
|
||
), | ||
|
||
aggregated as ( | ||
|
||
select distinct | ||
|
||
creative_id, | ||
first_value(child_link) over ( | ||
partition by creative_id | ||
order by _sdc_batched_at | ||
rows between unbounded preceding and unbounded following | ||
) as child_link | ||
|
||
from child_attachment_links | ||
|
||
) | ||
|
||
select * from aggregated | ||
|
||
{% endmacro %} | ||
|
||
|
||
{% macro snowflake__stitch_fb_ad_creatives__child_links() %} | ||
|
||
|
||
{% set fields = [ | ||
|
||
'object_story_spec', | ||
'child_link', | ||
|
||
]%} | ||
|
||
with base as ( | ||
|
||
select * from {{ var('ad_creatives_table') }} | ||
|
||
), | ||
|
||
child_attachment_links as ( | ||
|
||
select | ||
*, | ||
attachments.value:link::varchar as child_link | ||
|
||
from base, | ||
lateral flatten (input => object_story_spec:link_data:child_attachments) attachments | ||
where child_link ilike '%utm%' | ||
|
||
), | ||
|
||
aggregated as ( | ||
|
||
select distinct | ||
id as creative_id, | ||
|
||
{% for field in fields %} | ||
first_value({{ field }}) over (partition by id | ||
order by _sdc_batched_at | ||
rows between unbounded preceding and unbounded following) | ||
as {{ field }} | ||
{% if not loop.last%} , {% endif %} | ||
{% endfor %} | ||
|
||
from child_attachment_links | ||
|
||
) | ||
|
||
select * from aggregated | ||
|
||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{ | ||
config( | ||
enabled = var('etl') == 'stitch' | ||
) | ||
}} | ||
|
||
{{ stitch_fb_ad_creatives__child_links() }} |