Last active
March 31, 2025 18:22
-
-
Save robisatthefunction/10cfb7cb6efa6e124400019a92717313 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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