Skip to content

Commit

Permalink
Move the initPermutive call (#1782)
Browse files Browse the repository at this point in the history
* Move the initPermutive call

* Make comment more useful

* Changeset

* Put change behind a 0% test

* Update test dates

* Add console log for testing
  • Loading branch information
emma-imber authored Feb 19, 2025
1 parent 890ca37 commit 6f4fe3a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
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,
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
2 changes: 2 additions & 0 deletions src/init/consented/prepare-permutive.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { log } from '@guardian/libs';
import { isUserInVariant } from '../../experiments/ab';
import { deferPermutiveLoad } from '../../experiments/tests/defer-permutive-load';
import { reportError } from '../../lib/error/report-error';
Expand Down Expand Up @@ -173,6 +174,7 @@ const runPermutive = (
* @returns Promise
*/
const initPermutiveSegmentation = () => {
log('commercial', 'Initialising Permutive segmentation');
/* eslint-disable -- permutive code */
// From here until we re-enable eslint is the Permutive code
// that we received from them.
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

0 comments on commit 6f4fe3a

Please sign in to comment.