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

Move the initPermutive call #1782

Merged
merged 7 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/unlucky-lizards-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/commercial': minor
---

Move the initPermutive call so that the googletag script can be loaded a little earlier
29 changes: 29 additions & 0 deletions src/experiments/tests/move-permutive-segmentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { ABTest } from '@guardian/ab-core';

export const movePermutiveSegmentation: ABTest = {
id: 'MovePermutiveSegmentation',
author: '@commercial-dev',
start: '2025-02-12',
expiry: '2025-03-21',
audience: 0 / 100,
audienceOffset: 20 / 100,
Copy link
Contributor

@dskamiotis dskamiotis Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know its a 0% test, Wondered what this does audienceOffset: 20 / 100

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The offset is to make sure that if we set it live (eg not 0%) that the test audience wouldn't overlap with that of your test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see great, Ill keep mine to 0/100 👍

audienceCriteria: '',
successMeasure: '',
description:
'Measure the performance impact of moving the initialisation of Permutive segmentation.',
variants: [
{
id: 'control',
test: (): void => {
/* no-op */
},
},
{
id: 'variant',
test: (): void => {
/* no-op */
},
},
],
canRun: () => true,
};
9 changes: 6 additions & 3 deletions src/init/consented-advertising.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isUserInVariant } from '../experiments/ab';
import { movePermutiveSegmentation } from '../experiments/tests/move-permutive-segmentation';
import { init as prepareAdVerification } from '../lib/ad-verification/prepare-ad-verification';
import { bootCommercial } from '../lib/commercial-boot-utils';
import { adFreeSlotRemove } from './consented/ad-free-slot-remove';
Expand Down Expand Up @@ -35,9 +37,10 @@ const commercialModules = [
reloadPageOnConsentChange,
preparePrebid,
initDfpListeners,
// Permutive init code must run before google tag enableServices()
// The permutive lib however is loaded async with the third party tags
() => initPermutive().then(prepareGoogletag),
// add test to determine impact of moving initPermutive
isUserInVariant(movePermutiveSegmentation, 'variant')
? prepareGoogletag
: () => initPermutive().then(prepareGoogletag),
initDynamicAdSlots,
prepareA9,
initFillSlotListener,
Expand Down
9 changes: 9 additions & 0 deletions src/init/consented/static-ad-slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createAdvert } from '../../define/create-advert';
import { displayAds } from '../../display/display-ads';
import { displayLazyAds } from '../../display/display-lazy-ads';
import { isUserInVariant } from '../../experiments/ab';
import { movePermutiveSegmentation } from '../../experiments/tests/move-permutive-segmentation';
import { mpuWhenNoEpic } from '../../experiments/tests/mpu-when-no-epic';
import type { SizeMapping } from '../../lib/ad-sizes';
import { adSizes, createAdSize } from '../../lib/ad-sizes';
Expand All @@ -11,6 +12,7 @@ import { getCurrentBreakpoint } from '../../lib/detect/detect-breakpoint';
import { dfpEnv } from '../../lib/dfp/dfp-env';
import { queueAdvert } from '../../lib/dfp/queue-advert';
import { isInUk, isInUsa } from '../../lib/geo/geo-utils';
import { initPermutive } from './prepare-permutive';
import { setupPrebidOnce } from './prepare-prebid';
import { removeDisabledSlots } from './remove-slots';

Expand Down Expand Up @@ -63,6 +65,13 @@ const fillStaticAdvertSlots = async (): Promise<void> => {
// initiates these dependencies, to speed up the init process. Bootstrap also captures the module performance.
const dependencies: Array<Promise<void>> = [removeDisabledSlots()];

// add test to determine impact of moving initPermutive
if (isUserInVariant(movePermutiveSegmentation, 'variant')) {
// Permutive segmentation init code must run before googletag.enableServices() is called
/** @see https://support.permutive.com/hc/en-us/articles/360011779239-Deploying-the-Permutive-JavaScript-Tag */
dependencies.push(initPermutive());
}

await Promise.all(dependencies);

// Prebid might not load if it does not have consent
Expand Down
Loading