[N/A] Fix signed-in-page-views Optimzely tracking - #14304
Open
elvinasv wants to merge 7 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to make the Optimizely signed-in-page-views conversion metric fire reliably for signed-in users by decoupling it from the Optimizely DECISION notification (which only fires when activate()/decisioning happens).
Changes:
- Added a new
SignedInPageViewTrackingcomponent intended to tracksigned-in-page-viewsindependently viaoptimizely.onReady().then(() => optimizely.track(...)). - Extracted
isSignedInlogic into a dedicated helper module and removed signed-in tracking from theDECISIONlistener. - Updated/added tests around signed-in page-view tracking behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/app/legacy/containers/PageHandlers/withOptimizelyProvider/SignedInPageViewTracking/index.tsx | Introduces a new tracking component for signed-in-page-views outside the DECISION listener. |
| src/app/legacy/containers/PageHandlers/withOptimizelyProvider/SignedInPageViewTracking/index.test.tsx | Adds unit tests for the new tracking component. |
| src/app/legacy/containers/PageHandlers/withOptimizelyProvider/isSignedIn.ts | Extracts “signed-in” detection into a shared helper. |
| src/app/legacy/containers/PageHandlers/withOptimizelyProvider/index.tsx | Removes signed-in tracking from the DECISION listener and mounts the new tracking component under the provider. |
| src/app/legacy/containers/PageHandlers/withOptimizelyProvider/index.client.test.tsx | Adjusts expectations to ensure DECISION listener no longer emits signed-in-page-views. |
| src/app/components/OptimizelyPageMetrics/index.tsx | Adds a console.log of activated experiments (appears to be debug-only). |
Suppressed comments (2)
src/app/legacy/containers/PageHandlers/withOptimizelyProvider/SignedInPageViewTracking/index.test.tsx:44
- This test calls
mockOptimizely.onReady()even though the signed-out path should never invokeonReady()at all. Calling it directly in the test makes it harder to tell whether the component behaved correctly. Assert thatonReady(andtrack) were not called.
renderWithProvider();
await mockOptimizely.onReady();
expect(mockOptimizely.track).not.toHaveBeenCalled();
});
src/app/legacy/containers/PageHandlers/withOptimizelyProvider/SignedInPageViewTracking/index.test.tsx:53
- This test calls
mockOptimizely.onReady()directly (twice), which bypasses the component’s control flow and can make the “only once” guarantee less meaningful. Instead, flush the promise microtasks and assertonReady/trackcall counts across the re-render.
const { rerender } = renderWithProvider();
await mockOptimizely.onReady();
rerender(
<OptimizelyProvider
optimizely={mockOptimizely as unknown as ReactSDKClient}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+31
to
+35
| renderWithProvider(); | ||
| await mockOptimizely.onReady(); | ||
|
|
||
| expect(mockOptimizely.track).toHaveBeenCalledWith('signed-in-page-views'); | ||
| }); |
| const { isAmp, pageType } = useContext(RequestContext); | ||
| const activatedExperiments = useActivatedExperiments(); | ||
|
|
||
| console.log({ activatedExperiments }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves JIRA: n/a
Summary
Problem
signed-in-page-views(Introduced by #14283) (used as a proxy conversion metric on thenewswb_ws_article_account_promo_bannerexperiment) was only tracked from inside the OptimizelyDECISIONnotification listener inwithOptimizelyProvider, which for this experiment only fires when the app explicitly callsoptimizely.activate(). Activation was gated behind the banner's eligibility check, which required the user to be signed out. So as soon as a user signed in (e.g. returning via the sign-in/register PTRT redirect to the same article), the experiment stopped activating for them - meaningsigned-in-page-viewscould never fire for exactly the users the metric was meant to measure.Solution
Decoupled
signed-in-page-viewstracking from theDECISIONlistener entirely. Added a newSignedInPageViewTrackingcomponent, mounted unconditionally insidewithOptimizelyProvider, that tracks the event directly viaoptimizely.onReady().then(() => optimizely.track(...))once per page view - independent of whether any experiment happens to activate/decide on that page. This removes the dependency on experiment-specific activation timing/eligibility for this metric, so it now fires reliably for every signed-in page view.Code changes
Testing
Useful Links