Appendix B - Sample Client Extensibility Javascript

//The following code is added to the client extensibility in the Bonfire component of the Allegiance platform. These examples correlate with the examples in the website code.

$(function() {

//Survey must have text box to keep track of Adobe Beacon value (ex: aaURL)

//Hide Adobe Beacon question

$('#aaURL_question').hide();

if($('#aaURL_question input').length > 0) sessionStorage.setItem('aaURL', $('#aaURL_question input').val());

function appendToStorage(name, data) {

var old = sessionStorage.getItem(name);

if (old === null) old = "";

sessionStorage.setItem(name, old + data);

}

//Adobe Integration parameters.

//Add the questions that we are tracking to send responses to Adobe

//Values should be [QuestionTag]_row or [QuestionTag]_question

var MCXAdobeParameters = {

questionIDs: ['NPS_row', 'lookandfeel_row']

}

var q1 = $('#' + MCXAdobeParameters.questionIDs);

$('.nextButton').on('click', function() {

for (var i = 0; i < MCXAdobeParameters.questionIDs.length; i++) {

var $q = $('#' + MCXAdobeParameters.questionIDs[i]);

if ($q.length > 0) {

appendToStorage('mcxAdobe', $('input[name=id]').val() + ':' + MCXAdobeParameters.questionIDs[i] + ':' + $q.find('input:checked').val());

if (i != MCXAdobeParameters.questionIDs.length) appendToStorage('mcxAdobe', ',');

}

}

//If there is a 'Thank You/Exit' page this value will need to updated to reflect the last page of the survey

//Example if the finish button is on page 2 and page 3 is a thank you page, this value will need to be '3' not '0'

if ($('input[name=nextpage]').val() == "0") {

//THE SUBMIT BUTTON HAS BEEN CLICKED AND WE ARE READY TO SUBMIT

console.log(sessionStorage.getItem('aaURL'));

sendDataToAdobeAnalytics(decodeURIComponent(sessionStorage.getItem('aaURL')));

console.log(sessionStorage.getItem('mcxAdobe'));

console.log('Survey complete, send to Adobe');

}

});

function sendDataToAdobeAnalytics(aaURL) {

if (!aaURL || aaURL.indexOf('http') != 0)

return;

var adobeCDVars = [];

var src = aaURL;

var responseIdVar = 'Maritz_rid'; // Do not change this value. Back end processing rules depend on this string in the URL.

var responseIdVal = $('input[name=id]').val(); // Fill in with actual Respondent ID

adobeCDVars[responseIdVar] = responseIdVal;

var answerListVar = 'Maritz_rlist'; // Do not change this value. Back end processing rules depend on this string in the URL.

var answerListVal = sessionStorage.getItem('mcxAdobe'); // Fill in with actual Response LIST

adobeCDVars[answerListVar] = answerListVal;

// strip off the AQE pair

var index = src.indexOf('&AQE=');

if (index > 0) {

src = src.substring(0, index);

}

// add the contextData variables

src += "&c.";

for (v in adobeCDVars) {

src += "&" + v + "=" + escape(adobeCDVars[v]);

}

src += "&.c";

src += '&AQE=1';

// add the img url to the page

var imgEl = document.createElement('img');

imgEl.src = src;

imgEl.setAttribute('style', 'display:none');

imgEl.setAttribute('height', '1');

imgEl.setAttribute('width', '1');

document.body.appendChild(imgEl);

}

});