Skip to content

Release/snowplow attribution/0.5.0 #27

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

Merged
merged 4 commits into from
Apr 16, 2025
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
33 changes: 33 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
snowplow-attribution 0.5.0 (2025-04-16)
---------------------------------------
## Summary
This release enables passing multiple path transformations as dictionary values for transformations enabled in `dbt_project.yml` using the variable `snowplow__path_transforms`.

It is specifically related to transformations `remove_if_not_all` and `remove_if_last_and_not_all`.

### Usage example
```yml
snowplow__path_transforms: {'exposure_path': null, 'remove_if_not_all': ['placeholder_transformation_1', 'placeholder_transformation_2'], 'remove_if_last_and_not_all': ['placeholder_transformation_3', 'placeholder_transformation_4']}
```

## Features
- Allow multiple path transformation parameters

## Fixes
- Fix warning message in source checks macro
- Fix trim_long_path transformation

## 🚨 Breaking Changes 🚨
- From now on the `snowplow__path_transforms` variable parameters only accept non-empty arrays for `remove_if_last_and_not_all` and `remove_if_not_all` variables instead of strings, please your variable overwrites in your dbt_project.yml accordingly. Previously you could only remove one specific channel or campaign, now you can do multiple, if needed.

```yml title="dbt_project.yml"
vars:
snowplow_attribution:
snowplow__path_transforms: {'exposure_path': null, 'remove_if_last_and_not_all': ['channel_to_remove_1', 'campaign_to_remove_1', 'campaign_to_remove_2']}
```

## Upgrading
Update the snowplow-attribution version in your `packages.yml` file. For existing users, please follow the migration guide [here](https://docs.snowplow.io/docs/modeling-your-data/modeling-your-data-with-dbt/migration-guides/attribution/#upgrading-to-050).


snowplow-attribution 0.4.0 (2024-10-15)
---------------------------------------
## Summary
Expand All @@ -12,6 +44,7 @@ This release extends support to Apache Spark with the Iceberg file format and up
## Upgrading
Update the snowplow-attribution version in your `packages.yml` file.


snowplow-attribution 0.3.0 (2024-07-26)
---------------------------------------
## Summary
Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

name: 'snowplow_attribution'
version: '0.4.0'
version: '0.5.0'
config-version: 2

require-dbt-version: [">=1.6.0", "<2.0.0"]
Expand Down
6 changes: 3 additions & 3 deletions docs/markdown/snowplow_attribution_macros_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Error message, if it fails one of the checks.
{% docs macro_path_transformation %}

{% raw %}
Macro to execute the indvidual path_transformation specified as a parameter.
Macro to execute the individual path_transformation specified as a parameter.

#### Returns

Expand Down Expand Up @@ -132,12 +132,12 @@ 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.
It is used by the transform_paths() macro for the transformation cte sql code build. It takes a parameter to refer to which model it is used in (either conversions or non_conversions)

```sql
with base_data as (...),

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

select * from path_transforms
```
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'snowplow_attribution_integration_tests'
version: '0.4.0'
version: '0.5.0'
config-version: 2

profile: 'integration_tests'
Expand Down
79 changes: 79 additions & 0 deletions macros/path_transformations/build_ctes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{#
Copyright (c) 2024-present Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Snowplow Personal and Academic License Version 1.0,
and you may not use this file except in compliance with the Snowplow Personal and Academic License Version 1.0.
You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 at https://docs.snowplow.io/personal-and-academic-license-1.0/
#}

/* macro is for spark only */
/* Macro to remove complexity from model "transform_paths" for building spark CTEs. */

{% macro build_ctes(path_transform_name, parameter, model_type) %}
{{ return(adapter.dispatch('build_ctes', 'snowplow_attribution')(path_transform_name, parameter, model_type)) }}
{% endmacro %}

{% macro default__build_ctes(path_transform_name, parameter, model_type) %}
{% endmacro %}

{% macro spark__build_ctes(path_transform_name, parameter, model_type) %}

select
customer_id,
{% if model_type == 'conversions' %}
cv_id,
event_id,
cv_tstamp,
cv_type,
cv_path_start_tstamp,
revenue,
{% endif %}
channel_path,
{% if path_transform_name == 'unique_path' %}
{{ path_transformation('unique_path', field_alias='channel') }} as channel_transformed_path,
{% elif path_transform_name == 'frequency_path' %}
{{ exceptions.raise_compiler_error(
"Snowplow Error: Frequency path is currently not supported by the model, please remove it from the variable and use this path transformation function in a custom model."
) }}

{% elif path_transform_name == 'first_path' %}
{{ path_transformation('first_path', field_alias='channel') }} as channel_transformed_path,

{% elif path_transform_name == 'exposure_path' %}
{{ path_transformation('exposure_path', field_alias='channel') }} as channel_transformed_path,

{% elif path_transform_name == 'remove_if_not_all' %}
{{ path_transformation('remove_if_not_all', parameter, 'channel') }} as channel_transformed_path,

{% elif path_transform_name == 'remove_if_last_and_not_all' %}
{{ path_transformation('remove_if_last_and_not_all', parameter, 'channel') }} as channel_transformed_path,

{% else %}
{%- do exceptions.raise_compiler_error("Snowplow Error: the path transform - '"+path_transform_name+"' - is not supported. Please refer to the Snowplow docs on tagging. Please use one of the following: exposure_path, first_path, frequency_path, remove_if_last_and_not_all, remove_if_not_all, unique_path") %}
{% endif %}

campaign_path,
{% if path_transform_name == 'unique_path' %}
{{ path_transformation('unique_path', field_alias='campaign') }} as campaign_transformed_path

{% elif path_transform_name == 'frequency_path' %}
{{ exceptions.raise_compiler_error(
"Snowplow Error: Frequency path is currently not supported by the model, please remove it from the variable and use this path transformation function in a custom model."
) }}

{% elif path_transform_name == 'first_path' %}
{{ path_transformation('first_path', field_alias='campaign') }} as campaign_transformed_path

{% elif path_transform_name == 'exposure_path' %}
{{ path_transformation('exposure_path', field_alias='campaign') }} as campaign_transformed_path

{% elif path_transform_name == 'remove_if_not_all' %}
{{ path_transformation('remove_if_not_all', parameter, 'campaign') }} as campaign_transformed_path

{% elif path_transform_name == 'remove_if_last_and_not_all' %}
{{ path_transformation('remove_if_last_and_not_all', parameter, 'campaign') }} as campaign_transformed_path

{% else %}
{%- do exceptions.raise_compiler_error("Snowplow Error: the path transform - '"+path_transform_name+"' - is not supported. Please refer to the Snowplow docs on tagging. Please use one of the following: exposure_path, first_path, frequency_path, remove_if_last_and_not_all, remove_if_not_all, unique_path") %}
{% endif %}

{% endmacro %}
79 changes: 79 additions & 0 deletions macros/path_transformations/build_sql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{#
Copyright (c) 2024-present Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Snowplow Personal and Academic License Version 1.0,
and you may not use this file except in compliance with the Snowplow Personal and Academic License Version 1.0.
You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 at https://docs.snowplow.io/personal-and-academic-license-1.0/
#}

/* macro is for spark only */
/* Macro to remove complexity from model "transform_paths" for building spark CTEs. */

{% macro build_sql(path_transform_name, parameter, model_type) %}
{{ return(adapter.dispatch('build_sql', 'snowplow_attribution')(path_transform_name, parameter, model_type)) }}
{% endmacro %}

{% macro default__build_sql(path_transform_name, parameter, model_type) %}
{% endmacro %}

{% macro spark__build_sql(path_transform_name, parameter, model_type) %}

select
customer_id,
{% if model_type == 'conversions' %}
cv_id,
event_id,
cv_tstamp,
cv_type,
cv_path_start_tstamp,
revenue,
{% endif %}
channel_path,
{% if path_transform_name == 'unique_path' %}
{{ path_transformation('unique_path', field_alias='channel') }} as channel_transformed_path,
{% elif path_transform_name == 'frequency_path' %}
{{ exceptions.raise_compiler_error(
"Snowplow Error: Frequency path is currently not supported by the model, please remove it from the variable and use this path transformation function in a custom model."
) }}

{% elif path_transform_name == 'first_path' %}
{{ path_transformation('first_path', field_alias='channel') }} as channel_transformed_path,

{% elif path_transform_name == 'exposure_path' %}
{{ path_transformation('exposure_path', field_alias='channel') }} as channel_transformed_path,

{% elif path_transform_name == 'remove_if_not_all' %}
{{ path_transformation('remove_if_not_all', parameter, 'channel') }} as channel_transformed_path,

{% elif path_transform_name == 'remove_if_last_and_not_all' %}
{{ path_transformation('remove_if_last_and_not_all', parameter, 'channel') }} as channel_transformed_path,

{% else %}
{%- do exceptions.raise_compiler_error("Snowplow Error: the path transform - '"+path_transform_name+"' - is not supported. Please refer to the Snowplow docs on tagging. Please use one of the following: exposure_path, first_path, frequency_path, remove_if_last_and_not_all, remove_if_not_all, unique_path") %}
{% endif %}

campaign_path,
{% if path_transform_name == 'unique_path' %}
{{ path_transformation('unique_path', field_alias='campaign') }} as campaign_transformed_path

{% elif path_transform_name == 'frequency_path' %}
{{ exceptions.raise_compiler_error(
"Snowplow Error: Frequency path is currently not supported by the model, please remove it from the variable and use this path transformation function in a custom model."
) }}

{% elif path_transform_name == 'first_path' %}
{{ path_transformation('first_path', field_alias='campaign') }} as campaign_transformed_path

{% elif path_transform_name == 'exposure_path' %}
{{ path_transformation('exposure_path', field_alias='campaign') }} as campaign_transformed_path

{% elif path_transform_name == 'remove_if_not_all' %}
{{ path_transformation('remove_if_not_all', parameter, 'campaign') }} as campaign_transformed_path

{% elif path_transform_name == 'remove_if_last_and_not_all' %}
{{ path_transformation('remove_if_last_and_not_all', parameter, 'campaign') }} as campaign_transformed_path

{% else %}
{%- do exceptions.raise_compiler_error("Snowplow Error: the path transform - '"+path_transform_name+"' - is not supported. Please refer to the Snowplow docs on tagging. Please use one of the following: exposure_path, first_path, frequency_path, remove_if_last_and_not_all, remove_if_not_all, unique_path") %}
{% endif %}

{% endmacro %}
Loading
Loading