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

Ads for Tag Fronts & respect speed #8056

Merged
merged 28 commits into from
Jul 5, 2023

Conversation

OllysCoding
Copy link
Contributor

@OllysCoding OllysCoding commented Jun 27, 2023

Summary

This PR expands the existing work to support tag fronts on DCR.

This PR does 3 key things

  1. Re-introduces the Tuple work carried out by @mxdvl in Introduce Tuple helpers #5807
  2. Tag fronts now respect the speed decided by DCR when laying out cards
  3. Tag fronts now have ads including inline MPUs, merchandising high & mobile ads

Tuple re-introduction

While working on the MPU injection code I found myself posed with a problem, we're only going to inject MPUs on containers which are a specific set of lengths. I wanted to be able to represent this in our type system, but didn't have an immediately obvious way of doing that. This is where I decided to use Tuples, adding in the code that @mxdvl originally wrote & expanding it to be more applicable for my use case, I was able to create really tidy definitions both in the model & in the components

speed (slow & fast)

The previous integration for TagFronts used one set of containers for all tag fronts, this PR updates this logic in order to consider the speed. There now 'shared' containers used for both slow & fast tag fronts, as well as some speed specific ones where the design calls for it. These layouts are taken directly directly from Frontend

Ads

Injected Inline Ads

This PR adds two new types at the model stage - GroupedTrailsSlowMpu & GroupedTrailsFastMpu, representing a set of trails that should show a MPU. These types differ by speed as both the containers & number of cards are different.

There are then two consuming components TagFrontSlowMpu.tsx & TagFrontFastMpu.tsx responsible for correctly rendering the MPU containers.

Ads are only injected if isAdFreeUser is set to false.

Merchandising High

The Merchandising high slot is now added in, using the same logic as pressed fronts

Mobile ads

Mobile ads are inserted in place of injected mpus for mobile pages, this uses similar logic to pressed fronts, but has slightly fewer considerations around placement (there are no thrashers, most viewed, etc)

Some screenshots 📷

(Ads don't render locally for me so you have to imagine the blank spaces are filled!)

Desktop:
image

Mobile:
image

OllysCoding and others added 4 commits June 26, 2023 15:18
Revert "feat: Inject MPU states into containers on Tag fronts"

This reverts commit 4d8140dd3ae5e31ebbaa340b332862e1cf5c68ab.

Revert "Revert "feat: Inject MPU states into containers on Tag fronts""

This reverts commit 7bca0a66bd23c90d7a4b1c129c72959245d16e51.
@OllysCoding OllysCoding changed the title [WIP] Ads for Tag Fronts [WIP] Ads for Tag Fronts & respect speed Jun 27, 2023
@github-actions
Copy link

github-actions bot commented Jun 27, 2023

Size Change: -45.8 kB (-7%) ✅

Total Size: 626 kB

Filename Size Change
dotcom-rendering/dist/1238.modern.********************.js 0 B -3.07 kB (removed) 🏆
dotcom-rendering/dist/3911.modern.********************.js 0 B -3.16 kB (removed) 🏆
dotcom-rendering/dist/9470.modern.********************.js 0 B -28.8 kB (removed) 🏆
dotcom-rendering/dist/9500.modern.********************.js 0 B -10.7 kB (removed) 🏆
ℹ️ View Unchanged
Filename Size Change
dotcom-rendering/dist/1061.modern.********************.js 689 B 0 B
dotcom-rendering/dist/1266.modern.********************.js 3.97 kB 0 B
dotcom-rendering/dist/1511.modern.********************.js 688 B 0 B
dotcom-rendering/dist/1813.modern.********************.js 6.52 kB 0 B
dotcom-rendering/dist/1816.modern.********************.js 780 B 0 B
dotcom-rendering/dist/1860.modern.********************.js 815 B 0 B
dotcom-rendering/dist/2006.modern.********************.js 3.84 kB 0 B
dotcom-rendering/dist/2238.modern.********************.js 619 B 0 B
dotcom-rendering/dist/2286.modern.********************.js 639 B 0 B
dotcom-rendering/dist/2429.modern.********************.js 760 B 0 B
dotcom-rendering/dist/2476.modern.********************.js 901 B 0 B
dotcom-rendering/dist/2478.modern.********************.js 491 B 0 B
dotcom-rendering/dist/2630.modern.********************.js 479 B 0 B
dotcom-rendering/dist/2843.modern.********************.js 859 B 0 B
dotcom-rendering/dist/2854.modern.********************.js 3.3 kB 0 B
dotcom-rendering/dist/2964.modern.********************.js 745 B 0 B
dotcom-rendering/dist/320.modern.********************.js 778 B 0 B
dotcom-rendering/dist/3250.modern.********************.js 3.56 kB 0 B
dotcom-rendering/dist/3398.modern.********************.js 20.4 kB 0 B
dotcom-rendering/dist/3547.modern.********************.js 942 B 0 B
dotcom-rendering/dist/3577.modern.********************.js 4.77 kB 0 B
dotcom-rendering/dist/3697.modern.********************.js 745 B 0 B
dotcom-rendering/dist/3702.modern.********************.js 829 B 0 B
dotcom-rendering/dist/375.modern.********************.js 711 B 0 B
dotcom-rendering/dist/3993.modern.********************.js 6.21 kB 0 B
dotcom-rendering/dist/40.modern.********************.js 812 B 0 B
dotcom-rendering/dist/4188.modern.********************.js 758 B 0 B
dotcom-rendering/dist/4249.modern.********************.js 556 B 0 B
dotcom-rendering/dist/4295.modern.********************.js 574 B 0 B
dotcom-rendering/dist/4331.modern.********************.js 3.36 kB 0 B
dotcom-rendering/dist/4381.modern.********************.js 622 B 0 B
dotcom-rendering/dist/4415.modern.********************.js 888 B 0 B
dotcom-rendering/dist/4738.modern.********************.js 699 B 0 B
dotcom-rendering/dist/4755.modern.********************.js 25.4 kB 0 B
dotcom-rendering/dist/4970.modern.********************.js 682 B 0 B
dotcom-rendering/dist/5153.modern.********************.js 2.29 kB 0 B
dotcom-rendering/dist/5162.modern.********************.js 2.5 kB 0 B
dotcom-rendering/dist/5182.modern.********************.js 3.9 kB 0 B
dotcom-rendering/dist/5194.modern.********************.js 748 B 0 B
dotcom-rendering/dist/5237.modern.********************.js 2.44 kB 0 B
dotcom-rendering/dist/5556.modern.********************.js 927 B 0 B
dotcom-rendering/dist/5593.modern.********************.js 2.3 kB 0 B
dotcom-rendering/dist/5676.modern.********************.js 828 B 0 B
dotcom-rendering/dist/5743.modern.********************.js 3.25 kB 0 B
dotcom-rendering/dist/5936.modern.********************.js 762 B 0 B
dotcom-rendering/dist/5959.modern.********************.js 776 B 0 B
dotcom-rendering/dist/6297.modern.********************.js 21.3 kB 0 B
dotcom-rendering/dist/6633.modern.********************.js 3.22 kB 0 B
dotcom-rendering/dist/6663.modern.********************.js 645 B 0 B
dotcom-rendering/dist/6814.modern.********************.js 5.56 kB 0 B
dotcom-rendering/dist/6939.modern.********************.js 5.36 kB 0 B
dotcom-rendering/dist/7044.modern.********************.js 887 B 0 B
dotcom-rendering/dist/7392.modern.********************.js 2.49 kB 0 B
dotcom-rendering/dist/7465.modern.********************.js 621 B 0 B
dotcom-rendering/dist/7515.modern.********************.js 745 B 0 B
dotcom-rendering/dist/7601.modern.********************.js 699 B 0 B
dotcom-rendering/dist/7844.modern.********************.js 4.98 kB 0 B
dotcom-rendering/dist/7872.modern.********************.js 1.89 kB +1 B (0%)
dotcom-rendering/dist/8012.modern.********************.js 4.66 kB 0 B
dotcom-rendering/dist/8326.modern.********************.js 2.61 kB 0 B
dotcom-rendering/dist/8452.modern.********************.js 4.28 kB +1 B (0%)
dotcom-rendering/dist/8602.modern.********************.js 868 B 0 B
dotcom-rendering/dist/8780.modern.********************.js 3.16 kB 0 B
dotcom-rendering/dist/8862.modern.********************.js 964 B 0 B
dotcom-rendering/dist/8888.modern.********************.js 2.75 kB 0 B
dotcom-rendering/dist/9328.modern.********************.js 964 B 0 B
dotcom-rendering/dist/9370.modern.********************.js 3.13 kB 0 B
dotcom-rendering/dist/9456.modern.********************.js 870 B 0 B
dotcom-rendering/dist/9463.modern.********************.js 635 B 0 B
dotcom-rendering/dist/9571.modern.********************.js 3.91 kB 0 B
dotcom-rendering/dist/9861.modern.********************.js 3.5 kB -1 B (0%)
dotcom-rendering/dist/9874.modern.********************.js 4.96 kB 0 B
dotcom-rendering/dist/9875.modern.********************.js 10.9 kB 0 B
dotcom-rendering/dist/9959.modern.********************.js 834 B 0 B
dotcom-rendering/dist/AlreadyVisited-importable.modern.********************.js 412 B +2 B (0%)
dotcom-rendering/dist/AnimatePulsingDots-importable.modern.********************.js 389 B 0 B
dotcom-rendering/dist/atomIframe.modern.********************.js 516 B 0 B
dotcom-rendering/dist/AudioAtomWrapper-importable.modern.********************.js 464 B +1 B (0%)
dotcom-rendering/dist/AustralianTerritorySwitcher-importable.modern.********************.js 4.43 kB 0 B
dotcom-rendering/dist/Branding-importable.modern.********************.js 2.18 kB 0 B
dotcom-rendering/dist/braze-web-sdk-core.modern.********************.js 36.9 kB 0 B
dotcom-rendering/dist/BrazeMessaging-importable.modern.********************.js 5.5 kB 0 B
dotcom-rendering/dist/CalloutBlockComponent-importable.modern.********************.js 6.47 kB +1 B (0%)
dotcom-rendering/dist/CalloutEmbedBlockComponent-importable.modern.********************.js 6.59 kB +1 B (0%)
dotcom-rendering/dist/Carousel-importable.modern.********************.js 5.94 kB 0 B
dotcom-rendering/dist/CarouselForNewsletters-importable.modern.********************.js 7.88 kB 0 B
dotcom-rendering/dist/ChartAtomWrapper-importable.modern.********************.js 474 B 0 B
dotcom-rendering/dist/CommentCount-importable.modern.********************.js 2.77 kB 0 B
dotcom-rendering/dist/discussion.modern.********************.js 393 B 0 B
dotcom-rendering/dist/DiscussionContainer-importable.modern.********************.js 22.2 kB 0 B
dotcom-rendering/dist/DiscussionMeta-importable.modern.********************.js 3.73 kB 0 B
dotcom-rendering/dist/DocumentBlockComponent-importable.modern.********************.js 2.71 kB 0 B
dotcom-rendering/dist/EmbedBlockComponent-importable.modern.********************.js 3.25 kB 0 B
dotcom-rendering/dist/embedIframe.modern.********************.js 520 B 0 B
dotcom-rendering/dist/EnhancePinnedPost-importable.modern.********************.js 1.95 kB -2 B (0%)
dotcom-rendering/dist/FetchCommentCounts-importable.modern.********************.js 2.97 kB 0 B
dotcom-rendering/dist/FetchOnwardsData-importable.modern.********************.js 1.97 kB 0 B
dotcom-rendering/dist/FilterKeyEventsToggle-importable.modern.********************.js 3.41 kB +1 B (0%)
dotcom-rendering/dist/FocusStyles-importable.modern.********************.js 511 B 0 B
dotcom-rendering/dist/frameworks.modern.********************.js 20.5 kB 0 B
dotcom-rendering/dist/GetCricketScoreboard-importable.modern.********************.js 3.36 kB 0 B
dotcom-rendering/dist/GetMatchNav-importable.modern.********************.js 11.4 kB 0 B
dotcom-rendering/dist/GetMatchStats-importable.modern.********************.js 6.32 kB 0 B
dotcom-rendering/dist/GetMatchTabs-importable.modern.********************.js 2.42 kB 0 B
dotcom-rendering/dist/guardian-braze-components-banner.modern.********************.js 13.3 kB 0 B
dotcom-rendering/dist/guardian-braze-components-end-of-article.modern.********************.js 10.3 kB 0 B
dotcom-rendering/dist/GuideAtomWrapper-importable.modern.********************.js 476 B 0 B
dotcom-rendering/dist/HeaderTopBar-importable.modern.********************.js 10.8 kB 0 B
dotcom-rendering/dist/index.modern.********************.js 34.3 kB 0 B
dotcom-rendering/dist/InstagramBlockComponent-importable.modern.********************.js 2.79 kB 0 B
dotcom-rendering/dist/InteractiveBlockComponent-importable.modern.********************.js 5.8 kB +1 B (0%)
dotcom-rendering/dist/InteractiveContentsBlockComponent-importable.modern.********************.js 4.09 kB 0 B
dotcom-rendering/dist/InteractiveSupportButton-importable.modern.********************.js 4.14 kB 0 B
dotcom-rendering/dist/KeyEventsCarousel-importable.modern.********************.js 2.21 kB +1 B (0%)
dotcom-rendering/dist/KnowledgeQuizAtomWrapper-importable.modern.********************.js 481 B 0 B
dotcom-rendering/dist/LatestLinks-importable.modern.********************.js 1.85 kB 0 B
dotcom-rendering/dist/LiveBlogEpic-importable.modern.********************.js 5.16 kB 0 B
dotcom-rendering/dist/Liveness-importable.modern.********************.js 5.53 kB 0 B
dotcom-rendering/dist/ManyNewsletterSignUp-importable.modern.********************.js 6.89 kB -2 B (0%)
dotcom-rendering/dist/MapEmbedBlockComponent-importable.modern.********************.js 5.32 kB -1 B (0%)
dotcom-rendering/dist/Metrics-importable.modern.********************.js 2.32 kB 0 B
dotcom-rendering/dist/MostViewedFooter-importable.modern.********************.js 5.36 kB 0 B
dotcom-rendering/dist/MostViewedFooterData-importable.modern.********************.js 7.57 kB +1 B (0%)
dotcom-rendering/dist/MostViewedRightWrapper-importable.modern.********************.js 3.79 kB 0 B
dotcom-rendering/dist/newsletterEmbedIframe.modern.********************.js 621 B 0 B
dotcom-rendering/dist/OnwardsUpper-importable.modern.********************.js 3.86 kB 0 B
dotcom-rendering/dist/PersonalityQuizAtomWrapper-importable.modern.********************.js 483 B 0 B
dotcom-rendering/dist/ProfileAtomWrapper-importable.modern.********************.js 478 B 0 B
dotcom-rendering/dist/QandaAtomWrapper-importable.modern.********************.js 475 B 0 B
dotcom-rendering/dist/ReaderRevenueDev-importable.modern.********************.js 461 B 0 B
dotcom-rendering/dist/readerRevenueDevUtils.modern.********************.js 3.03 kB 0 B
dotcom-rendering/dist/ReaderRevenueLinks-importable.modern.********************.js 5.82 kB 0 B
dotcom-rendering/dist/RecipeMultiplier-importable.modern.********************.js 3.26 kB +18 B (+1%)
dotcom-rendering/dist/relativeTime.modern.********************.js 976 B 0 B
dotcom-rendering/dist/RichLinkComponent-importable.modern.********************.js 5.05 kB 0 B
dotcom-rendering/dist/SecureSignupIframe-importable.modern.********************.js 2.57 kB -1 B (0%)
dotcom-rendering/dist/SendAMessage-importable.modern.********************.js 4.37 kB 0 B
dotcom-rendering/dist/sentry.modern.********************.js 766 B 0 B
dotcom-rendering/dist/SetABTests-importable.modern.********************.js 3.75 kB 0 B
dotcom-rendering/dist/SetAdTargeting-importable.modern.********************.js 537 B 0 B
dotcom-rendering/dist/ShareCount-importable.modern.********************.js 2.91 kB 0 B
dotcom-rendering/dist/shimport.modern.********************.js 2.78 kB 0 B
dotcom-rendering/dist/ShowHideContainers-importable.modern.********************.js 720 B +1 B (0%)
dotcom-rendering/dist/ShowMore-importable.modern.********************.js 5.17 kB -2 B (0%)
dotcom-rendering/dist/SignInGateMain.modern.********************.js 2.96 kB 0 B
dotcom-rendering/dist/SignInGateMainCheckoutComplete.modern.********************.js 3.86 kB 0 B
dotcom-rendering/dist/SignInGateSelector-importable.modern.********************.js 3.92 kB 0 B
dotcom-rendering/dist/SlotBodyEnd-importable.modern.********************.js 2.91 kB -1 B (0%)
dotcom-rendering/dist/Snow-importable.modern.********************.js 4.26 kB -1 B (0%)
dotcom-rendering/dist/SpotifyBlockComponent-importable.modern.********************.js 5.17 kB 0 B
dotcom-rendering/dist/StickyBottomBanner-importable.modern.********************.js 4 kB 0 B
dotcom-rendering/dist/SubNav-importable.modern.********************.js 2.34 kB -3 B (0%)
dotcom-rendering/dist/SupportTheG-importable.modern.********************.js 5.94 kB 0 B
dotcom-rendering/dist/TableOfContents-importable.modern.********************.js 3.08 kB 0 B
dotcom-rendering/dist/TimelineAtomWrapper-importable.modern.********************.js 476 B 0 B
dotcom-rendering/dist/TopRightAdSlot-importable.modern.********************.js 631 B 0 B
dotcom-rendering/dist/TweetBlockComponent-importable.modern.********************.js 1 kB 0 B
dotcom-rendering/dist/UnsafeEmbedBlockComponent-importable.modern.********************.js 2.8 kB 0 B
dotcom-rendering/dist/VideoFacebookBlockComponent-importable.modern.********************.js 5.33 kB 0 B
dotcom-rendering/dist/VineBlockComponent-importable.modern.********************.js 2.64 kB 0 B
dotcom-rendering/dist/WeatherData-importable.modern.********************.js 4.33 kB 0 B
dotcom-rendering/dist/YoutubeBlockComponent-importable.modern.********************.js 4.22 kB 0 B

compressed-size-action

@OllysCoding OllysCoding changed the title [WIP] Ads for Tag Fronts & respect speed Ads for Tag Fronts & respect speed Jun 29, 2023
@OllysCoding OllysCoding added the run_chromatic Runs chromatic when label is applied label Jun 29, 2023
@OllysCoding OllysCoding marked this pull request as ready for review June 29, 2023 11:30
@OllysCoding OllysCoding requested a review from a team as a code owner June 29, 2023 11:30
Comment on lines 101 to 102
//@ts-expect-error – we’ve tested this manually and it’s a very helpful method
array.slice(0, count);
Copy link
Contributor

Choose a reason for hiding this comment

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

We could have gone with augmenting the ReadonlyArray interface like so, but it feels like quite a lot for a single PR:

declare global {
	interface ReadonlyArray<T> {
		/**
		 * Returns a copy of a section of an array.
		 * For both start and end, a negative index can be used to indicate an offset from the end of the array.
		 * For example, -2 refers to the second to last element of the array.
		 * @param start The beginning index of the specified portion of the array.
		 * If start is undefined, then the slice begins at index 0.
		 * @param end The end index of the specified portion of the array. This is exclusive of the element at the index 'end'.
		 * If end is undefined, then the slice extends to the end of the array.
		 */
		slice<N extends 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12>(
			start: 0,
			end: N,
		): TupleOrLess<T, N>;
	}
}

Copy link
Contributor

@mxdvl mxdvl left a comment

Choose a reason for hiding this comment

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

Most wonderful use of the compiler to assert the lenght of tuples. I’m all for it, but worth checking this is not too esoteric with fellow devs <3

Comment on lines 10 to 12
type Props = GroupedTrailsFastMpu & {
adIndex: number;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this not be closer to the TagFrontFastMPU?

dotcom-rendering/src/components/TagFrontFastMpu.tsx Outdated Show resolved Hide resolved
dotcom-rendering/src/lib/getAdPositions.ts Outdated Show resolved Hide resolved
dotcom-rendering/src/lib/getAdPositions.ts Outdated Show resolved Hide resolved
dotcom-rendering/src/lib/tuple.ts Outdated Show resolved Hide resolved
dotcom-rendering/src/model/injectMpuIntoGroupedTrails.ts Outdated Show resolved Hide resolved
import { takeFirst } from './tuple';

describe('takeFirst', () => {
it('Always returns the correct array length when the array is one less, the same as, or one more than n', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is really asking for it.each

it.each([
 // take, expected length, array
 [1, 1, [0, 1]],
 [1, 1, [0]],
 [1, 0, []],
 // etc.
])("Can take %s correctly", (count, expectedLength, array) => {
		expect(takeFirst(array, count).length).toEqual(expectedLength);
}

Copy link
Contributor

@mxdvl mxdvl left a comment

Choose a reason for hiding this comment

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

💎 💰

Copy link
Contributor

@mxdvl mxdvl left a comment

Choose a reason for hiding this comment

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

I wonder if it would be better for this PR to have two commits, rather than fully squashed:

  • introduction of the tuple
  • all the rest of the work

dotcom-rendering/src/lib/getAdPositions.ts Outdated Show resolved Hide resolved
dotcom-rendering/src/lib/tuple.ts Outdated Show resolved Hide resolved
dotcom-rendering/src/lib/tuple.ts Outdated Show resolved Hide resolved
@OllysCoding OllysCoding merged commit c274b8a into main Jul 5, 2023
@OllysCoding OllysCoding deleted the olly/tag-fronts-containers-and-ads branch July 5, 2023 09:55
@arelra arelra mentioned this pull request Jul 5, 2023
@mxdvl mxdvl mentioned this pull request Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotcom-rendering run_chromatic Runs chromatic when label is applied
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants