Last active
July 23, 2024 15:28
-
-
Save robisatthefunction/c0f27730356a6540b271c189dce48fd5 to your computer and use it in GitHub Desktop.
This file contains 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
// Client-side JavaScript example | |
// Notification Listeners execute whenever a bucketing decision is made on a visitor for an A/B Test or Targeted Delivery. | |
// https://docs.developers.optimizely.com/feature-experimentation/docs/set-up-notification-listener-javascript | |
const onDecision = ({ type, userId, attributes, decisionInfo }) => { | |
// Check if a decision event was dispatched. This will only happen if the visitor is put into an A/B Test. | |
if (decisionInfo['decisionEventDispatched']) { | |
// Get experiment bucketing info | |
let experimentKey = "[Optimizely] " + decisionInfo['ruleKey'] | |
let variationKey = decisionInfo['variationKey'] | |
let decisionObject = {}; | |
decisionObject[experimentKey] = variationKey; | |
// https://docs.mixpanel.com/docs/data-structure/property-reference | |
// Set Mixpanel Super Property with experiment bucketing info. This will include experiment bucketing info with all future track calls. | |
mixpanel.register(decisionObject); | |
// (Optional) Set Mixpanel User Profile Property with experiment bucketing info. | |
mixpanel.people.set(decisionObject); | |
// (Optional) Set Mixpanel experiment_viewed event with experiment bucketing info. | |
mixpanel.track("experiment_viewed", decisionObject); | |
} | |
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