Skip to main content

Context entities

Custom context can be used to augment any standard Snowplow event type, including self-describing events, with additional data. We refer to this custom context as entities.

The context is an array of entities. More than one entity (of either different or the same type) can be attached to an event. The context argument (if it is provided at all) should be a non-empty array.

As with self-describing events, if you want to create your own custom context, you will need to create a corresponding schema. Snowplow uses the schema to validate that the JSON containing the context properties is well-formed.

Each individual entity is a self-describing JSON such as:

{
"schema": "iglu:com.my_company/user/jsonschema/1-0-0",
"data": {
"fb_uid": "9999xyz"
}
}
info

"iglu:com.my_company/user/jsonschema/1-0-0" respresents a self-describing JSON. It is used to validate the event data against a predefined JSON Schema as part of a Snowplow pipeline.

How are context entities serialized in event payload?

All entities attached to an event will be wrapped in an array by the user and passed to the tracker, which will wrap them in a self-describing JSON:

{

// Tells Snowplow this is an array of custom contexts
"schema": "iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0",
"data": [
{

// Tells Snowplow that this is a "user" context
"schema": "iglu:com.my_company/user/jsonschema/1-0-0",
"data": {

// The context data itself
"fb_uid": "9999xyz"
}
}
]
}

Trackers can be configured to encode the context into URL-safe Base64 to ensure that no data is lost or corrupted. The downside is that the data will be bigger and less readable.

ParameterTable ColumnTypeDescriptionExample values
cocontextJSONAn array of custom contexts%7B%22schema%22:%22iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0%22,%22data%22:%5B%7B%22schema%22:%22iglu:com.my_company/user/jsonschema/1-0-0%22,%22data%22:%7B%22fb_uid%22:%229999xyz%22%7D%7D%5D%7D
cxcontextJSON (URL-safe Base64 encoded)An array of custom contextsew0KICBzY2hlbWE6ICdpZ2x1OmNvbS5zbm93cGxvd2FuYWx5dGljcy5zbm93cGxvdy9jb250ZXh0cy9qc29uc2NoZW1hLzEtMC0wJyANCiAgZGF0YToge1sNCiAgICB7DQogICAgICBzY2hlbWE6ICdpZ2x1OmNvbS5teV9jb21wYW55L3VzZXIvanNvbnNjaGVtYS8xLTAtMCcgDQogICAgICBkYXRhOiB7DQogICAgICAgIGZiX3VpZDogJzk5OTl4eXonDQogICAgICB9DQogICAgfQ0KICBdfQ0KfQ==
note

The exact field names may vary depending on your warehouse, for snowflake/bigquery/databricks you will find unstruct_ or context_ at the front and for bigquery you will see an extended version number at the end such as 1_0_0.

Was this page helpful?