-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NASAA-203/204] - Create AmpExperiment component, add top stories experiment to PS articles #12048
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really nice! I've only commented on things I can speak to and nothing really around the AMP implementation which I'll leave to someone who understands that in Simorgh more deeply.
let blocksWithExperimentTopStories = blocks; | ||
const topStoriesContent = pageData?.secondaryColumn?.topStories; | ||
const shouldEnableExperimentTopStories = | ||
enableExperimentTopStories({ | ||
isAmp, | ||
service, | ||
pathname, | ||
}) && topStoriesContent; | ||
|
||
if (shouldEnableExperimentTopStories) { | ||
blocksWithExperimentTopStories = insertExperimentTopStories({ | ||
blocks, | ||
topStoriesContent, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion (non-blocking) Move this into the experiment top stories helper you've already created and just return either the blocks unchanged or the blocks with the top stories moved (as well as other things you might need)? This would hide the implementation detail of this experiment from anyone who is just parsing the article page code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally opted to keep this here since shouldEnableExperimentTopStories
is needed to conditionally render <AmpExperiment/>
on the correct pages too, but after fiddling with it I think your suggestion is cleaner. Refactored so that it's just one export from the helpers file that returns blocks
and shouldEnableExperimentTopStories
.
const newsTestAsset = 'c6v11qzyv8po'; | ||
const newsAsset = 'cz7xywn940ro'; | ||
const sportAsset = 'cpgw0xjmpd3o'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question I assume this is for testing only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this initial PR yes. I thought it would be a good idea to just keep these restricted to one asset from each service we're impacting just to be extra safe. Will remove this in the following PR once we're happy with it all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Leaving general comment but not on the AMP specific stuff
src/app/pages/ArticlePage/experimentTopStories/helpers.test.tsx
Outdated
Show resolved
Hide resolved
src/app/pages/ArticlePage/experimentTopStories/helpers.test.tsx
Outdated
Show resolved
Hide resolved
@@ -183,8 +203,8 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => { | |||
}; | |||
|
|||
const articleBlocks = startsWithHeading | |||
? blocks | |||
: [visuallyHiddenBlock, ...blocks]; | |||
? transformedBlocks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused on what's happening here. Does this always add in the experiment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be. This was flagged by a TS error I get on line 102
Right operand of ?? is unreachable because the left operand is never nullish.
If I add something in like the below on line 205 then the unit tests pass
const blocksToUse = shouldEnableExperimentTopStories
? transformedBlocks
: blocks;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the function now returns either the blocks unchanged or the experimentally changes to the blocks. This should probably be made more clear by updating the name of the function to de-couple it from experimentation. i.e getExperimentTopStoriesBlocks
should really be getTopStoriesBlocks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry that was just me being careless. You're right about the fix, I moved around a few things in the last refactor and completely left the check out. Re-added, should make sense now. Also missed some more renaming, but should be good now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iainrj I've kept the name getExperimentTopStoriesBlocks
since it doesn't get the data for the original TopStoriesSection
in the secondary column and because the top stories blocks in the article blocks array have type: experimentTopStories
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one, thanks :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Isabella-Mitchell I discussed this with @eagerterrier prior to starting this work and it was agreed that since it's just an experiment and there aren't any actual changes to the Top Stories section besides the position of it, we should be ok without full UX/accessibility checks. |
${'only service is undefined'} | ${true} | ${'c6v11qzyv8po'} | ${undefined} | ||
${'only service is defined and valid'} | ${false} | ${undefined} | ${'news'} | ||
${'all props defined but service is invalid'} | ${true} | ${'c6v11qzyv8po'} | ${'igbo'} | ||
`( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Impressive I like that
Co-authored-by: Michelle <[email protected]>
}) | ||
: blocks; | ||
const transformedBlocks = | ||
shouldEnableExperimentTopStories && blocks.length > 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the blocks.length > 2
condition to account for:
- The current formula for calculating the halfway position placing the experiment top stories block before the original block if there is only one block in the array.
- The experiment top stories block being placed before any content if there were only two blocks (e.g. headline block + image block).
Resolves NASAA-203 and NASAA-204
Experiment Brief
Overall changes
Implements experimentation on AMP pages via AMP's built-in experimentation tools. Created the
<AmpExperiment/>
component and a config used for the NASAA Google Discover experiment. This PR also adds front-end changes based on the variants served by the config.The front-end changes consist of inserting an edited copy of the Top Stories section into the blocks array that are always hidden and only shown on one column breakpoints for specific variants via css. The desktop behaviour for all variants should behave the same as usual, only showing the Top Stories section in a different location for specific variants.
These changes will only show on specific AMP assets for
news
andsport
services for this PR.No other services should be affected. These changes only affect specific assets initially to ensure the experimentation works as expected on pages served by the AMP cache and that performance isn't somehow significantly impacted.
This PR also does not have any analytics work completed yet (to be done in the next PR), hence it does not start the experiment or put it 'live' per se.
Code changes
<AmpExperiment/>
component (similar to other existing AMP components e.g. AmpIframe)/experimentTopStories
folder inpages/ArticlePage
that contains most of the code added specifically for this experiment.<AmpExperiment/>
for the experiment.ExperimentTopStories
that wraps a<TopStoriesSection/>
component with experiment specific styling (to show/hide via<AmpExperiment/>
).insertExperimentTopStories()
that inserts aexperimentTopStories
block into the blocks array in the halfway position of the array (this is the first variant of the experiment).simorgh-bff
FABL module.enableExperimentTopStories()
to check if the conditions to runinsertExperimentTopStories()
are fulfilled.ArticlePage.tsx
andArticlePage.styles.ts
to handle changes added specifically for the experiment.isAmp
andpathname
to list of props retrieved from the request context.topStoriesContent
out early to be passed into the<ExperimentTopStories/>
component incomponentsToRender
. This does not replace any existing logic with the Top Stories section.blocks
array used inarticleBlocks
(where a visually hidden heading block is added to blocks array) withblocksWithExperimentTopStories
. This will be the same as the blocks array if functions to insert anexperimentTopStories
block are not run, so this should not impact anything besides the specificnews
andsport
assets.topStoriesAndFeaturesSection
css intotopStoriesSection
andfeaturesSection
. This is so that styles that show/hide each Top Stories section will not affect anything else in the secondary column.experimentTopStories
blocks so that they only appear on one column breakpoints.topStoriesSection
so that it is hidden for specific variants on one column breakpoints.Testing
Ensure the following assets behave as expected and does not break AMP validation.
Override links below with specific variant are formatted as such:
/
service
/articles/xyz.amp?renderer_env=env
#amp-x-experimentName
=variant
When checking other pages with services not affected by this PR, ensure that
<amp-experiment/>
is not present in the DOM. It should be present for the assets below:Control (no changes to existing behaviour):
Variant name in code:
control
Variant 1 (show Top Stories section halfway into the article content instead of after it):
Variant name in code:
show_at_halfway
Helpful Links
AMP experiment documentation