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

Support for Custom Item Parameters #331

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ vars:
- name: "country_code"
value_type: "int_value"
```
### Custom Item Parameters

If you are capturing custom parameters at the item level (within items.item_params), you can specify these parameters and make them available in the `stg_ga4__event_items` model. This uses a similar syntax as the "Custom Parameters" feature described above:

```
vars:
ga4:
custom_item_parameters:
- name: "item_variant_color"
value_type: "string_value"
rename_to: "color"
```

### User Properties

Expand Down
5 changes: 5 additions & 0 deletions macros/stage_custom_parameters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
{% endfor %}
{% endmacro %}

{% macro stage_custom_item_parameters(custom_item_parameters) %}
{% for cip in custom_item_parameters %}
,{{ ga4.unnest_key('i.item_params', cip.name , cip.value_type, cip.rename_to or "default" ) }}
{% endfor %}
{% endmacro %}
63 changes: 33 additions & 30 deletions models/staging/stg_ga4__event_items.sql
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
with items_with_params as (
select
event_key,
event_name,
event_date_dt,
stream_id,
i.item_id,
i.item_name,
i.item_brand,
i.item_variant,
i.item_category,
i.item_category2,
i.item_category3,
i.item_category4,
i.item_category5,
i.price_in_usd,
i.price,
i.quantity,
i.item_revenue_in_usd,
i.item_revenue,
i.item_refund_in_usd,
i.item_refund,
i.coupon,
i.affiliation,
i.location_id,
i.item_list_id,
i.item_list_name,
i.item_list_index,
i.promotion_id,
i.promotion_name,
i.creative_name,
i.creative_slot
event_key
, event_name
, event_date_dt
, stream_id
, i.item_id
, i.item_name
, i.item_brand
, i.item_variant
, i.item_category
, i.item_category2
, i.item_category3
, i.item_category4
, i.item_category5
, i.price_in_usd
, i.price
, i.quantity
, i.item_revenue_in_usd
, i.item_revenue
, i.item_refund_in_usd
, i.item_refund
, i.coupon
, i.affiliation
, i.location_id
, i.item_list_id
, i.item_list_name
, i.item_list_index
, i.promotion_id
, i.promotion_name
, i.creative_name
, i.creative_slot
{% if var("custom_item_parameters", "none") != "none" %}
{{ ga4.stage_custom_item_parameters( var("custom_item_parameters") )}}
{% endif %}
from {{ref('stg_ga4__events')}},
unnest(items) as i
where event_name in ('add_payment_info', 'add_shipping_info', 'add_to_cart','add_to_wishlist','begin_checkout' ,'purchase','refund', 'remove_from_cart','select_item', 'select_promotion','view_item_list','view_promotion', 'view_item')
Expand Down
Loading