Skip to content

Add shouldReportToOphan to ABTest type#15551

Merged
domlander merged 4 commits intomainfrom
doml/add-canrun-abtest
Mar 19, 2026
Merged

Add shouldReportToOphan to ABTest type#15551
domlander merged 4 commits intomainfrom
doml/add-canrun-abtest

Conversation

@domlander
Copy link
Copy Markdown
Contributor

@domlander domlander commented Mar 18, 2026

What does this change?

Adds shouldReportToOphan to the ABTest type. The network request that is sent to Ophan that includes the users test participations will exclude a test if the test object has shouldReportToOphan defined and evaluates to false on the client.

Why?

So that server-side AB tests have a way of excluding users from the test on the client.

Client-side AB tests are able to exclude users using logic in the components. Server-side tests do not have this luxury as the page may have already been changed. For example, an AB test that removes the Highlights container on fronts cannot reinstate this container on the client. There would be a horrible flash of content and high CLS when the client-side code runs and the highlights container is inserted. If we wanted to run a test like this but ONLY include users that have a certain cookie, for instance, we would still show the user the experience based on their allotted variant, but choose to NOT report the user to Ophan if they don't have this cookie set.

I thought shouldReportToOphan was more accurate than canRun which was used in the previous AB testing framework, as the user will still see the experience dictated by their test variant; only the reporting is affected.

This server-side AB test attempts to only include users at certain screen sizes. This PR will allow for accurate analysis of test results.

@domlander domlander self-assigned this Mar 18, 2026
@domlander domlander added run_chromatic Runs chromatic when label is applied fronts + curation maintenance Departmental tracking: maintenance work, not a fix or a feature labels Mar 18, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 18, 2026

@domlander domlander force-pushed the doml/add-canrun-abtest branch from ba38957 to 40bc36d Compare March 18, 2026 11:08
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 18, 2026

@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 18, 2026
@domlander domlander force-pushed the doml/add-canrun-abtest branch 2 times, most recently from 7f5ae65 to 6dcfc6b Compare March 18, 2026 11:29
@domlander domlander marked this pull request as ready for review March 18, 2026 14:25
@domlander domlander requested a review from a team as a code owner March 18, 2026 14:25
@github-actions
Copy link
Copy Markdown

Hello 👋! When you're ready to run Chromatic, please apply the run_chromatic label to this PR.

You will need to reapply the label each time you want to run Chromatic.

Click here to see the Chromatic project.

@domlander domlander changed the title Add canRun to ABTest type Add shouldReportToOphan to ABTest type Mar 18, 2026
@domlander domlander requested review from Jakeii and abeddow91 March 18, 2026 14:27
*
* On by default: if not provided, the test will report to Ophan as usual.
*/
shouldReportToOphan?: () => boolean;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Jakeii I assume we don't attempt to serialise the tests anywhere?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nope they aren't, so having functions here should be fine

*
* On by default: if not provided, the test will report to Ophan as usual.
*/
shouldReportToOphan?: () => boolean;
Copy link
Copy Markdown
Contributor

@cemms1 cemms1 Mar 18, 2026

Choose a reason for hiding this comment

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

Could this be a boolean rather than a function? Similar to shouldForceMetricsCollection?

I'm possibly misunderstanding how this should work. Maybe an example could be useful here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've just given it a try. shouldReportToOphan is evaluated on the server if it is a boolean rather than a function, which I don't think we want to happen. It also doesn't work when testing locally (the ophan request is fired every time), and with a condition to stop it blowing up on the server, e.g.:
shouldReportToOphan: typeof window !== "undefined" ? window.innerWidth >= 1300 : false
If I've misunderstood please let me know.

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.

Makes sense that we want this to be able to be evaluated away from the server! Maybe an extra comment would be useful here to indicate why this is a function not a boolean since this isn't obvious at the moment and the naming convention follows the booleans

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've updated the comment to hopefully make it a bit clearer. I'm not entirely happy with the name so I'm open to ideas for improvement.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add a specific usage example to the comment, the breakpoint is a good example.

I think it is also applicable to client-side tests? They can exclude users from the functionality being tested but not the reporting!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this could also be used for client-side tests. I'll make the server-side comment as an example rather than the use case. I'll also update the comment to specify an actual example.

@domlander domlander added the run_chromatic Runs chromatic when label is applied label Mar 18, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 18, 2026
@domlander domlander force-pushed the doml/add-canrun-abtest branch from 6cf8d40 to d3cbd2e Compare March 18, 2026 15:10
@domlander domlander added the run_chromatic Runs chromatic when label is applied label Mar 18, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 18, 2026
@domlander domlander added the run_chromatic Runs chromatic when label is applied label Mar 19, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 19, 2026
Copy link
Copy Markdown
Member

@Jakeii Jakeii left a comment

Choose a reason for hiding this comment

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

Nice addition, I think this will come in handy for future tests too!

@domlander domlander merged commit 116b044 into main Mar 19, 2026
31 checks passed
@domlander domlander deleted the doml/add-canrun-abtest branch March 19, 2026 16:54
@gu-prout
Copy link
Copy Markdown

gu-prout bot commented Mar 19, 2026

Seen on PROD (merged by @domlander 7 minutes and 20 seconds ago) Please check your changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fronts + curation maintenance Departmental tracking: maintenance work, not a fix or a feature Seen-on-PROD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants