Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds manual gpid to prebid ad unit and launch to 99% of users #1651

Merged
merged 13 commits into from
Nov 20, 2024
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
Loading