Skip to content

Commit

Permalink
adds manual gpid to prebid ad unit and launch to 99% of users (#1651)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* extends date for test

---------

Co-authored-by: Emma Imber <[email protected]>
  • Loading branch information
dskamiotis and emma-imber authored Nov 20, 2024
1 parent ecc4e1b commit 9fa6e7d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-rats-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/commercial': patch
---

adds gpid for 99% of users to prebid request
2 changes: 2 additions & 0 deletions src/experiments/ab-tests.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,4 +14,5 @@ export const concurrentTests: ABTest[] = [
mpuWhenNoEpic,
optOutFrequencyCap,
newHeaderBiddingEndpoint,
gpidPrebidAdUnits,
];
29 changes: 29 additions & 0 deletions src/experiments/tests/gpid-prebid.ts
Original file line number Diff line number Diff line change
@@ -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,
};
30 changes: 30 additions & 0 deletions src/lib/header-bidding/prebid/prebid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -163,10 +164,21 @@ type BidderSettings = {
magnite?: Partial<BidderSetting>;
};

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,
Expand All @@ -176,13 +188,31 @@ 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);
}

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 {
Expand Down

0 comments on commit 9fa6e7d

Please sign in to comment.