Skip to content

Instantly share code, notes, and snippets.

@LMG23
Last active November 16, 2023 15:10
Show Gist options
  • Save LMG23/ddcccca63ca46bab64ecab8eabb3c966 to your computer and use it in GitHub Desktop.
Save LMG23/ddcccca63ca46bab64ecab8eabb3c966 to your computer and use it in GitHub Desktop.
usblCustomVars = {};
//Potentially define other custom variables here by adding them to the usblCustomVars object:
//usblCustomVars['Variable X'] = 'value A';
//usblCustomVars['Variable Y'] = 'value B';
//usblCustomVars['Variable Z'] = 'value C';
function updateUsblCustomVar() {
window.usabilla_live('data', {
'custom': usblCustomVars
});
}
function checkOptimizely() {
if (typeof optimizely !== 'undefined' && optimizely !== null) {
var campaign_data;
// Get Optimizely state
var state = optimizely.get('state');
// Return all active campaigns
campaign_data = state.getCampaignStates({ "isActive": true });
// Loop through Optimizely Campaigns
for (var campaign_id in campaign_data) {
if (campaign_data.hasOwnProperty(campaign_id)) {
// Get all data
var data = state.getDecisionObject({ "campaignId": campaign_id });
// Get variation
var variation = data.variation;
// Get experiment
var experiment = data.experiment;
// Append experiment and variation to GetFeedback custom object
usblCustomVars['Optimizely_Experiment_Name: ' + experiment] = variation;
}
}
}
updateUsblCustomVar();
}
function onCampaignDecided(event) {
checkOptimizely();
}
if (typeof optimizely !== 'undefined' && optimizely !== null) {
window["optimizely"] = window["optimizely"] || [];
window["optimizely"].push({
type: "addListener",
filter: {
type: "lifecycle",
name: "campaignDecided"
},
handler: onCampaignDecided
});
}
checkOptimizely();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment