Last active
July 29, 2024 21:37
-
-
Save robisatthefunction/28377ad89609192182f4cf1cdc0d5a14 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 = decisionInfo['ruleKey'] | |
let variationKey = decisionInfo['variationKey'] | |
let decisionObject = {}; | |
decisionObject[experimentKey] = variationKey; | |
// https://docs.mparticle.com/developers/sdk/web/event-tracking/ | |
window.mParticle.logEvent('Experiment Viewed', window.mParticle.EventType.Other, 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