From 14bc5bcfb1b66ac6138264d52574afb2c9cec5df Mon Sep 17 00:00:00 2001 From: Damon Gudaitis Date: Fri, 14 Apr 2023 03:26:13 -0700 Subject: [PATCH] Hotfix: restore create_custom_event macro (#179) * updating local main branch from remote * updating local main branch from remote * restore create_custom_event macro * Restoring Readme updates * Update dbt_project.yml --------- Co-authored-by: Adam Ribaudo <71573504+adamribaudo-velir@users.noreply.github.com> --- README.md | 20 ++++++++++++++++++++ dbt_project.yml | 2 +- macros/create_custom_event.sql | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 macros/create_custom_event.sql diff --git a/README.md b/README.md index 78812a63..a8b47a5e 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,26 @@ vars: conversion_events:['purchase','download'] ``` +# Custom Events + +Custom events can be generated in your project using the `create_custom_event` macro. Simply create a new model in your project and enter the following: + +``` +{{ ga4.create_custom_event('my_custom_event') }} +``` + +Note, however, that any event-specific custom parameters or default custom parameters must be defined in the global variable space as shown below: + +``` +vars: + default_custom_parameters: + - name: "some_parameter" + value_type: "string_value" + my_custom_event_custom_parameters: + - name: "some_other_parameter" + value_type: "string_value" +``` + # Incremental Loading of Event Data (and how to handle late-arriving hits) By default, GA4 exports data into sharded event tables that use the event date as the table suffix in the format of `events_YYYYMMDD` or `events_intraday_YYYYMMDD`. This package incrementally loads data from these tables into `base_ga4__events` which is partitioned on date. There are two incremental loading strategies available: diff --git a/dbt_project.yml b/dbt_project.yml index 5a3b4fd5..dd398f92 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -1,5 +1,5 @@ name: 'ga4' -version: '3.2.0' +version: '3.2.1' config-version: 2 model-paths: ["models"] analysis-paths: ["analyses"] diff --git a/macros/create_custom_event.sql b/macros/create_custom_event.sql new file mode 100644 index 00000000..48d09b42 --- /dev/null +++ b/macros/create_custom_event.sql @@ -0,0 +1,15 @@ +{%- macro create_custom_event(event_name) -%} + {{ return(adapter.dispatch('create_custom_event', 'ga4')(event_name)) }} +{%- endmacro -%} + +{%- macro default__create_custom_event(event_name) -%} + select * + {% if var("default_custom_parameters", "none") != "none" %} + {{ ga4.stage_custom_parameters( var("default_custom_parameters", "none") )}} + {% endif %} + {% if var(event_name+"_custom_parameters", "none") != "none" %} + {{ ga4.stage_custom_parameters( var(event_name+"_custom_parameters") )}} + {% endif %} + from {{ref('stg_ga4__events')}} + where event_name = '{{event_name}}' +{%- endmacro -%} \ No newline at end of file