Skip to content
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

Improve spacefinder's handling of ranked and list articles on mobile #1271

Merged
merged 25 commits into from
Mar 6, 2024

Conversation

Jakeii
Copy link
Member

@Jakeii Jakeii commented Feb 14, 2024

What does this change?

Sample articles
https://www.theguardian.com/football/2024/feb/09/premier-league-10-things-to-look-out-for-this-weekend
https://www.theguardian.com/culture/2024/feb/15/miski-omar-the-10-funniest-things-i-have-ever-seen-on-the-internet
https://www.theguardian.com/culture/2024/feb/08/say-it-with-a-kiss-the-20-greatest-smooches-on-film-ranked

Improve ad insertion around headings and hr elements

On these articles spacefinder is avoiding placing ads near anything that isn't a paragraph by quite a wide margin of 200px.

We have decided that we wouldn't mind ads appearing above headings, so we can add h2 elements to our candidate selectors, some articles also place hr's above these headings and others have media (images/videos/embeds) directly after that have rules to not have ads within 200px above.

This rule makes sense so that ads are not inserted between paragraphs related to the media and the media itself. However a heading element above would indicate that the content above the heading is not directly related to the media, so an ad above the heading would be fine.

After some iteration, the best way to handle it I thought was to allow headings to "bypass" the minBelow rule for an opponent. So that heading candidates are allowed to have an ad inserted above even if they are above a media element, other elements still need to be further away.

Handle candidates/opponents with negative margins

There was another issue with this because the headings have a negative top margin and the hr's are only 1 pixel tall, so they were neither above or below it.

Examples of new placement:

Screen.Recording.2024-02-15.at.16.10.43.mov
Screen.Recording.2024-02-16.at.10.20.32.mov

Why?

Otherwise there would be no ads on these articles on mobile and we can't have that.

Copy link

changeset-bot bot commented Feb 14, 2024

🦋 Changeset detected

Latest commit: a6d166c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@guardian/commercial Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Jakeii Jakeii marked this pull request as ready for review February 15, 2024 16:12
@Jakeii Jakeii requested a review from a team as a code owner February 15, 2024 16:12
@Jakeii Jakeii added the [beta] @guardian/commercial Add this label to publish an @guardian/commercial beta npm release from a PR label Feb 15, 2024
Copy link
Contributor

🚀 0.0.0-beta-20240215161943 published to npm as a beta release

@Jakeii Jakeii changed the title Handle "Ranked" articles Handle ranked and list articles Feb 16, 2024
@Jakeii Jakeii changed the title Handle ranked and list articles Improve spacefinder's handling of ranked and list articles on mobile Feb 16, 2024
@domlander
Copy link
Contributor

I think this change could benefit from some adding some extra E2E testing. I'm concerned that other articles that use h2 or hr on mobile could be adversely affected and we wouldn't know about it.

@Jakeii
Copy link
Member Author

Jakeii commented Feb 16, 2024

I think this change could benefit from some adding some extra E2E testing. I'm concerned that other articles that use h2 or hr on mobile could be adversely affected and we wouldn't know about it.

E2E tests may be useful to ensure we don't break this functionality in future on articles we know about, but it won't tell us about the ones we don't know about!

@Jakeii
Copy link
Member Author

Jakeii commented Feb 19, 2024

The best way to ensure these articles have ads where we expect I thought was to improve the article e2e tests to check the positions of the ads, which I've managed to do. However it's going to be quite laborious to update all these positions if intentional changes are ever made.

I had a go writing a script to update the expected ad positions automatically, but I'm struggling to get playwright and typescript to play nicely together outside of the test (e.g. as a script), so abandoning that for now, I think limiting to 2 test articles will be fine for now?

@@ -290,19 +290,35 @@ const addDesktopInline2PlusAds = (): Promise<boolean> => {
const addMobileInlineAds = (): Promise<boolean> => {
const rules: SpacefinderRules = {
bodySelector: articleBodySelector,
slotSelector: ' > p',
candidateSelector: [
Copy link
Member Author

Choose a reason for hiding this comment

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

This needs to be an array for multiple elements due to how the body and candidate selector is combined within spacefinder, if they were simply comma separated it would end up for example like .article-commercial-selector > p, h2, hr which would select h2 and hr elements that aren't direct children of the article body.

minAboveSlot: 35,
minBelowSlot: 200,
// Usually we don't want an ad right before videos, embeds and atoms etc. so that we don't break up related content too much. But if we have a heading above, anything above the heading won't be related to the current content, so we can place an ad there.
bypassMinBelow:
Copy link
Member Author

Choose a reason for hiding this comment

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

Hopefully the comment makes sense but please let me know if it can be improved.

@Jakeii Jakeii requested review from domlander and a team March 1, 2024 18:04
@SiAdcock
Copy link
Contributor

SiAdcock commented Mar 1, 2024

Amazing work @Jakeii 👏

Does the rules documentation need to be updated to account for changes to how Spacefinder treats <h2>s and <hr>s?

@Jakeii
Copy link
Member Author

Jakeii commented Mar 4, 2024

Amazing work @Jakeii 👏

Does the rules documentation need to be updated to account for changes to how Spacefinder treats <h2>s and <hr>s?

I didn't even know that document existed! Will update

src/insert/spacefinder/spacefinder.ts Outdated Show resolved Hide resolved
src/insert/spacefinder/spacefinder.ts Outdated Show resolved Hide resolved
src/insert/spacefinder/spacefinder.ts Show resolved Hide resolved
@Jakeii Jakeii merged commit bece12b into main Mar 6, 2024
10 checks passed
@Jakeii Jakeii deleted the jlk/ads-mobile-ranked-lists branch March 6, 2024 09:56
@Jakeii Jakeii mentioned this pull request Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[beta] @guardian/commercial Add this label to publish an @guardian/commercial beta npm release from a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants