Skip to content

WS-2925 - Migrate inline js code for Piano tracking on Opera Mini - #14258

Open
alex-magana wants to merge 24 commits into
latestfrom
TRIAGE-2-migrate-inline-js-code-for-opera-mini
Open

WS-2925 - Migrate inline js code for Piano tracking on Opera Mini#14258
alex-magana wants to merge 24 commits into
latestfrom
TRIAGE-2-migrate-inline-js-code-for-opera-mini

Conversation

@alex-magana

@alex-magana alex-magana commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Resolves JIRA: WS-2925

Summary

Update Opera Mini & Lite site Piano inline JS tracking code to meet coding standards.

Code changes

  • Convert src/app/components/ATIAnalytics/canonical/sendPageViewBeaconOperaMini/index.ts o ES5 to
    enable tracking in Opera Mini 4.5.33867.
  • Convert src/app/lib/analyticsUtils/staticATITracking/sendStaticBeacon/index.ts to ES5 to
    enable dispatch of Piano requests in Opera Mini 4.5.33867.

Testing

  1. Setup the Opera Mini emulator. This can be done via the guide here.
  2. Launch the Opera Mini emulator
  3. Visit an asset on the emulator. See list below for sample assets.
  4. Check Piano to assert that the data from the tracking beacons is persisted and accessible in Piano.

See WS-2925 for links to the Piano reports for monitoring/testing.

Sample Assets

LITE
https://simorgh2.belfrage-preview.test.api.bbc.com?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/afrique.lite?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/gahuza.lite?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/afrique/monde-63615109.lite?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/gahuza/articles/cz91q9n4y11o.lite?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/mundo/articles/ckg4ev45q4xo.lite?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/russian/articles/c9826xrd0d1o.lite?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/russian/topics/c44vyp57qy4t.lite?renderer_env=live


AMP
https://simorgh2.belfrage-preview.test.api.bbc.com?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/afrique.amp?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/gahuza.amp?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/afrique/monde-63615109.amp?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/gahuza/articles/cz91q9n4y11o.amp?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/mundo/articles/ckg4ev45q4xo.amp?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/russian/articles/c9826xrd0d1o.amp?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/russian/topics/c44vyp57qy4t.amp?renderer_env=live

CANONICAL
https://simorgh2.belfrage-preview.test.api.bbc.com/afrique?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/gahuza?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/afrique/monde-63615109?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/gahuza/articles/cz91q9n4y11o?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/mundo/articles/ckg4ev45q4xo?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/russian/articles/c9826xrd0d1o?renderer_env=live
https://simorgh2.belfrage-preview.test.api.bbc.com/russian/topics/c44vyp57qy4t?renderer_env=live

Expected Behaviour Matrix

Browser Platform Page Tracking Event Tracking
Chrome Responsive (Canonical)
Lite
AMP
Firefox Responsive (Canonical)
Lite
AMP
Opera Mini 4.5.33867 Responsive (Canonical)
Lite
AMP

Findings

To test tracking on Preview 2, we appended text to the app name property here and here. We then used
appropriate filters in Piano to ascertain that tracking data surfaces in Piano.

Opera Mini 4.5.33867 does not support arrow functions. Tracking on Lite and AMP platforms fails due to
the use of arrow functions in processClientDeviceAndSendStaticBeacon.

We attempted to use the configuration set out in the block below in ws-nextjs-app/next.config.js
to transpile the ES6 code to ES5. However, this failed with errors. We therefore had to rewrite
the functions manually.

    config.module.rules.push({
      // Alternatively, target an entire folder: include: [path.resolve(__dirname, 'src/legacy-scripts')]
      include: [
        path.resolve(
          __dirname,
          '..',
          'src/app/lib/analyticsUtils/staticATITracking/processClientDeviceAndSendStaticBeacon/index.ts',
        ),
        path.resolve(
          __dirname,
          '..',
          'src/app/lib/analyticsUtils/staticATITracking/sendStaticBeacon/index.ts',
        ),
      ],
      use: [
        {
          loader: 'babel-loader',
          options: {
            presets: [
              [
                '@babel/preset-env',
                {
                  targets: {
                    ie: '11', // Targets ES5-compatible browsers
                  },
                },
              ],
            ],
          },
        },
      ],
    });

Useful Links

@alex-magana alex-magana changed the title Triage 2 migrate inline js code for opera mini WS-2925 - Migrate inline js code for Piano tracking on Opera Mini Jul 23, 2026
@alex-magana
alex-magana marked this pull request as ready for review July 28, 2026 13:35
Copilot AI review requested due to automatic review settings July 28, 2026 13:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates Opera Mini Piano/ATI tracking inline JS from string/eval-style snippets to callable functions, allowing safer composition of inline scripts and reducing reliance on runtime string evaluation.

Changes:

  • Converted sendStaticBeacon and Opera Mini page-view beacon logic from string-returning helpers to real functions invoked via addInlineScript.
  • Extended addInlineScript to support passing functions as script parameters (to inline via .toString()), and added/updated unit tests accordingly.
  • Updated global typing for window.sendStaticBeacon to reflect the new void return.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/global.d.ts Updates window.sendStaticBeacon typing to void return.
src/app/lib/utilities/addInlineScript/index.tsx Extends inline-script parameter handling to support function parameters.
src/app/lib/utilities/addInlineScript/index.test.tsx Adds coverage for function parameters in inline scripts.
src/app/lib/analyticsUtils/staticATITracking/sendStaticBeacon/index.ts Replaces string-based inline code with functions that attach/call window.sendStaticBeacon.
src/app/lib/analyticsUtils/staticATITracking/sendStaticBeacon/index.test.ts Updates tests to call functions directly instead of eval.
src/app/components/ATIAnalytics/canonical/sendPageViewBeaconOperaMini/index.ts Refactors Opera Mini page-view beacon to a callable function with injected isOperaProxy dependency.
src/app/components/ATIAnalytics/canonical/sendPageViewBeaconOperaMini/index.client.test.ts Updates client test to avoid eval and verify new callable behavior.
src/app/components/ATIAnalytics/canonical/index.tsx Switches Helmet-injected scripts to use function references + parameters.
src/app/components/ATIAnalytics/canonical/index.test.tsx Updates expectations for new inline script output and adds Opera Mini script presence test.

Comment on lines 1 to 5
export type InlineScriptProps = {
script: string | { toString: () => string };
parameters?: string | string[];
parameters?: string | string[] | (string | { toString: () => string })[];
nonce?: string | null;
};
Comment on lines 13 to 16
beforeEach(() => {
XMLHttpRequestSpy = jest.spyOn(window, 'XMLHttpRequest');
eval(addSendStaticBeaconToWindow());
addSendStaticBeaconToWindow();
});
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