Skip to content

Commit

Permalink
Only filter even indices if there are no secondary level containers p…
Browse files Browse the repository at this point in the history
…resent on the front
  • Loading branch information
cemms1 committed Jan 3, 2025
1 parent 4b4d390 commit e04fe00
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion dotcom-rendering/src/lib/getFrontsAdPositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ const isMostViewedContainer = (collection: DCRCollectionType) =>
const isSecondaryLevelContainer = (collection: DCRCollectionType | undefined) =>
collection?.config.containerLevel === 'Secondary';

/**
* For front pages using Primary / Secondary level containers,
* we avoid inserting ads before Secondary containers
*
* Examples to demonstrate:
* Primary | Advert | Primary ✅
* Primary | Advert | Secondary ❌
* Secondary | Advert | Secondary ❌
* Secondary | Advert | Primary ✅
*/
const isBeforeASecondaryLevelContainer = (
index: number,
collections: DCRCollectionType[],
Expand Down Expand Up @@ -78,10 +88,16 @@ const isEvenIndex = (_: unknown, index: number): boolean => index % 2 === 0;
*/
const getMobileAdPositions = (collections: DCRCollectionType[]): number[] => {
const merchHighPosition = getMerchHighPosition(collections.length);
const hasSecondaryLevelContainers = collections.some(
isSecondaryLevelContainer,
);

return collections
.filter(isPossibleMobileAdPosition(merchHighPosition))
.filter(isEvenIndex)
.filter(
/** If there are no secondary level containers, we pick every other container to be a possible ad position */
(_, index) => hasSecondaryLevelContainers || isEvenIndex(_, index),
)
.map((collection) =>
collections.findIndex(({ id }) => id === collection.id),
)
Expand Down

0 comments on commit e04fe00

Please sign in to comment.