Skip to main content

For AI agents: a Markdown version of this page is at https://docs.snowplow.io/docs/api-reference/snowplow-cli/tracking-plans.md. The index of all documentation pages is at https://docs.snowplow.io/llms.txt, and the index for this section is at https://docs.snowplow.io/docs/api-reference/llms.txt.

Managing tracking plans via the CLI

Terminology

We originally called tracking plans "data products". You'll still find the old term used in some existing APIs and CLI commands.

  • Cloud: available
  • Private Managed Cloud: available
  • Self-Hosted: not available
  • Add-on: not available

The data-products subcommand of Snowplow CLI provides a collection of functionality to ease the integration of custom development and publishing workflows.

Snowplow CLI Prerequisites​

Installed and configured Snowplow CLI

Available commands​

Creating tracking plan​

bash
snowplow-cli dp generate --data-product my-data-product

This command creates a minimal tracking plan template in a new file ./data-products/my-data-product.yaml.

Creating source application​

bash
snowplow-cli dp generate --source-app my-source-app

This command creates a minimal source application template in a new file ./data-products/source-apps/my-source-app.yaml.

Creating event specification​

To create an event specification, you need to modify the existing data-product file and add an event specification object. Here's a minimal example:

yaml./data-products/test-cli.yaml
apiVersion: v1
resourceType: data-product
resourceName: 3d3059c4-d29b-4979-a973-43f7070e1dd0
data:
name: test-cli
sourceApplications: []
eventSpecifications:
- resourceName: 11d881cd-316e-4286-b5d4-fe7aebf56fca
name: test
event:
source: iglu:com.snowplowanalytics.snowplow/button_click/jsonschema/1-0-0
note

The source fields of events and entities must refer to a deployed data structure. Referring to a locally created data structure is not yet supported.

Linking tracking plan to a source application​

To link a tracking plan to a source application, provide a list of references to the source application files in the data.sourceApplications field. Here's an example:

yaml./data-products/test-cli.yaml
apiVersion: v1
resourceType: data-product
resourceName: 3d3059c4-d29b-4979-a973-43f7070e1dd0
data:
name: test-cli
sourceApplications:
- $ref: ./source-apps/my-source-app.yaml

Modifying the event specifications source applications​

By default event specifications inherit all the source applications of the tracking plan. If you want to customise it, you can use the excludedSourceApplications in the event specification description to remove a given source application from an event specification.

yaml./data-products/test-cli.yaml
apiVersion: v1
resourceType: data-product
resourceName: 3d3059c4-d29b-4979-a973-43f7070e1dd0
data:
name: test-cli
sourceApplications:
- $ref: ./source-apps/generic.yaml
- $ref: ./source-apps/specific.yaml
eventSpecifications:
- resourceName: 11d881cd-316e-4286-b5d4-fe7aebf56fca
name: All source apps
event:
source: iglu:com.snowplowanalytics.snowplow/button_click/jsonschema/1-0-0
- resourceName: b9c994a0-03b2-479c-b1cf-7d25c3adc572
name: Not quite everything
excludedSourceApplications:
- $ref: ./source-apps/specific.yaml
event:
source: iglu:com.snowplowanalytics.snowplow/button_click/jsonschema/1-0-0

In this example event specification All source apps is related to both generic and specific source apps, but event specification Not quite everything is related only to the generic source application.

Downloading tracking plans, event specifications and source apps​

bash
snowplow-cli dp download

This command retrieves all organization tracking plans, event specifications, and source applications. By default, it creates a folder named data-products in your current working directory. You can specify a different folder name as an argument if needed. The command creates the following structure:

  • A main data-products folder containing your tracking plan files
  • A source-apps subfolder containing source application definitions
  • Event specifications embedded within their related tracking plan files.

Validating tracking plans, event specifications and source applications​

bash
snowplow-cli dp validate

This command scans all files under ./data-products and validates them using Snowplow Console. It checks:

  1. Whether each file is in a valid format (YAML/JSON) with correctly formatted fields
  2. Whether all source application references in the tracking plan files are valid
  3. Whether event specification rules are compatible with their schemas If validation fails, the command displays the errors in the console and exits with status code 1.

Syncing tracking plans, event specifications and source applications​

bash
snowplow-cli dp sync

This command locates all files under ./data-products, validates them, and pushes local changes to Console. Tracking plans and source applications are updated in place. For event specifications, Console may create a new version in draft status if the change is structural: a change to the name, the event, or the entities, including their property rules and entity cardinality.

Deprecated alias

The old publish command has been renamed to sync. Running dp publish still works as an alias for backward compatibility, but it may be removed in a future release. Update your scripts to use dp sync instead.

Releasing event specifications​

bash
snowplow-cli dp release

This command first syncs local files with Console (like sync), then releases any draft event specifications. Releasing marks event specifications as published and enables event spec inference. Only event specifications that are part of the local tracking plan files are affected — other event specifications in Console are left unchanged. Event specifications without an event are skipped.

Use sync if you only want to push changes without changing event specification status.

Declare event specification versions​

Applies to Snowplow CLI 0.4.0+Latest: 0.5.0

Console gives every event specification a version number. When you declare that version in your tracking plan files, the CLI checks that each change to a file raises it exactly as Console will, so the version in your files is the version Console assigns. The CLI doesn't check an event specification without a version field.

Declare versions when you manage tracking from a repository. Snowtype needs them to generate code from your repository, and they let you review every version change in a pull request. Without a version field, Console still assigns a version when you sync, but nothing checks that your files and the generated code match it.

Console sets the expected version as follows:

  • A new event specification starts at 0
  • A change to the name, the event, or the entities, including their property rules and entity cardinality, raises the version by one
  • Any other change, such as a new description, keeps the same version

Console counts versions per organization.

To declare versions and keep them correct, follow these steps.

Add the versions Console holds​

To start declaring versions in files that already exist, write the version Console holds into each event specification:

bash
snowplow-cli dp validate --fix

The command adds one version line per event specification. Adding versions changes nothing in Console: dp sync and dp release report no changes to apply.

You can also write the versions with snowplow-cli dp download --versions. The download overwrites your files with the copy in Console, so any change you haven't synced yet is lost. Use it only when your files match Console. Otherwise, use dp validate --fix instead.

It's best to commit the versions in a pull request of their own. On that pull request, the check against the point where the branch started finds no version at the base and skips those event specifications, so a structural change in the same pull request would be checked only against Console.

Raise the version when you change an event specification​

When you make a structural change to an event specification, run --fix to raise its version. The --fix flag works with the offline check and the check against Console, and writes the expected version into each event specification: it replaces a declared version that differs, and adds one where none is declared and the expected version is known. Update your branch from the base branch before you run --fix, as the warning in Troubleshooting explains.

bash
snowplow-cli dp validate --fix

For example, making the plan entity optional changes the entity cardinality, so --fix moves Signup from version 0 to 1:

yaml./data-products/signup-flow.yaml
eventSpecifications:
- resourceName: 00000000-0000-4000-8000-000000000003
name: Signup
version: 1
description: Someone created an account and picked a plan
event:
source: iglu:com.example/signup/jsonschema/1-0-0
entities:
tracked:
- source: iglu:com.example/plan/jsonschema/1-0-0
minCardinality: 0
maxCardinality: 1

You can also edit the version by hand: a structural change raises it by one.

Check versions against the point where the branch started​

dp validate offline compares the versions in your files with the same files at the commit where your branch started from --base-ref. The offline check needs no credentials and doesn't contact Console. It runs git, so git must be installed, and it needs the full history and the base ref.

bash
snowplow-cli dp validate offline --base-ref develop

The offline check exits with status 0 when every version matches, and with status 1 when a version is wrong. See Troubleshooting for each error and its fix.

To write the expected versions into your files without credentials, add --fix:

bash
snowplow-cli dp validate offline --base-ref develop --fix

In GitHub Actions, fetch the full history, because the shallow clone that actions/checkout creates by default has no point to compare with:

yaml
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: snowplow-cli dp validate offline --base-ref origin/develop --gh-annotate

The offline check covers event specification versions only. For a data structure that skips a version, see Validating data structures.

Verify the versions against Console​

dp validate compares the versions in your files with the versions Console holds, and needs credentials:

bash
snowplow-cli dp validate

The command exits with status 0 when every declared version matches the version Console will assign. dp sync and dp release run the same check before they write anything, including with --dry-run, and refuse to publish when a version doesn't match. See Troubleshooting for each error and its fix.

Troubleshooting​

The version checks print these errors and exit with status 1. Each error names the event specification it applies to.

  • needs a bump: your files, or Console, hold a structural change that the declared version doesn't reflect. The offline check, dp validate, dp sync, and dp release all print it, with what changed and the expected version. To fix it, update your branch from the base branch, so your files hold every change already published from other branches, then run the --fix command that the message names, and run the check again.

    3:32PM ERRO validating file=data-products/signup-flow.yaml path=/data/eventSpecifications/0
    errors=
    │ Signup: version 0 needs a bump
    │ changed: entities
    │ expected version: 1
    │ run `snowplow-cli dp validate offline --base-ref develop --fix` to update it

    3:32PM ERRO validation failed 1 errors
  • does not match: the declared version differs from the expected one for a reason other than a structural change, such as a new event specification that doesn't start at 0, which the message marks as new event specification. To fix it, run the --fix command that the message names.

    4:25PM ERRO validating file=data-products/signup-flow.yaml path=/data/eventSpecifications/1
    errors=
    │ Signup with GitHub: version 2 does not match
    │ new event specification
    │ expected version: 0
    │ run `snowplow-cli dp validate offline --base-ref develop --fix` to update it

    4:25PM ERRO validation failed 1 errors
  • Version mismatch on event spec: someone made a structural change to the event specification in Console after dp sync or dp release checked your files, but before the command wrote them. Console refuses the write, because it would assign a different version from the one in your files, and the command writes nothing. To fix it, update your branch so your files hold that change, run snowplow-cli dp validate --fix, and run dp sync or dp release again. If you run dp validate first instead, it reports the change as a needs a bump error with the new expected version.

    4:27PM ERRO bad response: {Version mismatch on event spec Signup id: 00000000-0000-4000-8000-000000000003: expected version 4, the platform would assign version 5}
  • could not find where the branch started from origin/develop: the repository doesn't have the base ref, or doesn't have enough history to find where the branch started from it. The error happens in the shallow clone that actions/checkout creates by default. A clone without the base ref prints fatal: Not a valid object name origin/develop, and a clone that has the base ref but not the history prints exit status 1: with nothing after it. To fix it, fetch the full history, for example with fetch-depth: 0 on actions/checkout, and make sure the base ref is fetched.

    12:23PM ERRO could not find where the branch started from origin/develop: fetch the full history (for example actions/checkout with fetch-depth: 0) and make sure origin/develop is fetched: git merge-base HEAD origin/develop failed: exit status 128: fatal: Not a valid object name origin/develop
    12:23PM ERRO could not find where the branch started from origin/develop: fetch the full history (for example actions/checkout with fetch-depth: 0) and make sure origin/develop is fetched: git merge-base HEAD origin/develop failed: exit status 1:
warning
Update your branch before running --fix

If you run --fix on a branch that isn't up to date, it writes the expected version into a file that still holds the older entities, and the next sync publishes them over the other change.

Was this page helpful?