Setting Up Snowplow as an Event Tracker
Snowplow is an advanced event tracking platform that gives you full control over your data. You can integrate it with GrowthBook to track experiment exposure events and other events.
Prerequisites
Before you begin, ensure that you have a working Snowplow tracker running on your site. Follow the Snowplow Web Tracker Quick Start Guide to get set up.
Targeting attributes
Use Snowplow's domain_user_id
as a targeting attribute by pulling it from the Snowplow tracker and passing it to GrowthBook.
Example:
window.snowplow(function() {
growthbook.updateAttributes({
domain_user_id: this.sp.getDomainUserId(),
});
});
Alternatively, if you're accessing sp
directly (e.g., when using the npm
package):
const domainUserId = sp.getDomainUserId();
growthbook.updateAttributes({
domain_user_id: domainUserId,
});
Tracking Experiment Exposure with Snowplow
To log when a user is exposed to an experiment, define a custom trackingCallback
function in your GrowthBook SDK snippet. This sends a self-describing event to Snowplow.
Example:
// In your GrowthBook SDK snippet...
trackingCallback: (experiment, result) => {
if (window.snowplow) {
window.snowplow("trackSelfDescribingEvent", {
event: {
schema: "iglu:io.growthbook/experiment_viewed/jsonschema/1-0-0",
data: {
experimentId: experiment.key,
variationId: result.key,
hashAttribute: result.hashAttribute,
hashValue: result.hashValue,
custom: [
{
key: "custom_key",
value: "custom_value",
},
],
},
},
});
}
};
Alternatively, if you're accessing sp
directly (e.g., when using the npm
package):
import { trackSelfDescribingEvent } from "@snowplow/browser-tracker";
// In your GrowthBook SDK snippet...
trackingCallback: (experiment, result) => {
trackSelfDescribingEvent({
event: {
schema: "iglu:io.growthbook/experiment_viewed/jsonschema/1-0-0",
data: {
experimentId: experiment.key,
variationId: result.key,
hashAttribute: result.hashAttribute,
hashValue: result.hashValue,
custom: [
{
key: "custom_key",
value: "custom_value",
},
],
},
},
});
};
GrowthBook's Official Schema
GrowthBook provides an official Iglu schema for experiment exposure events:
Schema URI:
iglu:io.growthbook/experiment_viewed/jsonschema/1-0-0
Testing your Integration with Snowplow Micro
Snowplow Micro is a lightweight tool that lets you test and validate your event tracking locally.
Steps:
- Start Snowplow Micro:
docker run -p 9090:9090 snowplow/snowplow-micro
- Point your Snowplow tracker to the local endpoint:
window.snowplow('newTracker', 'sp1', 'http://localhost:9090', {
appId: 'my-app-id'
})
or...
newTracker('sp1', 'http://localhost:9090', {
appId: 'my-app-id'
})
-
Run your app with GrowthBook and Snowplow configured. When an experiment is triggered, the exposure event will be sent to Snowplow Micro.
-
Open the Snowplow Micro UI in your browser:
http://localhost:9090/micro/ui
- Look for the
experiment_viewed
event to confirm the integration is working.