Skip to content

Commit

Permalink
Remove mega test (#1372)
Browse files Browse the repository at this point in the history
* Remove test from comments-expanded adverts

* Remove test from mobile-crossword-banner

* Remove test for ranked articles and high value sections

* Changeset
  • Loading branch information
emma-imber authored May 13, 2024
1 parent 3b912f4 commit 40cbc73
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 105 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-beds-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/commercial': minor
---

Remove mega test
19 changes: 0 additions & 19 deletions src/insert/comments-expanded-advert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,8 @@ export const initCommentsExpandedAdverts = (): Promise<void> => {
document.addEventListener('comments-loaded', () => {
const currentBreakpoint = getBreakpoint(getViewport().width);
if (currentBreakpoint === 'mobile') {
if (
window.guardian.config.tests?.commercialMegaTestControl ===
'control'
) {
return;
}
void handleCommentsLoadedMobileEvent();
} else {
if (
!window.guardian.config.isDotcomRendering &&
window.guardian.config.tests?.commercialMegaTestControl ===
'control'
) {
return;
}
void handleCommentsLoadedEvent();
}
});
Expand All @@ -203,12 +190,6 @@ export const initCommentsExpandedAdverts = (): Promise<void> => {
* we need to remove the existing slots and create new slots.
*/
document.addEventListener('comments-state-change', () => {
if (
window.guardian.config.tests?.commercialMegaTestControl ===
'control'
) {
return;
}
void removeMobileCommentsExpandedAds();
});

Expand Down
7 changes: 0 additions & 7 deletions src/insert/mobile-crossword-banner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ export const init = (): Promise<void> => {
return Promise.resolve();
}

const isInMegaTestControl =
window.guardian.config.tests?.commercialMegaTestControl === 'control';

if (isInMegaTestControl) {
return Promise.resolve();
}

const anchorSelector = '.crossword__container__above-controls + *';

const anchor: HTMLElement | null = document.querySelector(anchorSelector);
Expand Down
46 changes: 5 additions & 41 deletions src/insert/spacefinder/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ const hasImages = !!window.guardian.config.page.lightboxImages?.images.length;
const hasShowcaseMainElement =
window.guardian.config.page.hasShowcaseMainElement;

const isInMegaTestControl =
window.guardian.config.tests?.commercialMegaTestControl === 'control';

const increaseAdDensity = isInHighValueSection && !isInMegaTestControl;

const minDistanceBetweenRightRailAds = 500;
const minDistanceBetweenInlineAds = increaseAdDensity ? 500 : 750;
const minDistanceBetweenInlineAds = isInHighValueSection ? 500 : 750;

/**
* Rules to avoid inserting ads in the right rail too close to each other
Expand Down Expand Up @@ -160,8 +155,8 @@ const addDesktopInline1 = (fillSlot: FillAdSlot): Promise<boolean> => {
opponentSelectorRules: {
// don't place ads right after a heading
':scope > h2, [data-spacefinder-role="nested"] > h2': {
minAboveSlot: increaseAdDensity ? 150 : 5,
minBelowSlot: increaseAdDensity ? 0 : 190,
minAboveSlot: isInHighValueSection ? 150 : 5,
minBelowSlot: isInHighValueSection ? 0 : 190,
},
[`.${adSlotContainerClass}`]: {
minAboveSlot: 500,
Expand Down Expand Up @@ -311,40 +306,11 @@ const addDesktopRightRailAds = (fillSlot: FillAdSlot): Promise<boolean> => {
};

const addMobileInlineAds = (fillSlot: FillAdSlot): Promise<boolean> => {
const minDistanceFromArticleTop = !isInMegaTestControl ? 100 : 200;

/**
* These 2 sets of rules are for the changes to "ranked" articles as part of the mega test
*/
const oldRules: SpacefinderRules = {
bodySelector: articleBodySelector,
candidateSelector: ':scope > p',
minAbove: 200,
minBelow: 200,
opponentSelectorRules: {
':scope > h2': {
minAboveSlot: 100,
minBelowSlot: 250,
},
...inlineAdSlotContainerRules,
[`:scope > :not(p):not(h2):not(.${adSlotContainerClass}):not(#sign-in-gate)`]:
{
minAboveSlot: 35,
minBelowSlot: 200,
},
},
filter: (candidate, lastWinner) => {
if (!lastWinner) {
return true;
}
const distanceBetweenAds = candidate.top - lastWinner.top;
return distanceBetweenAds >= minDistanceBetweenInlineAds;
},
};
const minDistanceFromArticleTop = 100;

const ignoreList = `:not(p):not(h2):not(hr):not(.${adSlotContainerClass}):not(#sign-in-gate):not([data-spacefinder-type$="NumberedTitleBlockElement"])`;

const newRules: SpacefinderRules = {
const rules: SpacefinderRules = {
bodySelector: articleBodySelector,
candidateSelector:
':scope > p, :scope > h2, :scope > [data-spacefinder-type$="NumberedTitleBlockElement"], [data-spacefinder-role="nested"] > p',
Expand Down Expand Up @@ -382,8 +348,6 @@ const addMobileInlineAds = (fillSlot: FillAdSlot): Promise<boolean> => {
},
};

const rules = isInMegaTestControl ? oldRules : newRules;

const insertAds: SpacefinderWriter = async (paras) => {
const slots = paras.map(async (para, i) => {
const name = i === 0 ? 'top-above-nav' : `inline${i}`;
Expand Down
39 changes: 1 addition & 38 deletions src/insert/spacefinder/spacefinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ type Measurements = {
opponents?: ElementDimensionMap;
};

const isInMegaTestControl =
window.guardian.config.tests?.commercialMegaTestControl === 'control';

const query = (selector: string, context?: HTMLElement | Document) => [
...(context ?? document).querySelectorAll<HTMLElement>(selector),
];
Expand Down Expand Up @@ -306,12 +303,8 @@ const bypassTestCandidate = (
candidate.element === opponent.element ||
opponent.element.contains(candidate.element);

/**
* These 2 sets of candidate test functions are for the changes to "ranked" articles as part of the mega test
*/

// test one element vs another for the given rules
const newTestCandidate = (
const testCandidate = (
rule: RuleSpacing,
candidate: SpacefinderItem,
opponent: SpacefinderItem,
Expand Down Expand Up @@ -348,36 +341,6 @@ const newTestCandidate = (
return pass;
};

const oldTestCandidate = (
rule: RuleSpacing,
candidate: SpacefinderItem,
opponent: SpacefinderItem,
): boolean => {
const isMinAbove = candidate.top - opponent.bottom >= rule.minAboveSlot;
const isMinBelow = opponent.top - candidate.top >= rule.minBelowSlot;

const pass = isMinAbove || isMinBelow;

if (!pass) {
// if the test fails, add debug information to the candidate metadata
const isBelow = candidate.top < opponent.top;
const required = isBelow ? rule.minBelowSlot : rule.minAboveSlot;
const actual = isBelow
? opponent.top - candidate.top
: candidate.top - opponent.bottom;

candidate.meta?.tooClose.push({
required,
actual,
element: opponent.element,
});
}

return pass;
};

const testCandidate = isInMegaTestControl ? oldTestCandidate : newTestCandidate;

// test one element vs an array of other elements for the given rule
const testCandidates = (
rule: RuleSpacing,
Expand Down

0 comments on commit 40cbc73

Please sign in to comment.