fivetran / dbt_amplitude

Fivetran's Amplitude dbt package
https://fivetran.github.io/dbt_amplitude/
Apache License 2.0
3 stars 3 forks source link
amplitude dbt dbt-packages fivetran fivetran-product-analytics-reporting product-analytics

Amplitude Modeling dbt Package (Docs)

What does this dbt package do?

This package also generates a comprehensive data dictionary of your source and modeled Amplitude data through the dbt docs site. You can also refer to the table below for a detailed view of all tables materialized within this package by default.

Table Description
amplitude__event_enhanced Each record represents event data, enhanced with event type data and unnested event, group, and user properties.
amplitude__sessions Each record represents a distinct session with aggregated metrics for that session.
amplitude__user_enhanced Each record represents a distinct user with aggregated metrics for that user.
amplitude__daily_performance Each record represents performance metrics for each distinct day and event type.

How do I use the dbt package?

Step 1: Prerequisites

To use this dbt package, you must have the following:

Databricks dispatch configuration

If you are using a Databricks destination with this package, you must add the following (or a variation of the following) dispatch configuration within your dbt_project.yml file. This is required in order for the package to accurately search for macros within the dbt-labs/spark_utils then the dbt-labs/dbt_utils packages respectively.

dispatch:
  - macro_namespace: dbt_utils
    search_order: ['spark_utils', 'dbt_utils']

Step 2: Install the package

Include the following Amplitude package version in your packages.yml file:

TIP: Check dbt Hub for the latest installation instructions, or read the dbt docs for more information on installing packages.

packages:
- package: fivetran/amplitude
version: [">=0.4.0", "<0.5.0"] # we recommend using ranges to capture non-breaking changes automatically

Do NOT include the amplitude_source package in this file. The transformation package itself has a dependency on it and will install the source package as well.

Step 3: Define database and schema variables

By default, this package will run using your target database and the amplitude schema. If this is not where your Amplitude data is, add the following configuration to your root dbt_project.yml file:

# dbt_project.yml

...
config-version: 2

vars:
    amplitude_database: your_database_name    
    amplitude_schema: your_schema_name

Step 4: Configure event date range

Because of the typical volume of event data, you may want to limit this package's models to work with a recent date range. However, note that the amplitude__daily_performance, amplitude__event_enhanced, and amplitude__sessions final models are materialized as incremental tables.

The default date range for the stg_amplitude__event model starts at '2020-01-01' and ends one month past the current day. Conversely, for the date spine model in this package the default date range starts at 2020-01-01 and ends one day after the current day. To customize the date range, add the following configurations to your root dbt_project.yml file:

# dbt_project.yml
...
vars:
    amplitude__date_range_start: '2022-01-01' # your start date here
    amplitude__date_range_end: '2022-12-01' # your end date here

If you adjust the date range variables, we recommend running dbt run --full-refresh to ensure no data quality issues within the adjusted date range.

(Optional) Step 5: Additional configurations

Expand for configurations #### Change source table references If an individual source table has a different name than the package expects, add the table name as it appears in your destination to the respective variable: > IMPORTANT: See the package's source [`dbt_project.yml`](https://github.com/fivetran/dbt_amplitude_source/blob/main/dbt_project.yml) variable declarations to see the expected names. ```yml # dbt_project.yml ... config-version: 2 vars: ___identifier: your_table_name ``` #### Change build schema By default, this package builds the GitHub staging models within a schema titled ( + `_stg_amplitude`) in your target database. If this is not where you would like your GitHub staging data to be written to, add the following configuration to your root `dbt_project.yml` file: ```yml # dbt_project.yml models: amplitude_source: +schema: my_new_schema_name # leave blank for just the target_schema ``` #### Pivot out nested fields containing custom properties The Amplitude schema allows for custom properties to be passed as nested fields (for example, `user_properties: {"Cohort":"Test A"}`). To pivot out the properties, add the following configurations to your root `dbt_project.yml` file: ```yml # dbt_project.yml ... vars: event_properties_to_pivot: ['event_property_1','event_property_2'] group_properties_to_pivot: ['group_property_1','group_property_2'] user_properties_to_pivot: ['user_property_1','user_property_2'] ```


(Optional) Step 6: Using this package with the dbt Product Analytics package

Expand for configurations The [dbt_product_analytics](https://github.com/mjirv/dbt_product_analytics) package contains macros that allows for further exploration such as event flow, funnel, and retention analysis. To leverage this in conjunction with this package, add the following configuration to your project's `packages.yml` file: ```yml packages: - package: mjirv/dbt_product_analytics version: [">=0.1.0"] ``` Refer to the [dbt_product_analytics](https://github.com/mjirv/dbt_product_analytics) usage instructions and the example below: ```sql -- # product_analytics_funnel.sql {% set events = dbt_product_analytics.event_stream( from=ref('amplitude__event_enhanced'), event_type_col="event_type", user_id_col="amplitude_user_id", date_col="event_day", start_date="your_start_date", end_date="your_end_date") %} {% set steps = ["event_type_1", "event_type_2", "event_type_3"] %} {{ dbt_product_analytics.funnel(steps=steps, event_stream=events) }} ```


(Optional) Step 7: Orchestrate your models with Fivetran Transformations for dbt Core™

Expand for details
Fivetran offers the ability for you to orchestrate your dbt project through the [Fivetran Transformations for dbt Core™](https://fivetran.com/docs/transformations/dbt) product. Refer to the linked docs for more information on how to setup your project for orchestration through Fivetran.

Does this package have dependencies?

This dbt package is dependent on the following dbt packages. These dependencies are installed by default within this package. For more information on the following packages, refer to the dbt hub site.

IMPORTANT: If you have any of these dependent packages in your own packages.yml file, we highly recommend that you remove them from your root packages.yml to avoid package version conflicts.


packages:
- package: fivetran/amplitude_source
version: [">=0.3.0", "<0.4.0"]
- package: fivetran/fivetran_utils
  version: [">=0.4.0", "<0.5.0"]

- package: dbt-labs/dbt_utils
  version: [">=1.0.0", "<2.0.0"]

- package: dbt-labs/spark_utils
  version: [">=0.3.0", "<0.4.0"]

## How is this package maintained and can I contribute?
### Package Maintenance
The Fivetran team maintaining this package **only** maintains the latest version of the package. We highly recommend you stay consistent with the [latest version](https://hub.getdbt.com/fivetran/amplitude/latest/) of the package and refer to the [CHANGELOG](https://github.com/fivetran/dbt_amplitude/blob/main/CHANGELOG.md) and release notes for more information on changes across versions.

### Opinionated Decisions
In creating this package, which is meant for a wide range of use cases, we had to take opinionated stances on a few different questions we came across during development. We've consolidated significant choices we made in the [DECISIONLOG.md](https://github.com/fivetran/dbt_amplitude/blob/main/DECISIONLOG.md), and will continue to update as the package evolves. We are always open to and encourage feedback on these choices, and the package in general.

### Contributions
These dbt packages are developed by a small team of analytics engineers at Fivetran. However, the packages are made better by community contributions.

We highly encourage and welcome contributions to this package. Check out [this post](https://discourse.getdbt.com/t/contributing-to-a-dbt-package/657) on the best workflow for contributing to a package.

## Are there any resources available?
- If you encounter any questions or want to reach out for help, see the [GitHub Issue](https://github.com/fivetran/dbt_amplitude/issues/new/choose) section to find the right avenue of support for you.
- If you would like to provide feedback to the dbt package team at Fivetran, or would like to request a future dbt package to be developed, then feel free to fill out our [Feedback Form](https://www.surveymonkey.com/r/DQ7K7WW).