Last active
July 16, 2025 22:17
-
-
Save robisatthefunction/36001d59ba3116570a6cb2a55baf62b5 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
| // Constant for consistent event naming | |
| const OPTIMIZELY_EVENT_NAME = 'Optimizely_Experiment'; | |
| // Helper function to safely retrieve the FullStory API | |
| // You may want to add code to wait for it to be available | |
| function _fs() { | |
| const fsNamespace = window['_fs_namespace']; | |
| const fsApi = fsNamespace && window[fsNamespace]; | |
| return typeof fsApi === 'function' ? fsApi : () => {}; | |
| } | |
| // Optimizely decision listener callback | |
| const onDecision = ({ type, userId, attributes, decisionInfo }) => { | |
| // Defensive: ensure decisionInfo exists and the event was dispatched | |
| if (decisionInfo && decisionInfo.decisionEventDispatched) { | |
| const experimentKey = decisionInfo.ruleKey; | |
| const variationKey = decisionInfo.variationKey; | |
| const decisionObject = { | |
| experiment: experimentKey, | |
| variation: variationKey, | |
| }; | |
| // Track the decision in FullStory | |
| _fs()('trackEvent', { | |
| name: OPTIMIZELY_EVENT_NAME, | |
| properties: decisionObject, | |
| }); | |
| // Optional: remove listener if only needed once | |
| // optimizelyClient.notificationCenter.removeNotificationListener(notificationId); | |
| } | |
| }; | |
| // Register the 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