Skip to content

Use the create_custom_event macro for all default events #369

Description

@dgitis

Switch the events, and recommended_events included by default in the package to use the create_custom_event macro and use variables in the package dbt_project.yml file to implement the Google-recommended parameters.

Doing this will allow package users to override the defaults including removing required parameters (they aren't required when working out of BigQuery) and removing dis-used optional parameters.

It also means that users can override those settings in the project dbt_project.yml file and create a single place to hold all event parameter definitions.

This will then allow us to create a build_event_model macro for event fact models that will automatically pick up the settings from the dbt_project.yml file. This results in more consistent implementations.

Here's an example:

{% macro build_event_model( event_name ) %}
    event_key
    , session_key
    , client_key 
    , page_key
    , user_id
    , steam_id
    , event_name
    , event_date_dt
    , event_timestamp
    , page_path
    , page_location
    , page_referrer
    , original_page_location
    , original_page_referrer
    , device_category
    , device_web_info_browser
    , geo_country
    , geo_region
    , geo_city
    , geo_metro
    , session_region
    {% if var("default_custom_parameters", "none") != "none" -%}
        {{ return_custom_parameters(var("default_custom_parameters")) }}
    {% endif %}
    {% if var(event_name+"_custom_parameters", "none") != "none" -%}
        {{ return_custom_parameters(var(event_name+"_custom_parameters")) }}
    {% endif %}
{% endmacro %}

Whenever I've done this in the past, I've only created the interior of the select statement so that I can manually add calculations to event models in the model while leaving the common parts in the macro.

Event settings probably should be set at global scope rather than under ga4 so that they can be used at project-level and package level.

models:
  event_custom_parameters:
    -these can be accessed at package- and project-level
  ga4:
    other_event_custom_parameters:
      - these are stuck in GA4 scope

Finally, this lets us put all event configurations in the dbt_project.yml file. Having just one place to manage all parameters makes it easier to manage and understand an implementation and lets us automate parameter creation. This Colab notebook gets close.

I have had clients specifically request a single file where all parameters are set.

I'm not sure if it is possible to do this, but we may want to move all event settings to another file and then import them into the dbt_project.yml file similar to how you can use env_var in YAML files because the event settings can make the configuration quite long.

If we go this route, we may want to include a fct_ga4__event_page_view model and maybe a fct_ga4__events model (which would require some customization of the previous macro code) to show how users are expected to use this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

7.0-candidateRelease 7.0 uses the new fields and tables deployed after the launch of GA4

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions