Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

0.18.0 #39

Merged
merged 2 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'facebook_ads'
version: '0.5.0'
config-version: 2

require-dbt-version: [">=0.17.0"]
require-dbt-version: [">=0.18.0"]

source-paths: ["models"] # paths with source code to compile
analysis-paths: ["analysis"] # path with analysis files which are compiled, but not run
Expand All @@ -22,6 +22,6 @@ vars:
ad_creatives__child_links_table: #table -- disable if on snowflake

url_tag_table: #only for fivetran

models:
facebook_ads:
10 changes: 5 additions & 5 deletions macros/fivetran/base/fivetran_fb_ad_creatives.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% macro fivetran_fb_ad_creatives() %}

{{ adapter_macro('facebook_ads.fivetran_fb_ad_creatives') }}
{{ adapter.dispatch('fivetran_fb_ad_creatives', packages=facebook_ads._get_facebook_ads_namespaces())() }}

{% endmacro %}

Expand All @@ -22,14 +22,14 @@ with base as (

final as (

select
*
select
*

from base
from base
where row_num = 1

)

select * from final

{% endmacro %}
{% endmacro %}
12 changes: 6 additions & 6 deletions macros/fivetran/base/fivetran_fb_ad_insights.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% macro fivetran_fb_ad_insights() %}

{{ adapter_macro('facebook_ads.fivetran_fb_ad_insights') }}
{{ adapter.dispatch('fivetran_fb_ad_insights', packages=facebook_ads._get_facebook_ads_namespaces())() }}

{% endmacro %}

Expand Down Expand Up @@ -30,21 +30,21 @@ with base as (
inline_post_engagement,
unique_inline_link_clicks,
row_number() over (partition by date_day, ad_id order by _FIVETRAN_SYNCED desc) as row_num

from
{{ var('ads_insights_table') }}
),

final as (

select
*
select
*

from base
from base
where row_num = 1

)

select * from final

{% endmacro %}
{% endmacro %}
14 changes: 7 additions & 7 deletions macros/fivetran/base/fivetran_fb_ads.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% macro fivetran_fb_ads() %}

{{ adapter_macro('facebook_ads.fivetran_fb_ads') }}
{{ adapter.dispatch('fivetran_fb_ads', packages=facebook_ads._get_facebook_ads_namespaces())() }}

{% endmacro %}

Expand All @@ -13,7 +13,7 @@
with base as (

select

id as ad_id,
account_id,
ad_set_id as adset_id,
Expand All @@ -23,21 +23,21 @@ with base as (
created_time as created_at,
updated_time as updated_at,
row_number() over (partition by ad_id, updated_at order by _FIVETRAN_SYNCED desc) as row_num

from
{{ var('ads_table') }}
),

final as (

select
*
select
*

from base
from base
where row_num = 1

)

select * from final

{% endmacro %}
{% endmacro %}
12 changes: 6 additions & 6 deletions macros/fivetran/base/fivetran_fb_ads_adsets.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% macro fivetran_fb_ads_adsets() %}

{{ adapter_macro('facebook_ads.fivetran_fb_ads_adsets') }}
{{ adapter.dispatch('fivetran_fb_ads_adsets', packages=facebook_ads._get_facebook_ads_namespaces())() }}

{% endmacro %}

Expand All @@ -9,7 +9,7 @@
with base as (

select

id as adset_id,
nullif(name,'') as name,
account_id,
Expand All @@ -24,14 +24,14 @@ with base as (

final as (

select
*
select
*

from base
from base
where row_num = 1

)

select * from final

{% endmacro %}
{% endmacro %}
4 changes: 2 additions & 2 deletions macros/fivetran/base/fivetran_fb_campaigns.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% macro fivetran_fb_ads_campaigns() %}

{{ adapter_macro('facebook_ads.fivetran_fb_ads_campaigns') }}
{{ adapter.dispatch('fivetran_fb_ads_campaigns', packages=facebook_ads._get_facebook_ads_namespaces())() }}

{% endmacro %}

Expand All @@ -15,4 +15,4 @@ select distinct
from
{{ var('campaigns_table') }}

{% endmacro %}
{% endmacro %}
20 changes: 10 additions & 10 deletions macros/fivetran/base/fivetran_fb_url_tag.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% macro fivetran_fb_url_tag() %}

{{adapter_macro('facebook_ads.fivetran_fb_url_tag')}}
{{adapter.dispatch('fivetran_fb_url_tag', packages=facebook_ads._get_facebook_ads_namespaces())() }}

{% endmacro %}

Expand All @@ -16,7 +16,7 @@
} %}

with base as (

select
nullif(type,'') as type,
nullif(key,'') as key,
Expand All @@ -29,30 +29,30 @@ with base as (
),

final as (

select distinct

creative_id,

{% for key, value in utm_key_value_pairs.items()%}

first_value(
case
case
when key = '{{key}}' then value
else null
else null
end

{{facebook_ads.ignore_nulls()}}

over (
partition by creative_id
order by key
order by key
rows between unbounded preceding and unbounded following
) as {{value}}

{% if not loop.last %}
{% if not loop.last %}
,
{% endif %}
{% endif %}

{% endfor %}

Expand All @@ -62,4 +62,4 @@ final as (

select * from final

{% endmacro %}
{% endmacro %}
4 changes: 2 additions & 2 deletions macros/fivetran/ignore_nulls.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% macro ignore_nulls() %}

{{ adapter_macro('facebook_ads.ignore_nulls') }}
{{ adapter.dispatch('ignore_nulls', packages=facebook_ads._get_facebook_ads_namespaces())() }}

{% endmacro %}

Expand All @@ -14,4 +14,4 @@

) ignore nulls

{% endmacro %}
{% endmacro %}
4 changes: 4 additions & 0 deletions macros/get_face.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% macro _get_facebook_ads_namespaces() %}
{% set override_namespaces = var('facebook_ads_dispatch_list', []) %}
{% do return(override_namespaces + ['facebook_ads']) %}
{% endmacro %}
6 changes: 3 additions & 3 deletions macros/nested_field.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% macro nested_field(field, subfields) %}

{{ adapter_macro('facebook_ads.nested_field', field, subfields) }}
{{ adapter.dispatch('nested_field', packages=facebook_ads._get_facebook_ads_namespaces())(field, subfields) }}

{% endmacro %}

Expand All @@ -21,6 +21,6 @@

{% macro snowflake__nested_field(field, subfields) %}

{{field ~ "['" ~ subfields|join("']['") ~ "']" }}
{{field ~ "['" ~ subfields|join("']['") ~ "']" }}

{% endmacro %}
{% endmacro %}
32 changes: 16 additions & 16 deletions macros/stitch/base/stitch_fb_ad_creatives.sql
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
{% macro stitch_fb_ad_creatives() %}

{{ adapter_macro('facebook_ads.stitch_fb_ad_creatives') }}
{{ adapter.dispatch('stitch_fb_ad_creatives', packages=facebook_ads._get_facebook_ads_namespaces())() }}

{% endmacro %}


{% macro default__stitch_fb_ad_creatives() %}

with base as (

select * from {{ var('ad_creatives_table') }}

),

child_links as (

select * from {{ ref('fb_ad_creatives__child_links') }}

),

links_joined as (

select

id as creative_id,

lower(coalesce(
nullif(child_link, ''),
nullif({{ facebook_ads.nested_field('base.object_story_spec', ['link_data', 'call_to_action', 'value', 'link']) }}, ''),
nullif({{ facebook_ads.nested_field('base.object_story_spec', ['video_data', 'call_to_action', 'value', 'link']) }}, ''),
nullif({{ facebook_ads.nested_field('base.object_story_spec', ['link_data', 'link']) }}, '')
)) as url,

lower(coalesce(
nullif(url_tags, {{ dbt_utils.split_part('url', "'?'", 2) }}), '')
) as url_tags

from base
left join child_links
left join child_links
on base.id = child_links.creative_id

),

parsed as (

select

links_joined.*,
{{ dbt_utils.split_part('url', "'?'", 1) }} as base_url,
{{ dbt_utils.get_url_host('url') }} as url_host,
{{ dbt_utils.concat(["'/'", dbt_utils.get_url_path('url')]) }} as url_path,
{{ facebook_ads.get_url_parameter() }}
from links_joined

from links_joined

)

select * from parsed

{% endmacro %}
{% endmacro %}
Loading