- 
                Notifications
    
You must be signed in to change notification settings  - Fork 141
 
refactor: Clean up the Optimizely integration #481
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
base: master
Are you sure you want to change the base?
refactor: Clean up the Optimizely integration #481
Conversation
* Don't attempt to interface with Optimizely Classic Web, since Classic is finally dead * Prepare to support Optimizely Edge, an alternative to Optimizely Web * Drop all references to customCampaignProperties. It seems to have been documented [here](https://segment.com/docs/connections/destinations/catalog/optimizely-web/#settings) but it couldn't possibly have worked. * Generally refactor the code and tests.
| 
           @patrickshih-optimizely you may want to rebase #479 on top of this. I'll leave it up to you! One of us will definitely have merge conflicts 😆  | 
    
| // Segment added code: in case this is a redirect experiment | ||
| if (referrer) campaignState.experiment.referrer = referrer; | ||
| sendCampaignData(campaignState); | ||
| var registerFutureActiveCampaigns = function() { | 
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.
we talked a little bit about potentially bringing these out as private functions? It would make this suite much easier to test IMO. What are your thoughts?
If not, it feels a little questionable to declare these as functions and not really re-use them. Maybe we can unfurl them and supplement with comments? WDYT?
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.
Fair points! Of the three remaining nested functions (see the latest commit) I think some are going to be easily reusable and some aren't.
Maybe we can extract the reusable ones?
What would we do with remaining ones - inline them? One could argue that single-use nested functions are helpful for documenting what each block of code does, but I think code comments might suffice too.
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.
Thanks for doing all the cleanup code. I had a comment we can discuss!
Also, I'll rebase on top of yours... it'll makes my integration smoother
| 
               | 
          ||
| describe('after loading', function() { | ||
| beforeEach(function(done) { | ||
| analytics.once('ready', done); | 
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.
I don't know what analytics.once('ready', callback); does or whether it's relevant here. I removed it because it seemed to cause the test suite to hang and skip the tests in this describe; though maybe I'm wrong, maybe I was just misreading the test output.
| beforeEach(function() { | ||
| analytics.initialize(); | ||
| mockBothOptimizelyDataObjects(); | ||
| analytics.page(); | 
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.
I'm not sure if this was doing anything. There may be some value in testing an analytics.page call without the optional name argument, but I suspect this is not the correct place for that.
| 
               | 
          ||
| * Don't attempt to interface with Optimizely Classic Web, since Classic is finally dead | ||
| * Prepare to support Optimizely Edge, an alternative to Optimizely Web | ||
| * Drop all references to customCampaignProperties. It seems to have been documented [here](https://segment.com/docs/connections/destinations/catalog/optimizely-web/#settings) but it couldn't possibly have worked. | 
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.
Beyond this update to the integration code, Custom Campaign Properties and Custom Experiment Properties should also be removed from the docs and from the Segment app. (I didn't highlight Custom Experiment Properties in HISTORY.md since it was specific to the Optimizely Classic Web product, whose code is being removed entirely.)
Full explanation of why this functionality is surely broken:
- The docs indicate that Custom Experiment Properties and Custom Campaign Properties could be used to capture experiment- and campaign-specific properties like 
experiment_colorandcampaign_namein Classic Web and X Web respectively. This makes sense, kinda. - Unfortunately, the integration code indicates that for Classic Web, the Custom Experiment Properties are being read off of the top-level 
window.optimizely.dataobject, rather than off of an experiment object - And for X Web, the Custom Campaign Properties are being read off of a non-existent 
window.optimizely.newMockDataproperty. This property is mocked in index.test.js but does not appear in actual X Web snippets. 
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.
Thanks for the heads-up! I'll work on getting the documentation updated.
| 
           @nchilada Thanks for this! I'm going to work on releasing this shortly.  | 
    
| 
           @nchilada It looks like this PR introduces some new lint warnings in our CI. Do you think you could fix these up? (Sorry that this isn't clear -- I'm not sure why our CircleCI setup isn't able to run successfully with external branches, yet.)  | 
    
| 
           @tysonmote @gpsamson thank you for the reviews and sorry for the late update! I've pushed some lint fixes; hopefully they help. I'm heading out of office through next week but @patrickshih-optimizely and I can check in to make sure you don't need anything to more for this PR. BTW would you all be in charge of any necessary integration testing? I saw a link to this README but I don't have a lot of context (I've never directly used Segment myself).  | 
    
| 
           @patrickshih-optimizely and @nchilada — Thank you for your patience! We are planning to merge this PR and #483 on May 3, 2021. Let us know if anything has changed in the past (many) months.  | 
    
| 
           Hi @jenskene ! Thanks for getting back to us! @nchilada had since moved on from Optimizely, feel free to direct any questions about this PR to me. I scanned this PR once again and this one looks good. Mainly, because most of the changes in this PR is removing old functionality that Optimizely does not support anymore (specifically, our Classic product and things w.r.t Classic)  | 
    
| 
           @patrickshih-optimizely thanks very much for taking over! @jenskene yup I left Optimizely last year and stopped getting notifications. Sorry for not posting an update in either PR!  | 
    
What does this PR do?
Product changes
Bug fixes
registerFutureActiveCampaignscollects null campaign decisions in addition to active campaign decisions; until this PR, such campaigns were being passed tonewActiveCampaignwhere they were throwing (asynchronous and thus inconsequential) errors.Other refactoring
referrerOverride,sendExperimentData, andsendCampaignDatahooks on the left-hand side of the diff. It looks like that pattern was copy-and-pasted from here or here; in any case, it's confusing and unnecessary.setRedirectInfoas a stateful method.initWebIntegration as an isolated unit instead of invoking it as part ofanalytics.initialize. Ideally we'd do the same forsendWebDecisionToSegment`, but I ran out of energy.lodash,sinon, andchaiasdevDependenciesand use them throughout the tests. The preexisting tests used things likeanalytics.stub,analytics.called, andanalytics.deepEqualbut those are undocumented and seem to be less full-featured. As someone who doesn't have access to internal Segment documentation, those functions are very difficult to work with.Are there breaking changes in this PR?
Any background context you want to provide?
Is there parity with the server-side/android/iOS integration components (if applicable)?
N/A
Does this require a new integration setting? If so, please explain how the new setting works
No. On the contrary, the "Custom Experiment Properties" setting described here is obsolete now that Optimizely Classic is gone (and was also incorrectly documented or implemented), and the "Custom Campaign Properties" setting can also be un-documented because it too was incorrectly implemented and is now being removed.
Links to helpful docs and other external resources
I've linked to some API docs from JSDoc comments!