Currently Spotler Activate Search does not provide any built-in tooling to validate specific use cases or different Spotler Activate Search setups. However, in some cases we can provide a second Spotler Activate Search instance for you with which you are able to setup external A/B measurements in Google Analytics (GA) using Google Tag Manager (GTM). Basically you will have two different Spotler Activate Search indexes that will be accessed on a 50/50 basis by the snippet.
Please ensure that the Built-in variable “Random number” is enabled.
You can find the option in GTM → Variables → Built-in Variables → Configure:
The following code can be used in GTM for such a test. Note that ‘var _wssq = _wssq || [];’ needs to be mentioned on top.
To measure conversion you must use the 2 indexes provided by Spotler Activate Search that use different. GA url parameters (eg sqrA & sqrB). These parameters can then be used in GA to compare the data.
//var _wssq should be on top:
var _wssq = _wssq || [];
function createCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function createABtest() {
var randomChange = randomNumber % variants.length;
createCookie(prefix + '-cookie', variants[randomChange], 9);
if (variants[randomChange] != "0") {
var newcookie = variants[randomChange].split('.');
var changeID = newcookie[0];
var variantID = newcookie[1];
changes[changeID]['variants'][variantID].execute();
sendDimension(changeID, variantID);
} else {
sendDimension(0)
}
}
function sendDimension(changeID, variantID) {
if (readCookie('_ga')) {
if (changeID != 0) {
dataLayer.push({ 'event':'abTest', 'eventCategory': 'ab-test', 'eventAction': prefix + '-' + changeID + '-' + variantID, 'eventLabel': prefix + '-' + changeID + '-' + variantID, 'eventNonInteraction': 1 });
} else {
dataLayer.push({ 'event':'abTest', 'eventCategory': 'ab-test', 'eventAction': prefix + '-0-0', 'eventLabel': prefix + '-0-0', 'eventNonInteraction': 1 });
}
}
}
function checkCookie(name) {
ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(name) > -1) return true;
}
return false;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}
var prefix = 'tnw';
var randomNumber = {{Random Number}};
var changes = {
2: {
variants: {
1: {
execute: function () {
//Snippet variation 1, no personalization
//var _wssq = _wssq || [];
var setResizeFunction= false;
var sooqrAccount = '123456-1';
_wssq.push(['_load', { 'suggest' : { 'account' : 'SQ-' + sooqrAccount, 'version' : 4, fieldId : 'search'}}]);
_wssq.push(['suggest._setPosition', 'screen-middle', {top:0}]);
_wssq.push(['suggest._setLocale', 'nl_NL']);
_wssq.push(['suggest._excludePlaceholders', 'Search..']);
_wssq.push(['suggest._bindEvent', 'open', function() {
if(!setResizeFunction) {$jQ( window ).resize(function() {if($jQ('.sooqrSearchContainer-' + sooqrAccount).is(':visible'))
{websight.sooqr.instances['SQ-' + sooqrAccount].positionContainer(null, null, true);}});setResizeFunction = true;}
}]);
(function() {
var ws = document.createElement('script'); ws.type = 'text/javascript'; ws.async = true;
ws.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'static.sooqr.com/sooqr.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ws, s);
})();
}
},
2: {
execute: function () {
//Snippet variation 2, with personalization
//var _wssq = _wssq || [];
var sz_uid = ('; '+document.cookie).split('; sqzllocal=').pop().split(';')[0]; //squeezely user id
var setResizeFunction= false;
var sooqrAccount = '123456-1';
_wssq.push(['_load', { 'suggest' : { 'account' : 'SQ-' + sooqrAccount, 'version' : 4, fieldId : 'search', personalization: { value: sz_uid, type: 'squeezely'}}}]);
_wssq.push(['suggest._setPosition', 'screen-middle', {top:0}]);
_wssq.push(['suggest._setLocale', 'nl_NL']);
_wssq.push(['suggest._excludePlaceholders', 'Search..']);
_wssq.push(['suggest._bindEvent', 'open', function() {
if(!setResizeFunction) {$jQ( window ).resize(function() {if($jQ('.sooqrSearchContainer-' + sooqrAccount).is(':visible'))
{websight.sooqr.instances['SQ-' + sooqrAccount].positionContainer(null, null, true);}});setResizeFunction = true;}
}]);
(function() {
var ws = document.createElement('script'); ws.type = 'text/javascript'; ws.async = true;
ws.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'static.sooqr.com/sooqr.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ws, s);
})();
}
}
}
}
};
var variants = [];
for (var j in changes) {
for (var x in changes[j]['variants']) {
variants.push(j + '.' + x);
}
}
if (readCookie(prefix + '-cookie')) {
if (variants.indexOf(readCookie(prefix + '-cookie')) != -1) {
var currentCookie = readCookie(prefix + '-cookie').split('.');
var currentChangeID = currentCookie[0];
var currentVariantID = 0;
if (currentChangeID != 0) {
currentVariantID = currentCookie[1];
changes[currentChangeID]['variants'][currentVariantID].execute();
}
sendDimension(currentChangeID, currentVariantID);
} else {
eraseCookie(prefix + '-cookie');
createABtest();
}
} else {
createABtest();
}
Please contact support in case you have any further questions.
Information inspired by: How we are A/B Testing with Google Tag Manager