When the Mutiny client attaches to your webpage, it exposes variables that can be used to send custom analytics events to your backend data sources. Before diving into this article, its worth noting that much of the information that is exposed in this custom object is also made available by our Google Tag Manager integration, which may be easier to work with.
Window object
The window.mutiny
object contains information about the segments and experiences running on the page, as well as the current visitor.
The experiences attribute contains an array of all active experiences the visitor is currently seeing and relevant context such as:
- audienceSegment - the Segment you define in Mutiny associated with the experience
- impressionType - either "personalized" or "control"
- page - the current page URL
- variationName - the name of the variant if you are running a multi-variant experience
The visitor attribute contains information that Mutiny uses to segment the user, including their unique token which persists between sessions.
Here is an example object returned by window.mutiny
.
Event listeners
Mutiny also exposes this same experience data on a mutiny:experience-impressions event listener on the window variable, which gets triggered every time an experience is rendered for the visitor.
To send this information into your own database or other platforms, you will need to write custom Javascript to read these variables and send them to the appropriate destination.
For the most accurate tracking, we recommend calling both the window.mutiny object, as well as attaching an event listener in your code. This will ensure data is being passed for any window changes, as well as single page applications. Here is an example of JavaScript to have your developer implement:
if (window.mutiny.experiences) {
window.mutiny.experiences.forEach(function(experience) {
// replace this with reporting code
console.log(experience.variationName);
});
}
window.addEventListener('mutiny:experience-impression', function(event) {
// replace this with your reporting code
console.log(event.detail.variationName);
});
Be sure to replace console.log
with the appropriate code to pass this data back to your reporting platform. Additionally, be sure to replace variationName
with whatever attribute(s) are relevant to you.
Comments
0 comments
Please sign in to leave a comment.