By running reflekt dbt, you can create a dbt package the models and documents the events in your tracking plan.
When templating a plan (e.g. reflekt dbt --name my-plan --schema my_app_web
), Reflekt names folders and files in the default structure shown below:
# In Reflekt project
dbt-packages
└── reflekt_<project_name>_<cdp>
├── analyses
├── macros
├── models
│ └── <schema_or_alias>
│ ├── <docs_prefix>_<schema_or_alias>__<event_name>.yml
│ ├── <src_prefix>_reflekt_my_app_web.yml
│ ├── <model_prefix>_<schema_or_alias>__<event_name>.sql
│ └── <model_prefix>_<schema_or_alias>__tracks.sql
├── seeds
├── snapshots
├── tests
├── .gitignore
├── dbt_project.yml
└── README.md
Where:
<project_name>
is automatically replaced with the project name:
config defined in the reflekt_project.yml
(see Reflekt Project Configuration docs).
<cdp>
is automatically replaced with the cdp:
config defined in your reflekt_config.yml
(see Reflekt Profile Configuration docs).
<schema_or_alias>
is determined by the --schema
argument provided when running the reflekt dbt command. If a schema_alias
is defined for the plan in reflekt_project.yml
(see Reflekt Project Configuration docs), it will be used in place of the --schema
argument.
<event_name>
is the name of the event in the tracking plan.
<src_prefix>
is prefix defined in reflekt_project.yml
(see Reflekt Project Configuration docs) under:
dbt:
templater:
source:
prefix: _src_reflekt_ # Default value [required]
<model_prefix>
is prefix defined in reflekt_project.yml
(see Reflekt Project Configuration docs) under:
dbt:
templater:
models:
prefix: reflekt_ # Default value [required]
<docs_prefix>
is prefix defined in reflekt_project.yml
(see Reflekt Project Configuration docs) under:
dbt:
templater:
docs:
prefix: _reflekt_ # Default value [required]
Unlike events which are custom to your products analytics instrumentation, pages, screens, users, and groups are general concepts in most Customer Data Platforms (e.g. Segment). In order to have Reflekt template dbt sources, models, and docs for these general data sources, you must include the following your analytics governance tool and/or Reflekt tracking plan.
Analytics Governance Tool | Reflekt tracking plan | Templated files in Reflekt dbt package |
---|---|---|
Define User traits/properties | user-traits.yml |
<model_prefix>_<schema_or_alias>__users.sql |
<docs_prefix>_<schema_or_alias>__users.yml
|
| Define Group traits/properties | group-traits.yml
| <model_prefix>_<schema_or_alias>__groups.sql
<docs_prefix>_<schema_or_alias>__groups.yml
|
| Define a ‘Page Viewed’ event
(in your naming convention) | page-viewed.yml
| <model_prefix>_<schema_or_alias>__pages.sql
<docs_prefix>_<schema_or_alias>__pages.sql
|
| Define a ‘Screen Viewed’ event
(in your naming convention) | screen-viewed.yml
| `<model_prefix>_<schema_or_alias>__screens.sql
<docs_prefix>_<schema_or_alias>__screens.sql` |
Tests
You can configure Reflekt to add a not_null
and unique
test on the id columns of models it generates. This is configured in the reflekt_project.yml
like so: