Skip to main content

Snowplow Fractribution Macros

caution

This page is auto-generated from our dbt packages, some information may be incomplete

Snowplow Fractributionโ€‹

Channel Classificationโ€‹

macros/channel_classification.sql

Description

A macro used to perform channel classifications. Each channel should be classified a name that is a valid field name as it will be used for that purpose, once unnested downstream.

Returns

A sql of case statements that determine which channel is classified (it is most likely unique to each organisation, the sample provided is based on Google's Fractribution).

Example:

    case when lower(mkt_medium) in ('cpc', 'ppc') and regexp_count(lower(mkt_campaign), 'brand') > 0 then 'Paid_Search_Brand'
when lower(mkt_medium) in ('cpc', 'ppc') and regexp_count(lower(mkt_campaign), 'generic') > 0 then 'Paid_Search_Generic'
when lower(mkt_medium) in ('cpc', 'ppc') and not regexp_count(lower(mkt_campaign), 'brand|generic') > 0 then 'Paid_Search_Other'
when lower(mkt_medium) = 'organic' then 'Organic_Search'
when lower(mkt_medium) in ('display', 'cpm', 'banner') and regexp_count(lower(mkt_campaign), 'prospect') > 0 then 'Display_Prospecting'
when lower(mkt_medium) in ('display', 'cpm', 'banner') and regexp_count(lower(mkt_campaign), 'retargeting|re-targeting|remarketing|re-marketing') > 0 then 'Display_Retargeting'
when lower(mkt_medium) in ('display', 'cpm', 'banner') and not regexp_count(lower(mkt_campaign), 'prospect|retargeting|re-targeting|remarketing|re-marketing') > 0 then 'Display_Other'
when regexp_count(lower(mkt_campaign), 'video|youtube') > 0 or regexp_count(lower(mkt_source), 'video|youtube') > 0 then 'Video'
when lower(mkt_medium) = 'social' and regexp_count(lower(mkt_campaign), 'prospect') > 0 then 'Paid_Social_Prospecting'
when lower(mkt_medium) = 'social' and regexp_count(lower(mkt_campaign), 'retargeting|re-targeting|remarketing|re-marketing') > 0 then 'Paid_Social_Retargeting'
when lower(mkt_medium) = 'social' and not regexp_count(lower(mkt_campaign), 'prospect|retargeting|re-targeting|remarketing|re-marketing') > 0 then 'Paid_Social_Other'
when mkt_source = '(direct)' then 'Direct'
when lower(mkt_medium) = 'referral' then 'Referral'
when lower(mkt_medium) = 'email' then 'Email'
when lower(mkt_medium) in ('cpc', 'ppc', 'cpv', 'cpa', 'affiliates') then 'Other_Advertising'
else 'Unmatched_Channel'
end

Usage


select {{ channel_classification() }} as channel,

Details

Code
Source
{% macro channel_classification() %}
{{ return(adapter.dispatch('channel_classification', 'snowplow_fractribution')()) }}
{% endmacro %}

Referenced By

Channel Spendโ€‹

macros/channel_spend.sql

Description

A macro for the user to overwrite it with a sql script to extract total ad spend by channel.

-- Example (simplified) query:

select channel, sum(spend_usd) as spend from example_spend_table group by 1

-- Example table output for the user-supplied SQL:

Channel | Spend


direct | 1050.02 paid_search | 10490.11 etc...

Returns

A sql script to extract channel and corresponding spend values from a data source.

Usage


{{ channel_spend() }}

Details

Code
Source
{% macro channel_spend() %}
{{ return(adapter.dispatch('channel_spend', 'snowplow_fractribution')()) }}
{% endmacro %}

Depends On

Referenced By

Conversion Clauseโ€‹

macros/conversion_clause.sql

Description

A macro to let users specify how to filter on conversion events.

Returns

A sql to be used in a WHERE clause to filter on conversion events.

Usage

where {{ conversion_clause() }}

Details

Code
Source
{% macro conversion_clause() %}
{{ return(adapter.dispatch('conversion_clause', 'snowplow_fractribution')()) }}
{% endmacro %}

Referenced By

Conversion Valueโ€‹

macros/conversion_value.sql

Description

A user defined macro that specifies either a single column or a calculated value that represents the value associated with the conversion.

Returns

A sql to be used to refer to the conversion value.

Usage


select {{ conversion_value() }} as revenue

Details

Code
Source
{% macro conversion_value() %}
{{ return(adapter.dispatch('conversion_value', 'snowplow_fractribution')()) }}
{% endmacro %}

Referenced By

Create Report Table Procโ€‹

macros/snowflake_snowpark/create_report_table_proc.sql

Description

This macro does not currently have a description.

Details

Code
Source
{% macro create_report_table_proc() %}
{{ return(adapter.dispatch('create_report_table_proc', 'snowplow_fractribution')()) }}
{% endmacro %}

Depends On

  • macro.dbt.run_query

Referenced By

Create Udfsโ€‹

macros/path_transformations/create_udfs.sql

Description

Creates user defined functions for adapters apart from Databricks. It is executed as part of an on-start hook.

Returns

Nothing, sql is executed which creates the UDFs in the target database and schema.

Usage

dbt_project.yml
...
on-run-start: "{{ create_udfs() }}"
...

Details

Code
Source
{% macro create_udfs() %}
{{ return(adapter.dispatch('create_udfs', 'snowplow_fractribution')()) }}
{% endmacro %}

Depends On

  • macro.dbt.run_query

Get Lookback Date Limitsโ€‹

macros/get_lookback_date_limits.sql

Description

A macro returning the upper or lower boundary to limit what is processed by the sessions_by_customer_id model.

Arguments

  • limit_type (string): Can be either 'min' or 'max' depending on if the upper or lower boundary date needs to be returned
  • model (string): Can either be 'sessions' for usage within snowplow_fractribution_sessions_by_customer_id or 'conversions' to use for snowplow_fractribution_conversions_by_customer_id

Returns

A string value of the upper or lower date limit.

Usage

A macro call with 'min' or 'max' given as a parameter.

select
...
from
...
where
date(derived_tstamp) >= '{{ get_lookback_date_limits("min") }}'
and date(derived_tstamp) <= '{{ get_lookback_date_limits("max") }}'

-- returns
select
...
from
...
where
date(derived_tstamp) >= '2023-01-01 13:45:03'
and date(derived_tstamp) <= '2023-02-01 10:32:52'

Details

Code
Source
{% macro get_lookback_date_limits(limit_type, model) %}
{{ return(adapter.dispatch('get_lookback_date_limits', 'snowplow_fractribution')(limit_type, model)) }}
{% endmacro %}

Depends On

  • macro.dbt.dateadd
  • macro.dbt.run_query
  • macro.dbt.type_string

Referenced By

Path Transformationโ€‹

macros/path_transformations/path_transformation.sql

Description

Macro to execute the indvidual path_transformation specified as a parameter.

Arguments

Returns

The transformed array column.

Usage


{{ path_transformation('unique_path') }} as transformed_path

Details

Code
Source
{% macro path_transformation(transformation_type, transform_param) %}
{{ return(adapter.dispatch('path_transformation', 'snowplow_fractribution')(transformation_type, transform_param)) }}
{% endmacro %}

Referenced By

Run Stored Procedureโ€‹

macros/snowflake_snowpark/run_stored_procedure.sql

Description

This macro does not currently have a description.

Details

Code
Source
{% macro run_stored_procedure(attribution_model, conversion_window_start_date, conversion_window_end_date) %}
{{ return(adapter.dispatch('run_stored_procedure', 'snowplow_fractribution')(attribution_model, conversion_window_start_date, conversion_window_end_date)) }}
{% endmacro %}

Depends On

  • macro.dbt.run_query

Referenced By

Transform Pathsโ€‹

macros/path_transformations/transform_paths.sql

Description

Macro to remove complexity from models paths_to_conversion / paths_to_non_conversion.

Arguments

  • model_type (string): The macro only expects 'conversions' in case it runs in the path_to_conversions in which case it adds more fields
  • source_cte (string): The name of the cte to take as an input for the macro the build sql to

Returns

The sql with the missing cte's that take care of path transformations.

Usage

It is used by the transform_paths() macro for the transformation cte sql code build. It takes a transformation type as a parameter and its optional argument, if exists. The E.g.

with base_data as (...),

{{ transform_paths('conversions', 'base_data') }}

select * from path_transforms

Details

Code
Source
{% macro transform_paths(model_type, source_cte) %}
{{ return(adapter.dispatch('transform_paths', 'snowplow_fractribution')(model_type, source_cte)) }}
{% endmacro %}

Depends On

Referenced By

Trim Long Pathโ€‹

macros/path_transformations/trim_long_path.sql

Description

Returns the last 'snowplowpath_lookback_steps' number of channels in the path if snowplowpath_lookback_steps > 0, or the full path otherwise.

Arguments

  • array_column (string): The array column to be transformed
  • lookback_steps (integer): Defaulted to be taken from the snowplow__path_lookback_steps, the number of path to leave starting from the end

Returns

The transformed array column.

Usage


select
...
{{ trim_long_path('path', var('snowplow__path_lookback_steps')) }} as path,
...
from
...

Details

Code
Source
{% macro trim_long_path(array_column, lookback_steps=var('snowplow__path_lookback_steps')) %}
{{ return(adapter.dispatch('trim_long_path', 'snowplow_fractribution')(array_column,lookback_steps)) }}
{% endmacro %}

Referenced By

Was this page helpful?