-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add optimizely attribute fetching functionality #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fb6ef99
Add Optimizely attribute-fetching function to Kit,
patrick-wu 4d7c571
Don't reuse declarations
patrick-wu 4210206
Tests
patrick-wu c05d951
Lint
patrick-wu 8e29fa5
Fix
patrick-wu 4b605da
Refactor
patrick-wu dd518f9
Remove dist
patrick-wu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ var constructor = function () { | |
| self.name = name; | ||
| self.moduleId = moduleId; | ||
| self.isInitialized = false; | ||
|
|
||
| self.launcher = null; | ||
| self.filters = {}; | ||
| self.filteredUser = {}; | ||
|
|
@@ -39,6 +40,7 @@ var constructor = function () { | |
| var accountId = settings.accountId; | ||
| var sandboxMode = window.mParticle.getEnvironment() === 'development'; | ||
| self.userAttributes = filteredUserAttributes; | ||
| self.onboardingExpProvider = settings.onboardingExpProvider; | ||
|
|
||
| if (testMode) { | ||
| attachLauncher(accountId, sandboxMode); | ||
|
|
@@ -116,9 +118,18 @@ var constructor = function () { | |
|
|
||
| self.userAttributes = filteredAttributes; | ||
|
|
||
| var selectPlacementsAttributes = mergeObjects(filteredAttributes, { | ||
| mpid: mpid, | ||
| }); | ||
| var optimizelyAttributes = | ||
| self.onboardingExpProvider === 'Optimizely' | ||
| ? fetchOptimizely() | ||
| : {}; | ||
|
|
||
| var selectPlacementsAttributes = mergeObjects( | ||
| filteredAttributes, | ||
| optimizelyAttributes, | ||
| { | ||
| mpid: mpid, | ||
| } | ||
| ); | ||
|
|
||
| var selectPlacementsOptions = mergeObjects(options, { | ||
| attributes: selectPlacementsAttributes, | ||
|
|
@@ -187,6 +198,46 @@ var constructor = function () { | |
| this.selectPlacements = selectPlacements; | ||
|
|
||
| // mParticle Kit Callback Methods | ||
| function fetchOptimizely() { | ||
| var forwarders = window.mParticle | ||
| ._getActiveForwarders() | ||
| .filter(function (forwarder) { | ||
| return forwarder.name === 'Optimizely'; | ||
| }); | ||
|
|
||
| try { | ||
| if (forwarders.length > 0 && window.optimizely) { | ||
| // Get the state object | ||
| var optimizelyState = window.optimizely.get('state'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should add some handlers in case |
||
| if ( | ||
| !optimizelyState || | ||
| !optimizelyState.getActiveExperimentIds | ||
| ) { | ||
| return {}; | ||
| } | ||
| // Get active experiment IDs | ||
| var activeExperimentIds = | ||
| optimizelyState.getActiveExperimentIds(); | ||
| // Get variations for each active experiment | ||
| var activeExperiments = activeExperimentIds.reduce(function ( | ||
| acc, | ||
| expId | ||
| ) { | ||
| acc[ | ||
| 'rokt.custom.optimizely.experiment.' + | ||
| expId + | ||
| '.variationId' | ||
| ] = optimizelyState.getVariationMap()[expId].id; | ||
| return acc; | ||
| }, | ||
| {}); | ||
| return activeExperiments; | ||
| } | ||
| } catch (error) { | ||
| console.error('Error fetching Optimizely attributes:', error); | ||
| } | ||
| return {}; | ||
| } | ||
| this.init = initForwarder; | ||
| this.setUserAttribute = setUserAttribute; | ||
| this.onUserIdentified = onUserIdentified; | ||
|
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have a testing framework, I would like to see some tests around this logic. I can help you with mocking if you need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexs-mparticle can you take a look if these test cases are sufficient?