Reading Triggered Experiment Data for Using it in Third Party Systems
Read & Sync Convert Experiment Data to External Platforms
| Author: | George F. Crewe |
THIS ARTICLE WILL HELP YOU:
- Give an Overview of convert.currentData and convert.historicalData
- Understand Latest Object Structures
- Access Data Safely with _conv_q
- Know Difference with Legacy Structure
Overview
This guide explains how to access live and historical Convert experiment data (convert.currentData and convert.historicalData) from the web script for integration with third-party analytics and tracking systems. For more on the window.convert object, see The window.convert Object in the developer docs.
The latest Convert web script significantly restructured the experiment objects for greater detail and clarity, moving away from simple variation ID/name pairings to a comprehensive nested variation object.
1. Latest Object Structures
Convert provides two main global JavaScript objects for accessing experiment data: convert.currentData and convert.historicalData.
convert.currentData
This object holds the data for all experiments and goals that were triggered on the current page load.
|
Key |
Description |
|
experiences |
(New) This object contains all experiments currently running on the page. Keys are Experience IDs. |
|
goals |
A map of goals triggered on the current page. Keys are Goal IDs and values are always 1. |
|
experiencesGoals |
(New) Contains goal data structured relative to experiences, mirroring the data in goals. |
Details of the experiences Object
Each experience object (e.g., experiences["100127238"]) contains the following structure:
|
Key |
Description |
|
firstTime |
A Boolean indicating if the experiment is being triggered for the first time for this visitor on this page. (Previously first_time). |
|
variation |
(New) A nested object containing all variation details. |
Details of the nested variation Object
|
Key |
Description |
|
id |
The ID of the variation presented to the visitor. |
|
name |
The name of the variation. |
|
key |
A unique key combining the variation ID and name/type. |
|
status |
The current status of the variation (e.g., "running"). |
|
traffic_allocation |
The percentage of traffic allocated to this variation. |
|
changes |
An array of change objects, providing detail on the visual/code changes applied. |
Example of convert.currentData (Latest)
{
"experiences": {
"100127238": {
"firstTime": false,
"variation": {
"changes": [
{
"name": "Original"
}
],
"id": "1001186426",
"name": "Original",
"key": "1001186426-original",
"status": "running",
"traffic_allocation": 50
}
}
/* ... other experiences ... */
},
"experiencesGoals": {},
"goals": {}
}
convert.historicalData
This object contains experiment data gathered across all past visitor sessions, showing all experiments that have ever been triggered for the visitor.
|
Key |
Description |
|
experiences |
(New) This object contains all experiments previously triggered for the visitor. Keys are Experience IDs. |
Details of the experiences Object
Each experience object (e.g., experiences["100127238"]) contains:
|
Key |
Description |
|
variationId / variation_id |
The ID of the variation the visitor was bucketed into for this experiment. |
|
variationName / variation_name |
The name of the variation. |
|
goals |
An object holding goals triggered for the current experiment. Keys are Goal IDs and values are the count of conversions. |
Example of convert.historicalData (Latest)
{
"experiences": {
"100127238": {
"variation_name": "Original",
"variationName": "Original",
"variation_id": 1001186426,
"variationId": 1001186426,
"goals": {
"100132206": 1,
"100132207": 1
}
}
/* ... other experiences ... */
}
}
2. Accessing Data Safely using _conv_q
Since parts of the Convert tracking script run asynchronously, wait until the experience data is ready before you read it. Use the Convert queue variable, _conv_q, to add a listener for the snippet.goals_evaluated event. It runs after Convert has evaluated the experiences and goals on the page.
Add the code to Project > Configuration > Global Project Javascript, so that the listener is in place before the event. A listener added after the event doesn't run. The example reads the experience and variation names, or their IDs when data anonymization is on in your project. Replace the console.log line with the code that sends the data to your third-party system.
window._conv_q = window._conv_q || [];
window._conv_q.push({
what: 'addListener',
params: {
event: 'snippet.goals_evaluated',
handler: function () {
var rows = getConvertData();
rows.forEach(function (row) {
// ... send the data to your third-party system, for example:
console.log('Experience ' + row.experienceName + ' (' + row.experienceId + '), variation ' + row.variationName + ' (' + row.variationId + ')');
});
}
}
});
// Returns the experiences the visitor is in on this page, with their variation.
// With data anonymization on, it uses IDs instead of names.
function getConvertData() {
var rows = [];
var current = convert.currentData.experiences || {};
var configured = convert.data.experiences || [];
var settings = convert.data.project && convert.data.project.settings;
var anonymize = !!(settings && settings.data_anonymization);
for (var experienceId in current) {
if (!current.hasOwnProperty(experienceId)) continue;
var variation = current[experienceId].variation || {};
var experience = configured.filter(function (e) {
return String(e.id) === String(experienceId);
})[0];
rows.push({
experienceId: experienceId,
variationId: String(variation.id),
experienceName: anonymize ? experienceId : (experience ? experience.name : experienceId),
variationName: anonymize ? String(variation.id) : variation.name
});
}
return rows;
}
3. Note on Legacy Object Structure
The legacy (older) Convert web script objects primarily used the top-level keys experiments instead of the new experiences.
The main difference was in the structure of convert.currentData.experiments:
- Legacy structure: Variation data was flattened, residing directly within the experiment object, including variationId, variationName, and first_time.
- Crucially, for detail, it included a separate object called variation_name_parts, which housed the changes array and sections array (primarily used for Multivariate Tests) instead of nesting everything under a comprehensive variation object.
- Example Legacy Access: convert.currentData.experiments[expId].variationId and convert.currentData.experiments[expId].variation_name_parts.changes.
The new script simplifies data access by organizing all variation-related attributes under a single, dedicated variation object.