Skip to content
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

Open
wants to merge 22 commits into
base: latest
Choose a base branch
from

Conversation

HarveyPeachey
Copy link
Contributor

@HarveyPeachey HarveyPeachey commented Oct 4, 2024

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

  • Refactors applyBasicPageHandlers to cater for the order of the Optmizely provider needing the WithContexts HOC to be be cakked ub the right order, so ckns_mvt is guaranteed to be set before being passed to the Optmizely client.
  • Moves logic from withOptimizelyProvider for setting the ckns_mvt cookie.
  • Updates readme with new way to apply the withOptimizelyProvider HOC

Testing

  1. Check the cookie is being set properly everywhere

Helpful Links

Add Links to useful resources related to this PR if applicable.

Coding Standards

Repository use guidelines

@HarveyPeachey HarveyPeachey self-assigned this Oct 4, 2024
@HarveyPeachey HarveyPeachey changed the title adjusts withOptimizelyProvider usage WSTEAM1-816: Set ckns_mvt cookie on all first time visits Oct 7, 2024
@HarveyPeachey HarveyPeachey marked this pull request as ready for review October 7, 2024 13:44
export const UserContextProvider = ({ children }: PropsWithChildren) => {
const [cookiePolicy, setCookiePolicy] = useState(getCookiePolicy());
const [chartbeatConfig, sendCanonicalChartbeatBeacon] = useState(null);

if (onClient() && !isOperaProxy()) {
Copy link
Contributor

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

Copy link
Contributor Author

@HarveyPeachey HarveyPeachey Oct 7, 2024

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
Copy link
Contributor

@karinathomasbbc karinathomasbbc Oct 7, 2024

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?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor

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?

Copy link
Contributor Author

@HarveyPeachey HarveyPeachey Oct 8, 2024

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

README.md Outdated Show resolved Hide resolved
expect(cookieGetterSpy).not.toHaveBeenCalled();
});

it('should not set cookie when ckns_mvt cookie exists', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should not set cookie when ckns_mvt cookie exists', () => {
it('should not set cookie when ckns_mvt cookie already exists', () => {

Copy link
Contributor

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' });
wonder if this might be helpful i.e. allow us to pretend that ckns_mvt is already set?

Copy link
Contributor Author

@HarveyPeachey HarveyPeachey Oct 8, 2024

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

HarveyPeachey and others added 6 commits October 8, 2024 08:30
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>
Copy link
Contributor

@karinathomasbbc karinathomasbbc left a 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants