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

Move Canonical Chartbeat to UserContext #3622

Merged
merged 47 commits into from
Sep 20, 2019
Merged

Move Canonical Chartbeat to UserContext #3622

merged 47 commits into from
Sep 20, 2019

Conversation

dr3
Copy link

@dr3 dr3 commented Sep 8, 2019

POC of #3621

Overall change: Creates a useChartbeat function

Whats it do?:

  • Stops chartbeat.js script from being mounted and unmounted all the time
  • Stops render issues for chartbeat

NB: the 'UserContext' probably isnt the right place to put this, but as a POC its fine :)

Whats happening?

If you visit http://localhost.bbc.com:7080/news/articles/c0g992jmmkko
First you see a console message

MOUNT CHARTBEAT - Royal wedding flowers given to Hackney hospice

This is rendering the script tag, and sending the first beacon
Then, if you navigate you see

CHARTBEAT CANONICAL pSUPERFLY virtualPage -  Royal wedding 2018: Bouquet laid on tomb of unknown warrior

This is the calling of window.pSUPERFLY.virtualPage with the new config


  • I have assigned myself to this PR and the corresponding issues
  • Automated (jest and/or cypress) tests added (for new features) or updated (for existing features)
  • This PR requires manual testing

@dr3 dr3 added ws-articles Tasks for the WS Articles Team simorgh-core-stream POC labels Sep 8, 2019
@dr3 dr3 self-assigned this Sep 8, 2019
@rhenshaw56 rhenshaw56 marked this pull request as ready for review September 12, 2019 09:08
@rhenshaw56 rhenshaw56 self-assigned this Sep 16, 2019
return <UserContext.Provider value={value}>{children}</UserContext.Provider>;
return (
<UserContext.Provider value={value}>
<Chartbeat config={chartbeatConfig} />
Copy link
Author

Choose a reason for hiding this comment

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

Can we test that Chartbeat is called with chartbeatConfig?

return <CanonicalChartbeatBeacon chartbeatConfig={config} />;
};

Chartbeat.propTypes = {
Copy link
Author

Choose a reason for hiding this comment

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

Can you pull these into simorgh/src/app/models/propTypes please, as we now use them in 2 files :)

@@ -2,6 +2,6 @@

exports[`Charbeats Analytics Container should call AmpCharbeatsBeacon when platform is amp and toggle enabled for chartbeat on live 1`] = `"amp-return-value"`;

exports[`Charbeats Analytics Container should call CanonicalCharbeatsBeacon when platform is canonical, and toggle enabled for chartbeat for local 1`] = `"canonical-return-value"`;
exports[`Charbeats Analytics Container should call sendCanonicalChartbeatBeacon when platform is canonical, and toggle enabled for chartbeat for local 1`] = `null`;
Copy link
Author

Choose a reason for hiding this comment

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

Is this snap out of date? not sure if we need it/need to fix it?

Copy link
Contributor

Choose a reason for hiding this comment

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

since we're not rendering the canonical here, I just figured we'd refactor the test to be that sendCanonicalChartbeatBeacon is called instead

Copy link
Author

@dr3 dr3 Sep 16, 2019

Choose a reason for hiding this comment

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

Might need to reword the test description then, as I dont get that from the current wording. Also it probably shouldnt be a snapshot test, maybe isNull?

...(cookie && { idSync: { bbc_hid: cookie } }),
};
useEffect(() => {
if (platform !== 'amp') {
Copy link
Author

@dr3 dr3 Sep 16, 2019

Choose a reason for hiding this comment

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

Suggested change
if (platform !== 'amp') {
if (isCanonicalAndEnabled) {

const { enabled } = useToggle('chartbeatAnalytics');
const { env, platform, pageType, previousPath, origin } = useContext(
RequestContext,
);
const isEnabledForAmp = platform === 'amp' && enabled;
Copy link
Author

Choose a reason for hiding this comment

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

Suggested change
const isEnabledForAmp = platform === 'amp' && enabled;
const isAmpAndEnabled = platform === 'amp' && enabled;

@staylos92
Copy link
Contributor

LGTM 👍

Performed regression testing of several assets (Front pages, Articles and Media pages) and all looked good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
POC ws-articles Tasks for the WS Articles Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants