Skip to content

Commit 7d63a6e

Browse files
authored
Remove prebid bid cache code (#2152)
Remove all prebid bid caching related code including grouping slots
1 parent 83a83b1 commit 7d63a6e

7 files changed

Lines changed: 7 additions & 103 deletions

File tree

bundle/src/define/Advert.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,9 @@ const isSizeMappingEmpty = (sizeMapping: SizeMapping): boolean => {
127127
Object.entries(sizeMapping).every(([, mapping]) => mapping.length === 0)
128128
);
129129
};
130-
131-
//We are grouping all fronts-banner slots and subsequent inline slots except inline1 to get the most use of prebid bid caching
132-
const getPrebidAdUnit = (advertId: string): string => {
133-
if (advertId.includes('fronts-banner')) {
134-
return 'banner';
135-
} else if (advertId.includes('inline') && !advertId.includes('inline1')) {
136-
return 'inline';
137-
}
138-
return advertId;
139-
};
140-
141130
class Advert implements IAdvert {
142131
id: string;
143132
node: HTMLElement;
144-
prebidAdUnit: string;
145133
sizes: SizeMapping;
146134
headerBiddingSizes: HeaderBiddingSize[] | null = null;
147135
size: AdSize | 'fluid' | null = null;
@@ -165,7 +153,6 @@ class Advert implements IAdvert {
165153
) {
166154
this.id = adSlotNode.id;
167155
this.node = adSlotNode;
168-
this.prebidAdUnit = getPrebidAdUnit(adSlotNode.id);
169156
this.sizes = this.generateSizeMapping(additionalSizeMapping);
170157

171158
const slotDefinition = defineSlot(

bundle/src/experiments/ab-tests.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { ABTest } from '@guardian/ab-core';
22
import { admiralAdblockRecovery } from './tests/admiral-adblocker-recovery';
3-
import { prebidAdUnit } from './tests/prebid-ad-unit';
43
import { prebid946 } from './tests/prebid946';
54

65
/**
@@ -11,6 +10,5 @@ import { prebid946 } from './tests/prebid946';
1110
export const concurrentTests: ABTest[] = [
1211
// one test per line
1312
prebid946,
14-
prebidAdUnit,
1513
admiralAdblockRecovery,
1614
];

bundle/src/experiments/tests/prebid-ad-unit.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

bundle/src/lib/header-bidding/prebid/prebid.spec.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { type ConsentState } from '@guardian/libs';
22
import { getConsentFor } from '@guardian/libs';
3-
import { isUserInVariant } from '../../../experiments/ab';
43
import { pubmatic } from '../../__vendor/pubmatic';
54
import { getAdvertById as getAdvertById_ } from '../../dfp/get-advert-by-id';
65
import { shouldIncludeBidder, shouldIncludePermutive } from '../utils';
@@ -28,10 +27,6 @@ jest.mock('../utils', () => ({
2827
.mockReturnValue(jest.fn().mockReturnValue(true)),
2928
}));
3029

31-
jest.mock('experiments/ab', () => ({
32-
isUserInVariant: jest.fn(),
33-
}));
34-
3530
jest.mock('@guardian/libs', () => ({
3631
...jest.requireActual('@guardian/libs'),
3732
getConsentFor: jest.fn(),
@@ -77,8 +72,6 @@ describe('initialise', () => {
7772
jest.mocked(shouldIncludeBidder).mockReturnValue(
7873
jest.fn().mockReturnValue(true),
7974
);
80-
jest.mocked(isUserInVariant).mockReturnValue(false);
81-
window.guardian.config.switches.prebidBidCache = true;
8275
mockGetConsentForID5(true);
8376

8477
prebid.initialise(window, mockConsentState);
@@ -128,7 +121,6 @@ describe('initialise', () => {
128121
},
129122
priceGranularity: 'custom',
130123
timeoutBuffer: 400,
131-
useBidCache: true,
132124
userSync: {
133125
syncDelay: 3000,
134126
syncEnabled: true,
@@ -189,7 +181,6 @@ describe('initialise', () => {
189181
jest.mocked(shouldIncludeBidder).mockReturnValue(
190182
jest.fn().mockReturnValue(true),
191183
);
192-
jest.mocked(isUserInVariant).mockReturnValue(false);
193184

194185
mockGetConsentForID5(false);
195186
prebid.initialise(window, mockConsentState);
@@ -244,18 +235,6 @@ describe('initialise', () => {
244235
expect(window.pbjs?.getConfig('consentManagement')).toBeUndefined();
245236
});
246237

247-
test('should set value of useBidCache correctly in Prebid config when the switch is on', () => {
248-
window.guardian.config.switches.prebidBidCache = true;
249-
prebid.initialise(window, mockConsentState);
250-
expect(window.pbjs?.getConfig('useBidCache')).toBe(true);
251-
});
252-
253-
test('should set value of useBidCache correctly in Prebid config when the switch is off', () => {
254-
window.guardian.config.switches.prebidBidCache = false;
255-
prebid.initialise(window, mockConsentState);
256-
expect(window.pbjs?.getConfig('useBidCache')).toBe(false);
257-
});
258-
259238
test('should not include realTimeData object if permutive should not be included', () => {
260239
jest.mocked(shouldIncludePermutive).mockReturnValue(false);
261240
prebid.initialise(window, mockConsentState);

bundle/src/lib/header-bidding/prebid/prebid.ts

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
isSwitchedOn,
2929
shouldIncludeBidder,
3030
shouldIncludePermutive,
31-
shouldIncludePrebidAdUnit,
3231
stripDfpAdPrefixFrom,
3332
} from '../utils';
3433
import { bids } from './bid-config';
@@ -119,7 +118,6 @@ type PbjsConfig = {
119118
};
120119
consentManagement?: ConsentManagement;
121120
realTimeData?: unknown;
122-
useBidCache?: boolean;
123121
customPriceBucket?: PrebidPriceGranularity;
124122
/**
125123
* This is a custom property that has been added to our fork of prebid.js
@@ -222,7 +220,7 @@ class PrebidAdUnit {
222220
pageTargeting: PageTargeting,
223221
consentState: ConsentState,
224222
) {
225-
this.code = shouldIncludePrebidAdUnit ? advert.prebidAdUnit : advert.id;
223+
this.code = advert.id;
226224
this.mediaTypes = { banner: { sizes: slot.sizes } };
227225
this.gpid = this.generateGpid(advert, slot);
228226
this.ortb2Imp = {
@@ -235,15 +233,15 @@ class PrebidAdUnit {
235233
};
236234

237235
this.bids = bids(
238-
shouldIncludePrebidAdUnit ? advert.prebidAdUnit : advert.id,
236+
advert.id,
239237
slot.sizes,
240238
pageTargeting,
241239
this.gpid,
242240
consentState,
243241
);
244242

245243
advert.headerBiddingSizes = slot.sizes;
246-
log('commercial', `PrebidAdUnit ${advert.id}`, this.bids);
244+
log('commercial', `PrebidAdUnit ${this.code}`, this.bids);
247245
}
248246

249247
isEmpty() {
@@ -296,9 +294,7 @@ declare global {
296294
onEvent: (event: PbjsEvent, handler: PbjsEventHandler) => void;
297295
setTargetingForGPTAsync: (
298296
codeArr?: string[],
299-
customSlotMatching?: (
300-
slot: googletag.Slot,
301-
) => (adUnitCode: string) => boolean,
297+
customSlotMatching?: (slot: unknown) => unknown,
302298
) => void;
303299
getEvents: () => PrebidEvent[];
304300
};
@@ -430,7 +426,6 @@ const initialise = (window: Window, consentState: ConsentState): void => {
430426
timeoutBuffer,
431427
priceGranularity,
432428
userSync,
433-
useBidCache: isSwitchedOn('prebidBidCache'),
434429
},
435430
);
436431

@@ -622,34 +617,14 @@ const initialise = (window: Window, consentState: ConsentState): void => {
622617
});
623618
};
624619

625-
/**
626-
* Creates a slot matching function for Prebid to match GPT slots with their corresponding ad units
627-
* @param slot The googletag slot to find a matching advert for
628-
* @returns A function that takes an adUnitCode and returns true if the slot's corresponding advert has a matching prebidAdUnit
629-
* @see https://docs.prebid.org/dev-docs/publisher-api-reference/setTargetingForGPTAsync.html#custom-slot-matching
630-
*/
631-
const customSlotMatching = (slot: googletag.Slot) => {
632-
return function (adUnitCode: string) {
633-
const advert = getAdvertById(slot.getSlotElementId());
634-
return advert?.prebidAdUnit === adUnitCode;
635-
};
636-
};
637-
638620
const bidsBackHandler = (
639621
adUnits: PrebidAdUnit[],
640622
eventTimer: EventTimer,
641623
): Promise<void> =>
642624
new Promise((resolve) => {
643-
if (shouldIncludePrebidAdUnit) {
644-
window.pbjs?.setTargetingForGPTAsync(
645-
adUnits.map((u) => u.code).filter(isString),
646-
customSlotMatching,
647-
);
648-
} else {
649-
window.pbjs?.setTargetingForGPTAsync(
650-
adUnits.map((u) => u.code).filter(isString),
651-
);
652-
}
625+
window.pbjs?.setTargetingForGPTAsync(
626+
adUnits.map((u) => u.code).filter(isString),
627+
);
653628

654629
resolve();
655630

bundle/src/lib/header-bidding/utils.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import {
88
} from '@guardian/commercial-core/geo/geo-utils';
99
import { type ConsentState, getConsentFor, isString } from '@guardian/libs';
1010
import { once } from 'lodash-es';
11-
import { isUserInVariant } from '../../experiments/ab';
12-
import { prebidAdUnit } from '../../experiments/tests/prebid-ad-unit';
1311
import {
1412
getCurrentTweakpoint,
1513
matchesBreakpoints,
@@ -258,6 +256,3 @@ export const containsWS = (sizes: HeaderBiddingSize[]): boolean =>
258256
contains(sizes, createAdSize(160, 600));
259257

260258
export const shouldIncludeOnlyA9 = window.location.hash.includes('#only-a9');
261-
262-
export const shouldIncludePrebidAdUnit =
263-
isSwitchedOn('prebidBidCache') && isUserInVariant(prebidAdUnit, 'variant');

core/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ type HeaderBiddingSize = AdSize;
88
interface Advert {
99
id: string;
1010
node: HTMLElement;
11-
prebidAdUnit: string;
1211
sizes: SizeMapping;
1312
headerBiddingSizes: HeaderBiddingSize[] | null;
1413
size: AdSize | 'fluid' | null;

0 commit comments

Comments
 (0)