Skip to content

Commit

Permalink
Merge fa5856f into 25031be
Browse files Browse the repository at this point in the history
  • Loading branch information
deedeeh authored Jul 22, 2024
2 parents 25031be + fa5856f commit bdb27c5
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"dependencies": {
"@changesets/cli": "^2.26.2",
"@guardian/ophan-tracker-js": "2.1.1",
"@guardian/prebid.js": "8.52.0",
"@guardian/prebid.js": "8.52.0-1",
"@octokit/core": "^6.1.2",
"fastdom": "^1.0.11",
"lodash-es": "^4.17.21",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/experiments/ab-tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ABTest } from '@guardian/ab-core';
import { mpuWhenNoEpic } from './tests/mpu-when-no-epic';
import { prebidMagnite } from './tests/prebid-magnite';

/**
* You only need to add tests to this file if the code you are testing is here in
Expand All @@ -9,4 +10,5 @@ import { mpuWhenNoEpic } from './tests/mpu-when-no-epic';
export const concurrentTests: ABTest[] = [
// one test per line
mpuWhenNoEpic,
prebidMagnite,
];
28 changes: 28 additions & 0 deletions src/experiments/tests/prebid-magnite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { ABTest } from '@guardian/ab-core';

export const prebidMagnite: ABTest = {
id: 'PrebidMagnite',
author: '@commercial-dev',
start: '2024-07-18',
expiry: '2024-09-30',
audience: 0 / 100,
audienceOffset: 0 / 100,
audienceCriteria: '',
successMeasure: '',
description: 'Test Magnite as a prebid bidder.',
variants: [
{
id: 'control',
test: (): void => {
/* no-op */
},
},
{
id: 'variant',
test: (): void => {
/* no-op */
},
},
],
canRun: () => true,
};
9 changes: 9 additions & 0 deletions src/lib/header-bidding/prebid-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ export type PrebidKargoParams = {
placementId: string;
};

//This is used to be called Rubicon but now it's called Magnite. You can find it in the Prebid.js codebase as Rubicon
export type PrebidMagniteParams = {
accountId: number;
siteId: number;
zoneId: number;
};

export type BidderCode =
| 'adyoulike'
| 'and'
Expand All @@ -127,6 +134,7 @@ export type BidderCode =
| 'improvedigital'
| 'ix'
| 'kargo'
| 'magnite'
| 'oxd'
| 'ozone'
| 'pubmatic'
Expand All @@ -143,6 +151,7 @@ export type PrebidParams =
| PrebidImproveParams
| PrebidIndexExchangeParams
| PrebidKargoParams
| PrebidMagniteParams
| PrebidOpenXParams
| PrebidOzoneParams
| PrebidPubmaticParams
Expand Down
196 changes: 196 additions & 0 deletions src/lib/header-bidding/prebid/bid-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
PrebidImproveParams,
PrebidIndexExchangeParams,
PrebidKargoParams,
PrebidMagniteParams,
PrebidOpenXParams,
PrebidOzoneParams,
PrebidPubmaticParams,
Expand All @@ -41,13 +42,16 @@ import {
containsMobileSticky,
containsMpu,
containsMpuOrDmpu,
containsPortraitInterstitial,
containsWS,
getBreakpointKey,
shouldIncludeAdYouLike,
shouldIncludeAppNexus,
shouldIncludeCriteo,
shouldIncludeImproveDigital,
shouldIncludeImproveDigitalSkin,
shouldIncludeKargo,
shouldIncludeMagnite,
shouldIncludeOpenx,
shouldIncludeSmart,
shouldIncludeSonobi,
Expand Down Expand Up @@ -384,6 +388,184 @@ const getKargoPlacementId = (sizes: HeaderBiddingSize[]): string => {
return '_y9LINEsbfh';
};

const getMagniteZoneId = (
slotId: string,
sizes: HeaderBiddingSize[],
): number => {
if (isInUk()) {
switch (getBreakpointKey()) {
case 'D':
if (containsMpuOrDmpu(sizes) || containsWS(sizes)) {
return 3426780;
}
// top-above-nav on desktop
if (
containsLeaderboardOrBillboard(sizes) &&
slotId === 'dfp-ad--top-above-nav'
) {
return 3426786;
}
// Fronts-banners on desktop
if (
containsBillboard(sizes) &&
slotId.includes('fronts-banner')
) {
return 3426790;
}
break;
case 'M':
if (containsMpu(sizes) || containsPortraitInterstitial(sizes)) {
return 3426778;
}
break;
default:
return -1;
}
}

if (isInRow()) {
switch (getBreakpointKey()) {
case 'D':
if (containsMpuOrDmpu(sizes) || containsWS(sizes)) {
return 3426822;
}
// top-above-nav on desktop
if (
containsLeaderboardOrBillboard(sizes) &&
slotId === 'dfp-ad--top-above-nav'
) {
return 3426828;
}
// Fronts-banners on desktop
if (
containsBillboard(sizes) &&
slotId.includes('fronts-banner')
) {
return 3426834;
}
break;
case 'M':
if (containsMpu(sizes) || containsPortraitInterstitial(sizes)) {
return 3426836;
}
if (containsMobileSticky(sizes)) {
return 3477560;
}
break;
default:
return -1;
}
}

if (isInUsOrCa()) {
switch (getBreakpointKey()) {
case 'D':
if (containsMpuOrDmpu(sizes) || containsWS(sizes)) {
return 3471422;
}
// top-above-nav on desktop
if (
containsLeaderboardOrBillboard(sizes) &&
slotId === 'dfp-ad--top-above-nav'
) {
return 3471428;
}
// Fronts-banners on desktop
if (
containsBillboard(sizes) &&
slotId.includes('fronts-banner')
) {
return 3471434;
}
break;
case 'M':
if (containsMpu(sizes) || containsPortraitInterstitial(sizes)) {
return 3471436;
}
if (containsMobileSticky(sizes)) {
return 3471440;
}
break;
default:
return -1;
}
}

if (isInAuOrNz()) {
switch (getBreakpointKey()) {
case 'D':
if (containsMpuOrDmpu(sizes) || containsWS(sizes)) {
return 3471452;
}
// top-above-nav on desktop
if (
containsLeaderboardOrBillboard(sizes) &&
slotId === 'dfp-ad--top-above-nav'
) {
return 3471458;
}
// Fronts-banners on desktop
if (
containsBillboard(sizes) &&
slotId.includes('fronts-banner')
) {
return 3471462;
}
break;
case 'M':
if (containsMpu(sizes) || containsPortraitInterstitial(sizes)) {
return 3471464;
}
if (containsMobileSticky(sizes)) {
return 3471468;
}
break;
default:
return -1;
}
}
return -1;
};

const getMagniteSiteId = (): number => {
if (isInUk()) {
switch (getBreakpointKey()) {
case 'D':
return 549358;
case 'M':
return 549374;
}
}

if (isInRow()) {
switch (getBreakpointKey()) {
case 'D':
return 549496;
case 'M':
return 549498;
}
}

if (isInUsOrCa()) {
switch (getBreakpointKey()) {
case 'D':
return 554244;
case 'M':
return 554248;
}
}

if (isInAuOrNz()) {
switch (getBreakpointKey()) {
case 'D':
return 554256;
case 'M':
return 554258;
}
}
return -1;
};

const pubmaticBidder = (slotSizes: HeaderBiddingSize[]): PrebidBidder => {
const defaultParams = {
name: 'pubmatic' as BidderCode,
Expand Down Expand Up @@ -533,6 +715,19 @@ const kargoBidder: PrebidBidder = {
}),
};

const magniteBidder: PrebidBidder = {
name: 'magnite',
switchName: 'prebidMagnite',
bidParams: (
_slotId: string,
sizes: HeaderBiddingSize[],
): PrebidMagniteParams => ({
accountId: 26644,
siteId: getMagniteSiteId(),
zoneId: getMagniteZoneId(_slotId, sizes),
}),
};

// There's an IX bidder for every size that the slot can take
const indexExchangeBidders = (
slotSizes: HeaderBiddingSize[],
Expand Down Expand Up @@ -577,6 +772,7 @@ const currentBidders = (
[shouldUseOzoneAdaptor(), ozoneClientSideBidder(pageTargeting)],
[shouldIncludeOpenx(), openxClientSideBidder(pageTargeting)],
[shouldIncludeKargo(), kargoBidder],
[shouldIncludeMagnite(), magniteBidder],
];

const otherBidders = biddersToCheck
Expand Down
7 changes: 7 additions & 0 deletions src/lib/header-bidding/prebid/prebid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ type BidderSettings = {
ozone?: Partial<BidderSetting>;
criteo?: Partial<BidderSetting>;
kargo?: Partial<BidderSetting>;
magnite?: Partial<BidderSetting>;
};

class PrebidAdUnit {
Expand Down Expand Up @@ -443,6 +444,12 @@ const initialise = (
};
}

if (window.guardian.config.switches.prebidMagnite) {
window.pbjs.bidderSettings.magnite = {
storageAllowed: true,
};
}

window.pbjs.setConfig(pbjsConfig);

// Adjust slot size when prebid ad loads
Expand Down
12 changes: 12 additions & 0 deletions src/lib/header-bidding/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { isString } from '@guardian/libs';
import { once } from 'lodash-es';
import { createAdSize } from 'core/ad-sizes';
import { isUserInVariant } from 'experiments/ab';
import { prebidMagnite } from 'experiments/tests/prebid-magnite';
import {
getCurrentTweakpoint,
matchesBreakpoints,
Expand Down Expand Up @@ -104,6 +106,10 @@ export const containsLeaderboardOrBillboard = (
sizes: HeaderBiddingSize[],
): boolean => containsLeaderboard(sizes) || containsBillboard(sizes);

export const containsPortraitInterstitial = (
sizes: HeaderBiddingSize[],
): boolean => contains(sizes, createAdSize(320, 480));

export const getLargestSize = (
sizes: HeaderBiddingSize[],
): HeaderBiddingSize | null => {
Expand Down Expand Up @@ -194,6 +200,12 @@ export const shouldIncludeSmart = (): boolean => isInUk() || isInRow();

export const shouldIncludeKargo = (): boolean => isInUsa();

//Add the switch here and the AB test checks
export const shouldIncludeMagnite = (): boolean =>
(isInUk() || isInRow() || isInUsOrCa() || isInAuOrNz()) &&
!!window.guardian.config.switches.prebidMagnite &&
isUserInVariant(prebidMagnite, 'variant');

export const shouldIncludeMobileSticky = once(
(): boolean =>
window.location.hash.includes('#mobile-sticky') ||
Expand Down

0 comments on commit bdb27c5

Please sign in to comment.