-
Notifications
You must be signed in to change notification settings - Fork 222
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
WSTEAM1-816: Set ckns_mvt cookie on all first time visits #12030
base: latest
Are you sure you want to change the base?
Conversation
export const UserContextProvider = ({ children }: PropsWithChildren) => { | ||
const [cookiePolicy, setCookiePolicy] = useState(getCookiePolicy()); | ||
const [chartbeatConfig, sendCanonicalChartbeatBeacon] = useState(null); | ||
|
||
if (onClient() && !isOperaProxy()) { |
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.
does this mean that we dont set the cookie for opera mini (based of this and the unit tests)? can you remind me why if so! assuming that we just dont run experiments on opera mini for a weird opera reason
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.
Actually debated wether to set this on opera mini or not. The reason is because Opera mini extreme mode renders its' pages for the user on their servers, so that means all users using Opera Mini Extreme mode would have the same userId, making testing redundant. Although technically we can set it here as this effectively disables running optimizely for opera mini users anyway, I'll ask product and @andrewscfc to see what they think
README.md
Outdated
@@ -97,6 +97,20 @@ The withHashChangeHandler HOC is a wrapper applied to all pages that checks for | |||
|
|||
The withOptimizelyProvider HOC returns components that have been enhanced with access to an Optimizely client, that is used to run our A/B testing. This is done to limit bundle sizes, as we seperate some of our bundles by page type, that means if we're only running A/B testing on certain page types, we can prevent polluting page type bundles with the weight of the SDK library we use for Optimizely. | |||
|
|||
This should be used by using the `handlerBeforeContexts` object key within [applyBasicPageHandlers.js](https://github.com/bbc/simorgh/tree/latest/src/app/pages/utils/applyBasicPageHandlers.js#L8), as the `ckns_mvt` is [set within the UserContext](https://github.com/bbc/simorgh/tree/latest/src/app/contexts/UserContext/index.tsx#L33), so the withOptimizelyProvider HOC needs to be applied in the correct order alongside [withContexts](https://github.com/bbc/simorgh/tree/latest/src/app/pages/utils/applyBasicPageHandlers.js#L13) HOC, so the `ckns_mvt` is availible to be used on first time visits to be used as the Optimizely User Id |
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.
Could we reword this slightly as it is a wee bit confusing?
This should be used by using the
handlerBeforeContexts
object key within [applyBasicPageHandlers.js]
What should be used? We could repeat whatever it is for clarity.
Could we also avoid used & using twice in the same sentence if possible?
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.
Yeah I can make it more succint
README.md
Outdated
@@ -97,6 +97,20 @@ The withHashChangeHandler HOC is a wrapper applied to all pages that checks for | |||
|
|||
The withOptimizelyProvider HOC returns components that have been enhanced with access to an Optimizely client, that is used to run our A/B testing. This is done to limit bundle sizes, as we seperate some of our bundles by page type, that means if we're only running A/B testing on certain page types, we can prevent polluting page type bundles with the weight of the SDK library we use for Optimizely. | |||
|
|||
This should be used by using the `handlerBeforeContexts` object key within [applyBasicPageHandlers.js](https://github.com/bbc/simorgh/tree/latest/src/app/pages/utils/applyBasicPageHandlers.js#L8), as the `ckns_mvt` is [set within the UserContext](https://github.com/bbc/simorgh/tree/latest/src/app/contexts/UserContext/index.tsx#L33), so the withOptimizelyProvider HOC needs to be applied in the correct order alongside [withContexts](https://github.com/bbc/simorgh/tree/latest/src/app/pages/utils/applyBasicPageHandlers.js#L13) HOC, so the `ckns_mvt` is availible to be used on first time visits to be used as the Optimizely User Id |
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.
This should be used by using the `handlerBeforeContexts` object key within [applyBasicPageHandlers.js](https://github.com/bbc/simorgh/tree/latest/src/app/pages/utils/applyBasicPageHandlers.js#L8), as the `ckns_mvt` is [set within the UserContext](https://github.com/bbc/simorgh/tree/latest/src/app/contexts/UserContext/index.tsx#L33), so the withOptimizelyProvider HOC needs to be applied in the correct order alongside [withContexts](https://github.com/bbc/simorgh/tree/latest/src/app/pages/utils/applyBasicPageHandlers.js#L13) HOC, so the `ckns_mvt` is availible to be used on first time visits to be used as the Optimizely User Id | |
This should be used by using the `handlerBeforeContexts` object key within [applyBasicPageHandlers.js](https://github.com/bbc/simorgh/tree/latest/src/app/pages/utils/applyBasicPageHandlers.js#L8), as the `ckns_mvt` is [set within the UserContext](https://github.com/bbc/simorgh/tree/latest/src/app/contexts/UserContext/index.tsx#L33), so the `withOptimizelyProvider` HOC needs to be applied in the correct order alongside [withContexts](https://github.com/bbc/simorgh/tree/latest/src/app/pages/utils/applyBasicPageHandlers.js#L13) HOC, so the `ckns_mvt` is available on first time visits and set as the Optimizely User Id |
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.
A more general question - should we use links to the latest version of the code, or a fixed commit ID? Especially once the functionality changes, and the latest code no longer reflects the docs?
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.
Yeah I deliberated on this, either way if the code changes both would become out of date, I thought the latest branch would be better as hopefully a reader can see it's changed based on the context of the readme, but if we link to a fixed commit ID, the code could be completely different from what is actually in the codebase. Happy to change this to a fixed commit ID as I'm not fussed
expect(cookieGetterSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not set cookie when ckns_mvt cookie exists', () => { |
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.
it('should not set cookie when ckns_mvt cookie exists', () => { | |
it('should not set cookie when ckns_mvt cookie already exists', () => { |
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 am not seeing any references to the ckns_mvt
in this test - do we need to have an explicit mock for this (rather than just foo?) e.g. we did a form of cookie mocking here:
setCookie({ name: 'test', value: '111' }); |
ckns_mvt
is already set?
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.
Yeah I took this approach as we're only really bothered if Cookie.set is called, but I agree it does make it more clear if ckns_mvt is set properly. I've updated the test to reflect this, clearing the setter mock before we render the user context so it doesn't mess with the expect
Co-authored-by: Karina Thomas <58214768+karinathomasbbc@users.noreply.github.com>
Co-authored-by: Karina Thomas <58214768+karinathomasbbc@users.noreply.github.com>
Co-authored-by: Karina Thomas <58214768+karinathomasbbc@users.noreply.github.com>
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 making the doc & code changes!
Resolves JIRA WSTEAM1-816
Overall changes
Moves the logic for setting the
ckns_mvt
cookie to the user context so it's set everywhere in our application.Code changes
Testing
Helpful Links
Add Links to useful resources related to this PR if applicable.
Coding Standards
Repository use guidelines