opt_data
This requires integration opt_data
Let’s say you want to track some information in Optimize, but you’re unable to get to/share details about the page it’s on.
window.opt_data
provides a simple interface for sending additional data into Optimize, and can take place as part of your tag implementation if needed.
Wherever convenient, you can run this code. The tag will pick it up, and store those details as part of your conversion package. It can be inside SCRIPT
tags, inside your tag manager, etc.
Sending an event only
window.opt_data = window.opt_data || [];
window.opt_data.push({
"event": "purchase"
});
Sending data only
If you would like to send along any data for our datalayer – user attributes (e.g. is logged in) or page-level attributes (price, category, etc.), you can use the same opt_data.push method to send it to us. Just make sure you don’t send along an event name, so we don’t capture the data in a metric.
window.opt_data = window.opt_data || [];
window.opt_data.push({
"data": {
"is_logged_in": true,
"price": 99.99
// provide any other attributes you'd like to here.
}
});
Sending an event with additional data
window.opt_data = window.opt_data || [];
window.opt_data.push({
"event": "purchase",
"data": {
"revenue": 123.45, // Replace this value with your dynamically-inserted revenue.
"upt": 3 // Replace this value with your dynamically-inserted units purchased value.
// provide any other attributes you'd like to here.
}
});
All attributes are optional, and you’re welcome to provide anything you’d like to track for all tests you run
.
Passing in data before the tag has run:
The above code will see that window.opt_data
is not on the page, and will create the variable. It will then use .push
to insert your event details into the Array. Optimize will then pick this data up and pass it in as a conversion. This will happen for all tests that user is cooked for.
Once Optimize executes, you’ll then see this data in window.opt_data.h
Passing in data after the tag has run:
The above code will hit a pre-defined function, which will automatically send conversion data into Optimize for each test the user has fallen into. Your data will then be stored in window.opt_data.h
Knowing if opt_data is present
While there should be no need for you to know this, you can look for window.opt_data.h
. If present, that means Optimize has run.