Skip to content

WS-2284 - Fix lost view events in Optimizely#13858

Merged
louisearchibald merged 43 commits intolatestfrom
WS-2284-fix-lost-view-events-in-optimizely
Apr 21, 2026
Merged

WS-2284 - Fix lost view events in Optimizely#13858
louisearchibald merged 43 commits intolatestfrom
WS-2284-fix-lost-view-events-in-optimizely

Conversation

@louisearchibald
Copy link
Copy Markdown
Contributor

@louisearchibald louisearchibald commented Mar 31, 2026

Resolves JIRA: WS-2284

Summary

Attempts to solve a known bug with page-views firing incorrectly before experiments activate.

Code changes

  • Adds an external store for activated Optimizely experiment flags and uses useSyncExternalStore so React components will re-render when new flags are activated.
  • Provides a subscription model for React components, using a useActivatedExperiments hook.
  • Uses new Set instances when updating snapshots so React reliably detects state changes.
  • Add resetDecisionStore to clear state and reset snapshots.
  • Registers a global DECISION notification listener to react to experiment activations.
  • Calls notifyDecision(flagKey) to record activated experiments and notify subscribers.

Testing

  1. We will test with an AA experiment set.up in Optimizely to verify that page-views are being recorded accurately.

@louisearchibald louisearchibald self-assigned this Mar 31, 2026
Comment thread src/app/components/OptimizelyPageMetrics/index.tsx Outdated
@louisearchibald louisearchibald marked this pull request as ready for review April 8, 2026 08:02
@louisearchibald louisearchibald requested a review from a team as a code owner April 8, 2026 08:02
Copilot AI review requested due to automatic review settings April 8, 2026 08:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 addresses lost Optimizely page-view events by ensuring tracking in OptimizelyPageMetrics only renders after the user is confirmed to be bucketed into a relevant experiment, including handling late experiment assignment via an Optimizely decision notification listener.

Changes:

  • Adds @optimizely/optimizely-sdk to access Optimizely enums for notification types.
  • Adds an initial decideAll-based membership check before rendering tracking components.
  • Attaches and cleans up a decision notification listener to detect post-load bucketing into relevant experiments.

Reviewed changes

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

File Description
src/app/components/OptimizelyPageMetrics/index.tsx Adds initial bucketing check and a decision notification listener to gate tracking rendering until experiment membership is confirmed.
package.json Adds a direct dependency on @optimizely/optimizely-sdk for notification enums.
yarn.lock Updates lockfile to reflect the added Optimizely SDK dependency/version resolution.

Comment thread src/app/components/OptimizelyPageMetrics/index.tsx Outdated
Comment thread src/app/components/OptimizelyPageMetrics/index.tsx Outdated
Comment thread src/app/components/OptimizelyPageMetrics/index.test.tsx Outdated
Comment thread src/app/components/OptimizelyPageMetrics/index.test.tsx Outdated
Comment thread src/app/components/OptimizelyPageMetrics/index.tsx Outdated
Comment thread src/app/components/OptimizelyPageMetrics/index.tsx Outdated
Comment thread src/app/components/OptimizelyPageMetrics/index.tsx Outdated
Comment thread src/app/components/OptimizelyPageMetrics/index.tsx Outdated
louisearchibald and others added 20 commits April 15, 2026 09:09
…//github.com/bbc/simorgh into WS-2284-fix-lost-view-events-in-optimizely-alt
…//github.com/bbc/simorgh into WS-2284-fix-lost-view-events-in-optimizely-alt
…//github.com/bbc/simorgh into WS-2284-fix-lost-view-events-in-optimizely-alt
This reverts commit fe65d79.
HarveyPeachey
HarveyPeachey previously approved these changes Apr 21, 2026
@HarveyPeachey HarveyPeachey dismissed their stale review April 21, 2026 09:19

ACtually just noticed something with the bundle size

@louisearchibald louisearchibald merged commit 515b8ef into latest Apr 21, 2026
13 checks passed
@louisearchibald louisearchibald deleted the WS-2284-fix-lost-view-events-in-optimizely branch April 21, 2026 09:34
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.

6 participants