From 9fa6e7dd2dba99efaa3705b90270d82fce4f18c9 Mon Sep 17 00:00:00 2001 From: Demetrios Skamiotis <49187886+dskamiotis@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:55:54 +0000 Subject: [PATCH] adds manual gpid to prebid ad unit and launch to 99% of users (#1651) * adds manual gpid to prebid ad unit * fix slotconfig spec type issue * refactor to add higher definition ext object * use window config to get page details * use window config to get page details * use slot key for slot name * add 2% ab test for gpid * add gpid to 99% of users * add changeset for release * refator gpid test name * amend userVariant control logic * Update src/experiments/tests/gpid-prebid.ts Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com> * extends date for test --------- Co-authored-by: Emma Imber <108270776+emma-imber@users.noreply.github.com> --- .changeset/tiny-rats-lay.md | 5 +++++ src/experiments/ab-tests.ts | 2 ++ src/experiments/tests/gpid-prebid.ts | 29 ++++++++++++++++++++++++ src/lib/header-bidding/prebid/prebid.ts | 30 +++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 .changeset/tiny-rats-lay.md create mode 100644 src/experiments/tests/gpid-prebid.ts diff --git a/.changeset/tiny-rats-lay.md b/.changeset/tiny-rats-lay.md new file mode 100644 index 000000000..9aef7e1d8 --- /dev/null +++ b/.changeset/tiny-rats-lay.md @@ -0,0 +1,5 @@ +--- +'@guardian/commercial': patch +--- + +adds gpid for 99% of users to prebid request diff --git a/src/experiments/ab-tests.ts b/src/experiments/ab-tests.ts index f6b637ccc..b0676ae6b 100644 --- a/src/experiments/ab-tests.ts +++ b/src/experiments/ab-tests.ts @@ -1,4 +1,5 @@ import type { ABTest } from '@guardian/ab-core'; +import { gpidPrebidAdUnits } from './tests/gpid-prebid'; import { mpuWhenNoEpic } from './tests/mpu-when-no-epic'; import { newHeaderBiddingEndpoint } from './tests/new-header-bidding-endpoint'; import { optOutFrequencyCap } from './tests/opt-out-frequency-cap'; @@ -13,4 +14,5 @@ export const concurrentTests: ABTest[] = [ mpuWhenNoEpic, optOutFrequencyCap, newHeaderBiddingEndpoint, + gpidPrebidAdUnits, ]; diff --git a/src/experiments/tests/gpid-prebid.ts b/src/experiments/tests/gpid-prebid.ts new file mode 100644 index 000000000..17e86cb4b --- /dev/null +++ b/src/experiments/tests/gpid-prebid.ts @@ -0,0 +1,29 @@ +import type { ABTest } from '@guardian/ab-core'; + +export const gpidPrebidAdUnits: ABTest = { + id: 'GpidPrebidAdUnits', + author: '@commercial-dev', + start: '2024-11-15', + expiry: '2024-12-22', + audience: 2 / 100, + audienceOffset: 0 / 100, + audienceCriteria: '', + successMeasure: 'Verify GPID is added to Prebid.js ad units', + description: + 'Test to verify that GPID is correctly added to Prebid.js ad units.', + variants: [ + { + id: 'control', + test: (): void => { + /* no-op */ + }, + }, + { + id: 'variant', + test: (): void => { + /* no-op */ + }, + }, + ], + canRun: () => true, +}; diff --git a/src/lib/header-bidding/prebid/prebid.ts b/src/lib/header-bidding/prebid/prebid.ts index a83875a26..5e7165d7b 100644 --- a/src/lib/header-bidding/prebid/prebid.ts +++ b/src/lib/header-bidding/prebid/prebid.ts @@ -9,6 +9,7 @@ import { EventTimer } from '../../../core/event-timer'; import type { PageTargeting } from '../../../core/targeting/build-page-targeting'; import type { Advert } from '../../../define/Advert'; import { isUserInVariant } from '../../../experiments/ab'; +import { gpidPrebidAdUnits } from '../../../experiments/tests/gpid-prebid'; import { newHeaderBiddingEndpoint } from '../../../experiments/tests/new-header-bidding-endpoint'; import { getPageTargeting } from '../../build-page-targeting'; import { getAdvertById } from '../../dfp/get-advert-by-id'; @@ -163,10 +164,21 @@ type BidderSettings = { magnite?: Partial; }; +const shouldIncludeGpid = !isUserInVariant(gpidPrebidAdUnits, 'control'); + class PrebidAdUnit { code: string | null | undefined; bids: PrebidBid[] | null | undefined; mediaTypes: PrebidMediaTypes | null | undefined; + gpid?: string; + ortb2Imp?: { + ext: { + gpid: string; + data: { + pbadslot: string; + }; + }; + }; constructor( advert: Advert, @@ -176,6 +188,18 @@ class PrebidAdUnit { this.code = advert.id; this.bids = bids(advert.id, slot.sizes, pageTargeting); this.mediaTypes = { banner: { sizes: slot.sizes } }; + if (shouldIncludeGpid) { + this.gpid = this.generateGpid(advert, slot); + this.ortb2Imp = { + ext: { + gpid: this.gpid, + data: { + pbadslot: this.gpid, + }, + }, + }; + } + advert.headerBiddingSizes = slot.sizes; log('commercial', `PrebidAdUnit ${this.code}`, this.bids); } @@ -183,6 +207,12 @@ class PrebidAdUnit { isEmpty() { return this.code == null; } + private generateGpid(advert: Advert, slot: HeaderBiddingSlot): string { + const sectionName = window.guardian.config.page.section; + const contentType = window.guardian.config.page.contentType; + const slotName = slot.key; + return `/59666047/gu/${sectionName}/${contentType}/${slotName}`; + } } declare global {