--- stage: Analytics group: Analytics Instrumentation info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments --- # Implement Snowplow tracking This page describes how to: - Implement Snowplow frontend and backend tracking - Test Snowplow events ## Snowplow JavaScript frontend tracking GitLab provides a `Tracking` interface that wraps the [Snowplow JavaScript tracker](https://docs.snowplow.io/docs/collecting-data/collecting-from-own-applications/javascript-trackers/) to track custom events. For the recommended frontend tracking implementation, see [Usage recommendations](#usage-recommendations). Structured events and page views include the [`gitlab_standard`](schemas.md#gitlab_standard) context, using the `window.gl.snowplowStandardContext` object which includes [default data](https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/views/layouts/_snowplow.html.haml) as base: | Property | Example | | -------- | ------- | | `context_generated_at` | `"2022-01-01T01:00:00.000Z"` | | `environment` | `"production"` | | `extra` | `{}` | | `namespace_id` | `123` | | `plan` | `"gold"` | | `project_id` | `456` | | `source` | `"gitlab-rails"` | | `user_id` | `789`* | _\* Undergoes a pseudonymization process at the collector level._ These properties [are overridden](https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/assets/javascripts/tracking/get_standard_context.js) with frontend-specific values, like `source` (`gitlab-javascript`), `google_analytics_id` and the custom `extra` object. You can modify this object for any subsequent structured event that fires, although this is not recommended. Tracking implementations must have an `action` and a `category`. You can provide additional properties from the [event schema](index.md#event-schema), in addition to an `extra` object that accepts key-value pairs. | Property | Type | Default value | Description | |:-----------|:-------|:---------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `category` | string | `document.body.dataset.page` | Page or subsection of a page in which events are captured. | | `action` | string | `'generic'` | Action the user is taking. Clicks must be `click` and activations must be `activate`. For example, focusing a form field is `activate_form_input`, and clicking a button is `click_button`. | | `data` | object | `{}` | Additional data such as `label`, `property`, `value` as described in [Event schema](index.md#event-schema), `context` for custom contexts, and `extra` (key-value pairs object). | ### Usage recommendations - Use [data attributes](#implement-data-attribute-tracking) on HTML elements that emit `click`, `show.bs.dropdown`, or `hide.bs.dropdown` events. - Use the [Vue mixin](#implement-vue-component-tracking) for tracking custom events, or if the supported events for data attributes are not propagating. For example, clickable components that don't emit `click`. - Use the [tracking class](#implement-raw-javascript-tracking) when tracking in vanilla JavaScript files. ### Implement data attribute tracking To implement tracking for HAML or Vue templates, add a [`data-track` attribute](#data-track-attributes) to the element. The following example shows `data-track-*` attributes assigned to a button: ```haml %button.btn{ data: { track_action: "click_button", track_label: "template_preview", track_property: "my-template" } } ``` ```html