Skip to content

[WORLDSERVICE-643] Implement click tracking on Opera Mini for Canonical #12638

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

Draft
wants to merge 11 commits into
base: latest
Choose a base branch
from

Conversation

elvinasv
Copy link
Member

Resolves JIRA: https://jira.dev.bbc.co.uk/browse/WORLDSERVICE-643

Summary

A very high-level summary of easily-reproducible changes that can be understood by non-devs, and why these changes where made.

Code changes

  • A bullet point list of key code changes that have been made.

Developer Checklist

  • UX
    • UX Criteria met (visual UX & screenreader UX)
  • Accessibility
    • Accessibility Acceptance Criteria met
    • Accessibility swarm completed
    • Component Health updated
    • P1 accessibility bugs resolved
    • P2/P3 accessibility bugs planned (if not resolved)
  • Security
    • Security issues addressed
    • Threat Model updated
  • Documentation
    • Docs updated (runbook, READMEs)
  • Testing
    • Feature tested on relevant environments
  • Comms
    • Relevant parties notified of changes

Testing

  • Manual Testing required?
    • Local (Ready-For-Test, Local)
    • Test (Ready-For-Test, Test)
    • Preview (Ready-For-Test, Preview)
    • Live (Ready-For-Test, Live)
  • Manual Testing complete?
    • Local
    • Test
    • Preview
    • Live

Additional Testing Steps

  1. List the steps required to test this PR.

Useful Links

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's rename this to LiteTrackingTemplate for consistency with the ReverbTemplate

Comment on lines 65 to 69
__html: `${liteTrackingScripts({
onlyOperaMini,
trackViews,
trackClicks,
})}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can just move the original logic from src/server/Document/Renderers/LiteRenderer.tsx to here

Comment on lines 9 to 11
onlyOperaMini = false,
trackViews = true,
trackClicks = true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove this, we always want to track views + clicks

Suggested change
onlyOperaMini = false,
trackViews = true,
trackClicks = true,

Copy link
Member Author

Choose a reason for hiding this comment

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

After the changes, the will be used in both CanonicalRenderer and LiteRenderer.

If I understand your comment correctly, removing the conditional rendering (i.e., props here and inside liteTrackingScripts) would cause the scripts to load on all Canonical pages, which might not be what we want?

Comment on lines 188 to 189
// Note: Review if it's possible to assign LITE_ATI only on isLite and Opera Mini devices
return { [LITE_ATI_TRACKING]: liteHandler, onClick: clickTrackerHandler };
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good question. We don't want to double count the clicks.

One way to test this is to check a canonical page on Chrome - and ensure that only 1 event if fired. If 2 events are fired, then we will need to add the check for isLite || isOperaProxy() here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Initially my approach was to check for isLite || isOperaProxy() as you suggested. However isOperaProxy doesn't work on the server side due to window being undefined.

@shayneahchoon suggested that useATIClickTrackerHandler could return both - clickTrackerHandler and liteHandler. From my initial testing it shouldn't result in double counting the clicks for Canonical/Lite pages after the hydration due to stopPropagation inside useClickTrackerHandler

Meanwhile if server-rendered HTML version (i.e. Lite/Canonical Opera Mini) is used, event listeners are ignored and lite click tracking would be used.

Copy link
Contributor

@karinathomasbbc karinathomasbbc Apr 14, 2025

Choose a reason for hiding this comment

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

Ah yes, I had forgotten isOperaProxy won't work on the server!

Comment on lines 15 to 21

function sendBeaconLite (atiPageViewUrlString) {
var xhr = new XMLHttpRequest();
xhr.open("GET", atiPageViewUrlString, true);
xhr.withCredentials = true;
xhr.send();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove this

Copy link
Member Author

Choose a reason for hiding this comment

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

This also relates to the isOperaProxy not working on the server (As it could be loaded here https://github.com/bbc/simorgh/blob/latest/src/app/components/ATIAnalytics/canonical/index.tsx#L73 ). sendBeaconLite should be defined for Canonical on Opera Mini since it's used by processClientDeviceAndSendLite

Copy link
Contributor

@karinathomasbbc karinathomasbbc Apr 14, 2025

Choose a reason for hiding this comment

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

We should probably extract it into a separate script, and include it on canonical + lite pages. I want to try and reduce duplication as best we can. We have a file which already defines it: https://github.com/bbc/simorgh/blob/latest/src/app/components/ATIAnalytics/canonical/sendBeaconLite.ts - so we should ensure that's loaded first, and always available on the window.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point, we can just remove isLite check and always load the script for canonical + lite pages

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we need to refactor the sendBeaconLite file (+ test) & move it to within the new LiteRenderer template? (@shayneahchoon would you agree?)

@elvinasv elvinasv self-assigned this Apr 14, 2025
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.

2 participants