Skip to main content

Split tests and 3rd party integrations

Sending data to tools like GA or FullStory for split tests

D
Written by Dan Bier

Split tests within our platform are designed to mask the original page, hook into our pageview event, and as soon as this is detected we change the url.

There are some additional considerations if using advanced consent which are addressed here.

While this allows our view counts to be accurate, it poses a challenge for 3rd party integration tools, for example GA or FullStory.

The standard integration setup with these kinds of tools is that after our pageview fires, we push an event to the GA datalayer, or the FullStory window variable. However GA and FullStory are not always able to capture this data before the url changes, and some data for split test variants is lost compared to our numbers.

In theory, the surest way to avoid the discrepancy would be to delay the split test redirect for a long enough period, e.g. an extra second, that 3rd party integrations have time to capture the events. This is undesirable because users will see a masked screen for longer before being redirected, and this delay would negatively impact the test results.

The recommended approach is to apply two scripts to the Global Tag Script in the Tag Configurations screen in the UI. The first saves the data to be captured into local storage while still on the url prior to redirect. The second reads from local storage on the new page, and pushes to GA and FullStory. The script can be amended to handle other 3rd party analytics data capture - in most cases it is one line to push to a datalayer or variable with a slightly different name.

// Capture data on pageview for post-redirect page capture
WT.addEventHandler("pageview", function(e){
var tf = false;
try {
tf = JSON.stringify(e.target.z7715.process.body.factors).match(/location\.href\s*=|location\.replace/);
if(tf){
var p = e.target.params;

var o = {
project_alias: p.testAlias,
test_id: p.r_runID,
experiment_id: p.r_experimentID,

};

localStorage.setItem("_wt.refire", JSON.stringify(o));
}
} catch(err) {}
});

// Read from local storage and push to GA and FullStory
try {
var o = localStorage.getItem("_wt.refire");
if (o) {
o = JSON.parse(o);

// GA
window.dataLayer = window.dataLayer || [];
dataLayer.push({
event: "optimize_view",
...o,
});

var oFS = {
...o,
};

oFS.testAlias = oFS.project_alias;
delete oFS.project_alias;

// FullStory
var intvl = setInterval(
function (oFS) {
if (!window.FS || !FS.event) return;
clearInterval(intvl);
FS.event("WTO Experiment", oFS, "WebtrendsOptimize");
},
1000,
oFS,
);

setTimeout(function () {
clearInterval(intvl);
}, 30000);

localStorage.removeItem("_wt.refire");
}
} catch (err) {}

It is worth noting that even using this local storage and refire approach, that data within the 3rd party tools for the variant may still be slightly lower than control, and lower compared to our platform reporting. This is because we capture views on the original page prior to redirect, and this approach relies on the user not bouncing during the redirect and load of the new page. Some drop off is expected.

Did this answer your question?