Skip to main content

Amplitude

Sumatra can send events to Amplitude analytics when a visitor is assigned to a targeted experience or experiment. This allows you to add the Sumatra experience as additional context when analyzing traffic and conversions in Amplitude.

Impressions

To asynchronously send a Variants Seen event on every page view, add the following code directly on your page, below the Sumatra snippet, or via Google Tag Manager.

<script>
window.sumatra.ready((sumatra) => {
sumatra.optimizer.subscribe((assignedVariants) => {
amplitude.track('Variants Seen', { assignedVariants });
})
})
</script>

The resulting payload will look something like:

{
"assignedVariants": [
"signups-hero-default",
"signups-body-light"
]
}

User Actions

To add context to an event that a user initiates synchronously, you can access the sumatra.optimizer.assignedVariants variable directly.

Button click example:

<button id="clickme" onclick="trackClick(this.id)">Click Me</button>

<script>
function trackClick(id) {
amplitude.track('Button Clicked', {
button: id,
assignedVariants: window.sumatra.optimizer.assignedVariants
});
}
</script>