Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robisatthefunction/10cfb7cb6efa6e124400019a92717313 to your computer and use it in GitHub Desktop.
Save robisatthefunction/10cfb7cb6efa6e124400019a92717313 to your computer and use it in GitHub Desktop.
import { enums } from '@optimizely/optimizely-sdk';
// import your third-party analytics integration here
///////////////////////////////////////////
// SET UP DECISION NOTIFICATION LISTENER //
///////////////////////////////////////////
const onDecision = ({decisionType, userId, attributes, decisionInfo}) => {
if(decisionInfo['decisionEventDispatched']){
// This assumes the userContext is instantiated
// Ensure Contentsquare is available
if (typeof window._uxa !== 'undefined') {
// Send the experiment data to Contentsquare
// This uses Contentsquare's custom variable tracking
const experimentKey = decisionInfo.ruleKey;
const variationKey = decisionInfo.variationKey
const tagValue = `${experimentKey}:${variationKey}`;
window._uxa.push(['setCustomVariable', 1, 'OptimizelyExperiment', tagValue]);
}
}
}
const notificationId = optimizelyClient.notificationCenter.addNotificationListener(optimizelySdk.enums.NOTIFICATION_TYPES.DECISION, onDecision);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment