-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
🦋 Changeset detectedLatest commit: c061891 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
606acc9
to
09dc6f0
Compare
eebc53f
to
d007a78
Compare
🚀 0.0.0-beta-20240212160939 published to npm as a beta release |
🚀 0.0.0-beta-20240213120659 published to npm as a beta release |
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.
📝
const getCommentsColumn = async (): Promise<HTMLElement> => { | ||
return fastdom.measure(() => { | ||
const commentsColumn: HTMLElement | null = | ||
document.querySelector('.comments-column'); |
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.
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.
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.
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
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.
Would using a data attribute be more appropriate? We use data attributes for spacefinder: https://github.com/guardian/dotcom-rendering/blob/75379021a041660acee798cd3ed8902775bf14cf/dotcom-rendering/docs/contracts/001-commercial-selectors.md
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 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!
Can space be reserved for the ad once the ad slot is inserted into the DOM? This will prevent CLS |
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') { |
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.
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.
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.
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; |
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.
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;
?
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.
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.
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.
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.
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: 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>
5609c44
to
ac3d20e
Compare
🚀 0.0.0-beta-20240220115252 published to npm as a beta release |
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 insertcomments-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 thecomments-state-change
event we remove the previously inserted comments-expanded adverts. We make sure we are on mobile breakpoint so we don't remove thecomments-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