Skip to content

Commit 71985b1

Browse files
committed
Initialize commercial queue early and flush after modules load
1 parent 45303a1 commit 71985b1

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

bundle/src/commercial.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { ConsentState } from '@guardian/libs';
22
import { getConsentFor, onConsent } from '@guardian/libs';
33
import { commercialFeatures } from './lib/commercial-features';
4+
import { createCommercialQueue } from './lib/guardian-commercial-queue';
5+
6+
window.guardian.commercial ??= { queue: createCommercialQueue() };
7+
48

59
const shouldBootConsentless = (consentState: ConsentState) => {
610
return (

bundle/src/lib/commercial-boot-utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ const bootCommercial = async (
4848

4949
try {
5050
return Promise.allSettled(modules.map((module) => module())).then(
51-
recordCommercialMetrics,
51+
()=>{
52+
recordCommercialMetrics();
53+
window.guardian.commercial?.queue?.flush()
54+
}
5255
);
5356
} catch (error) {
5457
// report async errors in bootCommercial to Sentry with the commercial feature tag

core/src/global.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ declare global {
4646
commercial?: {
4747
dfpEnv?: DfpEnv;
4848
a9WinningBids?: FetchBidResponse[];
49-
queue: QueueArray;
49+
queue?: QueueArray;
5050
};
5151
notificationEventHistory?: HeaderNotification[][];
5252
commercialTimer?: EventTimer;

0 commit comments

Comments
 (0)