Skip to content

Commit

Permalink
Use region specific prebid bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
emma-imber committed Nov 18, 2024
1 parent 25f3376 commit e0b8a69
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 88 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@
},
"dependencies": {
"@changesets/cli": "^2.26.2",
"@guardian/prebid.js": "8.52.0-8",
"@octokit/core": "^6.1.2",
"fastdom": "^1.0.11",
"lodash-es": "^4.17.21",
"prebid.js": "guardian/prebid.js#4d50ccf7d3f74561ef9d11a091fde5dd434d9810",
"process": "^0.11.10",
"tslib": "^2.6.2",
"web-vitals": "^4.2.1"
Expand Down
171 changes: 87 additions & 84 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions src/init/consented/prepare-prebid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { commercialFeatures } from '../../lib/commercial-features';
import { isGoogleProxy } from '../../lib/detect/detect-google-proxy';
import { prebid } from '../../lib/header-bidding/prebid/prebid';
import { shouldIncludeOnlyA9 } from '../../lib/header-bidding/utils';
import { isInCanada } from '../../utils/geo-utils';
import { isInAuOrNz, isInCanada, isInUk, isInUsa } from '../../utils/geo-utils';

const shouldLoadPrebid = () =>
!isGoogleProxy() &&
Expand All @@ -16,11 +16,21 @@ const shouldLoadPrebid = () =>
!shouldIncludeOnlyA9 &&
!isInCanada();

const prebidVersion = () => {
if (isInUk()) {
return 'uk';
} else if (isInAuOrNz()) {
return 'aus-nz';
} else if (isInUsa()) {
return 'us';
}
return 'row';
};

const loadPrebid = async (framework: ConsentFramework): Promise<void> => {
if (shouldLoadPrebid()) {
await import(
// @ts-expect-error -- there’s no types for Prebid.js
/* webpackChunkName: "Prebid.js" */ '@guardian/prebid.js/build/dist/prebid'
/* webpackChunkName: "Prebid.js" */ `prebid.js/build/dist/${prebidVersion()}/prebid`
);
prebid.initialise(window, framework);
}
Expand Down

0 comments on commit e0b8a69

Please sign in to comment.