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

Show ads on mobile discussion #1239

Merged
merged 24 commits into from
Feb 21, 2024
Merged

Conversation

deedeeh
Copy link
Contributor

@deedeeh deedeeh commented Feb 1, 2024

What does this change?

This PR is an OKR ticket to insert MPU ads in mobile discussion as the discussion readers are our most engaged readers. Other PRs linked to this one guardian/dotcom-rendering#10448 and guardian/frontend#26899

The first ad is shown after the 4th comment and then an ad is inserted after every 5 comments. We don't insert every 5 comments from the beginning because the number of comments is usually a multiple of 5, and showing an ad after the last comment doesn't look right from a UX point of view.

The code listens for the custom event comments-loaded from DCR and we insert comments-expanded-${id} ads.

The code also listens for the comments-state-change event which is fired when the user makes a change in filter or to the page number. When we receive the comments-state-change event we remove the previously inserted comments-expanded adverts. We make sure we are on mobile breakpoint so we don't remove the comments-expanded ads on the right column on desktop view.

This feature is behind a feature switch for now.

Why?

Increase revenue and ad ratio without impacting the user experience.

Demo

mobile-expanded-comments-480.mov

Copy link

changeset-bot bot commented Feb 1, 2024

🦋 Changeset detected

Latest commit: c061891

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

@deedeeh deedeeh changed the title Show ads on mobile discussion Show ads on mobile discussion AB tests Feb 1, 2024
@deedeeh deedeeh force-pushed the dina/show-ads-on-mobile-discussion branch from 606acc9 to 09dc6f0 Compare February 1, 2024 16:07
@emma-imber emma-imber force-pushed the dina/show-ads-on-mobile-discussion branch 2 times, most recently from eebc53f to d007a78 Compare February 12, 2024 15:29
@deedeeh deedeeh added [beta] @guardian/commercial Add this label to publish an @guardian/commercial beta npm release from a PR and removed [beta] @guardian/commercial Add this label to publish an @guardian/commercial beta npm release from a PR labels Feb 12, 2024
Copy link
Contributor

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

@deedeeh deedeeh added [beta] @guardian/commercial Add this label to publish an @guardian/commercial beta npm release from a PR and removed [beta] @guardian/commercial Add this label to publish an @guardian/commercial beta npm release from a PR labels Feb 13, 2024
Copy link
Contributor

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

@deedeeh deedeeh removed the [beta] @guardian/commercial Add this label to publish an @guardian/commercial beta npm release from a PR label Feb 13, 2024
@emma-imber emma-imber marked this pull request as ready for review February 14, 2024 09:48
@emma-imber emma-imber requested a review from a team as a code owner February 14, 2024 09:48
src/core/ad-sizes.ts Outdated Show resolved Hide resolved
Copy link
Member

@arelra arelra left a comment

Choose a reason for hiding this comment

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

📝

const getCommentsColumn = async (): Promise<HTMLElement> => {
return fastdom.measure(() => {
const commentsColumn: HTMLElement | null =
document.querySelector('.comments-column');
Copy link
Member

Choose a reason for hiding this comment

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

This might break if the upstream class naming changes.

Would an e2e test be beneficial for this functionality? We could check that ads are inserted into mobile discussion, which would also cover if this contract breaks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah good point! We added the class name ourselves in DCR, we can add a comment to the code to explain to other developers why it was added to help discourage deletion. An e2e is test is a good idea - we'll have a look at implementing that

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should save writing an e2e test until we have the AB test results? We don't know for sure that this feature will be implemented yet. Would definitely be a valuable addition if we do implement the feature though!

@domlander
Copy link
Contributor

Can space be reserved for the ad once the ad slot is inserted into the DOM? This will prevent CLS

@domlander
Copy link
Contributor

domlander commented Feb 14, 2024

Not an issue, just something to think about:

It is possible that a comments-expanded ad can appear at the bottom of the comments section when it is expanded. This is fine in the below image as it sits above the Most Viewed container. Will the Most Viewed container always directly below the comments? Are there any situation where a different type of advert could be below the comments container?

image

@Jakeii
Copy link
Member

Jakeii commented Feb 14, 2024

You may have already explained this, but what made you decide to add the slots via JS, rather than in the react code in DCR?

@emma-imber
Copy link
Contributor

emma-imber commented Feb 14, 2024

Not an issue, just something to think about:

It is possible that a comments-expanded ad can appear at the bottom of the comments section when it is expanded. This is fine in the below image as it sits above the Most Viewed container. Will the Most Viewed container always directly below the comments? Are there any situation where a different type of advert could be below the comments container?

image

The only case in DCR where the Most Viewed component doesn't appear below the Discussion Component is when the content is paid for. I may be wrong but I've never seen comments on paid for content?

@emma-imber
Copy link
Contributor

You may have already explained this, but what made you decide to add the slots via JS, rather than in the react code in DCR?

It was simply that it made sense to us for all of the comments-expanded logic to live together in one file.

@@ -67,6 +106,30 @@ const createResizeObserver = (rightColumnNode: HTMLElement) => {
resizeObserver.observe(rightColumnNode);
};

const removeMobileCommentsExpandedAds = (): Promise<void> => {
const currentBreakpoint = getBreakpoint(getViewport().width);
if (currentBreakpoint === 'mobile') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we include tablet as well? We don't show a right column until the desktop breakpoint. Happy for this to be a follow-up ticket.

Copy link
Contributor

Choose a reason for hiding this comment

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

The ticket just specified mobile for this work which is why we haven't implemented tablet. I think it makes more sense as a follow-up ticket

@@ -53,6 +89,9 @@ const isEnoughSpaceForAd = (rightColumnNode: HTMLElement): boolean => {
return rightColumnNode.offsetHeight >= minHeightToPlaceAd;
};

const isEnoughCommentsForAd = (commentsColumn: HTMLElement): boolean =>
commentsColumn.childElementCount > 5;
Copy link
Contributor

@domlander domlander Feb 14, 2024

Choose a reason for hiding this comment

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

If we insert an advert after every fourth comment and it's acceptable for an advert to be at the bottom of the comments, should this be commentsColumn.childElementCount >= 4;?

Copy link
Contributor

Choose a reason for hiding this comment

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

We've checked this with Alex and have decided that an advert should never be at the bottom of the comments. I've introduced a check to make sure that this doesn't happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. This will also come in useful when we add comments to the frontend crossword comments, where the merchandising-high slot follows the comments.

deedeeh and others added 2 commits February 20, 2024 11:42
Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com>
emma-imber and others added 20 commits February 20, 2024 11:42
Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com>
Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com>
Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com>
Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com>
Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com>
Co-authored-by: Dina Hafez <dina.hafez@guardian.co.uk>
Co-authored-by: Dina Hafez <dina.hafez@guardian.co.uk>
Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com>
Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com>
Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com>
Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com>
Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com>
@emma-imber emma-imber force-pushed the dina/show-ads-on-mobile-discussion branch from 5609c44 to ac3d20e Compare February 20, 2024 11:43
@emma-imber emma-imber added the [beta] @guardian/commercial Add this label to publish an @guardian/commercial beta npm release from a PR label Feb 20, 2024
Copy link
Contributor

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

@emma-imber emma-imber changed the title Show ads on mobile discussion AB tests Show ads on mobile discussion Feb 20, 2024
@deedeeh deedeeh merged commit d285016 into main Feb 21, 2024
12 checks passed
@deedeeh deedeeh deleted the dina/show-ads-on-mobile-discussion branch February 21, 2024 10:36
@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

5 participants