Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save robisatthefunction/4fee6ed6638488d90dc7a071032014fc to your computer and use it in GitHub Desktop.

Select an option

Save robisatthefunction/4fee6ed6638488d90dc7a071032014fc to your computer and use it in GitHub Desktop.
const onDecision = ({ type, userId, attributes, decisionInfo }) => {
// Check if a decision event was dispatched
if (decisionInfo && decisionInfo.decisionEventDispatched) {
// Get experiment bucketing info
const experimentKey = decisionInfo.ruleKey;
const variationKey = decisionInfo.variationKey;
// Format decision string as "(experiment):(variation)"
const decisionString = `(${experimentKey}):(${variationKey})`;
// Send decision info through Adobe Analytics eVar2
// You may want to add code that waits for the s variable to be available
if (window.s) {
window.s.eVar2 = decisionString;
window.s.tl(true, 'o', 'OptimizelyDecision');
}
}
};
// Register the decision listener with Optimizely
const notificationId = optimizelyClient.notificationCenter.addNotificationListener(
enums.NOTIFICATION_TYPES.DECISION,
onDecision
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment