Tracking Events
Snowplow has been built to enable you to track a wide range of events that occur when users interact with your apps.
We provide several built-in methods to help you track different kinds of events. The methods range from single purpose methods, such as screenView
, to the more complex but flexible selfDescribing
, which can be used to track any kind of user behavior. We strongly recommend using selfDescribing
for your tracking, as it allows you to design custom event types to match your business requirements. This post on our blog, "Re-thinking the structure of event data" might be informative here.
Tracking methods supported by the Roku Tracker:
Method | Event type tracked |
---|---|
selfDescribing | Custom event based on "self-describing" JSON schema |
structured | Semi-custom structured event |
screenView | View of screen |
All the methods share common features and parameters. Every type of event can have an optional context added. A Timestamp can also be provided for all event types to override the default event timestamp. See the next page to learn about adding extra data to events. It's important to understand how event context works, as it is one of the most powerful Snowplow features. Adding event context is a way to add depth, richness and value to all of your events.
Snowplow events are all processed into the same format, regardless of the event type (and regardless of the tracker language used). Read about the different properties and fields of events in the Snowplow Tracker Protocol.
We will first discuss the custom event tracking methods, followed by the out-of-the-box event types. Note that you can also design and create your own page view, or screen view, using selfDescribing
, to fit your business needs better. The out-of-the-box event types are provided so you can get started with generating event data quickly.
Track self-describing events with selfDescribing
Use selfDescribing
to track a custom event. This is the most advanced and powerful tracking method, which requires a certain amount of planning and infrastructure.
Self-describing events are based around "self-describing" (self-referential) JSONs, which are a specific kind of JSON schema. A unique schema can be designed for each type of event that you want to track. This allows you to track the specific things that are important to you, in a way that is defined by you.
This is particularly useful when:
- You want to track event types which are proprietary/specific to your business
- You want to track events which have unpredictable or frequently changing properties
A self-describing JSON has two keys, schema
and data
. The schema
value should point to a valid self-describing JSON schema. They are called self-describing because the schema will specify the fields allowed in the data value. Read more about how schemas are used with Snowplow here.
After events have been collected by the event collector, they are validated to ensure that the properties match the self-describing JSONs. Mistakes (e.g. extra fields, or incorrect types) will result in events being processed as Bad Events. This means that only high-quality, valid events arrive in your data storage or real-time stream.
Your schemas must be accessible to your pipeline to allow this validation. We provide Iglu for schema management.
- Within Snowplow BDP, you can manage your schemas through your console.
- For Snowplow Open Source, see igluctl.
- If you are using Snowplow Micro for testing or debugging, this guide explains how to configure custom schemas.
The selfDescribing
method takes a roAssociativeArray
. This array takes a schema name and a flat hash of event data.
Example (assumes that you mounted the Snowplow instance in m.global.snowplow
):
m.global.snowplow.selfDescribing = {
data: {
saveId: "4321",
level: 23,
difficultyLevel: "HARD",
dlContent: true
},
schema: "iglu:com.example_company/save_game/jsonschema/1-0-2"
}
Track structured events with structured
This method provides a halfway-house between tracking fully user-defined self-describing events and out-of-the box predefined events. This event type can be used to track many types of user activity, as it is somewhat customizable. "Struct" events closely mirror the structure of Google Analytics events, with "category" (se_ca
), "action" (se_ac
), "label" (se_la
), and "value" (se_va
) properties.
As these fields are fairly arbitrary, we recommend following the advice in this table how to define structured events. It's important to be consistent throughout the business about how each field is used.
Argument | Description | Required in event? |
---|---|---|
se_ca | The grouping of structured events which this action belongs to | Yes |
se_ac | Defines the type of user interaction which this event involves | Yes |
se_la | Often used to refer to the 'object' the action is performed on | No |
se_pr | Describing the 'object', or the action performed on it | No |
se_va | Provides numerical data about the event | No |
Example:
m.global.snowplow.structured = {
se_ca: "shop",
se_ac: "add-to-basket",
se_pr: "pcs",
se_va: 2
}
Track screen views with screenView
Use screenView
to track a user viewing a screen (or similar) within your app. This is the page view equivalent for apps that are not webpages. The arguments are name
, id
, type
, and transitionType
; while all are optional, you must provided at least one of either name
or id
to create a valid event. "Name" is the human-readable screen name, and "ID" should be the unique screen ID.
This method creates an unstruct event, by creating and tracking a self-describing event. The schema ID for this is "iglu:com.snowplowanalytics.snowplow/screen_view/jsonschema/1-0-0", and the data field will contain the parameters which you provide. That schema is hosted on the schema repository Iglu Central, and so will always be available to your pipeline.
Example:
m.global.snowplow.screenView = {
id: "screen23",
name: "HUD > Save Game"
}