Skip to content

[N/A] Fix signed-in-page-views Optimzely tracking - #14304

Open
elvinasv wants to merge 7 commits into
latestfrom
notask-decouple-activation-from-tracking
Open

[N/A] Fix signed-in-page-views Optimzely tracking #14304
elvinasv wants to merge 7 commits into
latestfrom
notask-decouple-activation-from-tracking

Conversation

@elvinasv

@elvinasv elvinasv commented Aug 10, 2026

Copy link
Copy Markdown
Member

Resolves JIRA: n/a

Summary

Problem

signed-in-page-views (Introduced by #14283) (used as a proxy conversion metric on the newswb_ws_article_account_promo_banner experiment) was only tracked from inside the Optimizely DECISION notification listener in withOptimizelyProvider, which for this experiment only fires when the app explicitly calls optimizely.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 - meaning signed-in-page-views could never fire for exactly the users the metric was meant to measure.

Solution

Decoupled signed-in-page-views tracking from the DECISION listener entirely. Added a new SignedInPageViewTracking component, mounted unconditionally inside withOptimizelyProvider, that tracks the event directly via optimizely.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

  • List key code changes that have been made.

Testing

  1. List the steps required to test this PR.

Useful Links

@elvinasv
elvinasv marked this pull request as ready for review August 10, 2026 10:52
Copilot AI lite review requested due to automatic review settings August 10, 2026 10:52
@elvinasv elvinasv self-assigned this Aug 10, 2026

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 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 SignedInPageViewTracking component intended to track signed-in-page-views independently via optimizely.onReady().then(() => optimizely.track(...)).
  • Extracted isSignedIn logic into a dedicated helper module and removed signed-in tracking from the DECISION listener.
  • 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 invoke onReady() at all. Calling it directly in the test makes it harder to tell whether the component behaved correctly. Assert that onReady (and track) 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 assert onReady/track call 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 });
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