Skip to content

Commit

Permalink
Import prebid as a module
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakeii committed Jan 10, 2025
1 parent b9ffb75 commit 45f7683
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 26 deletions.
19 changes: 19 additions & 0 deletions src/init/consented/prebid-modules/all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import '@guardian/prebid.js/modules/adyoulikeBidAdapter';

Check failure on line 1 in src/init/consented/prebid-modules/all.ts

View workflow job for this annotation

GitHub Actions / Lint

Unable to resolve path to module '@guardian/prebid.js/modules/adyoulikeBidAdapter'
import '@guardian/prebid.js/modules/appnexusBidAdapter';

Check failure on line 2 in src/init/consented/prebid-modules/all.ts

View workflow job for this annotation

GitHub Actions / Lint

Unable to resolve path to module '@guardian/prebid.js/modules/appnexusBidAdapter'
import '@guardian/prebid.js/modules/consentManagement';

Check failure on line 3 in src/init/consented/prebid-modules/all.ts

View workflow job for this annotation

GitHub Actions / Lint

Unable to resolve path to module '@guardian/prebid.js/modules/consentManagement'
import '@guardian/prebid.js/modules/consentManagementUsp';

Check failure on line 4 in src/init/consented/prebid-modules/all.ts

View workflow job for this annotation

GitHub Actions / Lint

Unable to resolve path to module '@guardian/prebid.js/modules/consentManagementUsp'
import '@guardian/prebid.js/modules/criteoBidAdapter';

Check failure on line 5 in src/init/consented/prebid-modules/all.ts

View workflow job for this annotation

GitHub Actions / Lint

Unable to resolve path to module '@guardian/prebid.js/modules/criteoBidAdapter'
import '@guardian/prebid.js/modules/gridBidAdapter';

Check failure on line 6 in src/init/consented/prebid-modules/all.ts

View workflow job for this annotation

GitHub Actions / Lint

Unable to resolve path to module '@guardian/prebid.js/modules/gridBidAdapter'
import '@guardian/prebid.js/modules/guAnalyticsAdapter';

Check failure on line 7 in src/init/consented/prebid-modules/all.ts

View workflow job for this annotation

GitHub Actions / Lint

Unable to resolve path to module '@guardian/prebid.js/modules/guAnalyticsAdapter'
import '@guardian/prebid.js/modules/improvedigitalBidAdapter';

Check failure on line 8 in src/init/consented/prebid-modules/all.ts

View workflow job for this annotation

GitHub Actions / Lint

Unable to resolve path to module '@guardian/prebid.js/modules/improvedigitalBidAdapter'
import '@guardian/prebid.js/modules/ixBidAdapter';

Check failure on line 9 in src/init/consented/prebid-modules/all.ts

View workflow job for this annotation

GitHub Actions / Lint

Unable to resolve path to module '@guardian/prebid.js/modules/ixBidAdapter'
import '@guardian/prebid.js/modules/openxBidAdapter';

Check failure on line 10 in src/init/consented/prebid-modules/all.ts

View workflow job for this annotation

GitHub Actions / Lint

Unable to resolve path to module '@guardian/prebid.js/modules/openxBidAdapter'
import '@guardian/prebid.js/modules/ozoneBidAdapter';
import '@guardian/prebid.js/modules/permutiveRtdProvider';
import '@guardian/prebid.js/modules/prebidServerBidAdapter';
import '@guardian/prebid.js/modules/pubmaticBidAdapter';
import '@guardian/prebid.js/modules/sharedIdSystem';
import '@guardian/prebid.js/modules/sonobiBidAdapter';
import '@guardian/prebid.js/modules/tripleliftBidAdapter';
import '@guardian/prebid.js/modules/kargoBidAdapter';
import '@guardian/prebid.js/modules/rubiconBidAdapter';
14 changes: 14 additions & 0 deletions src/init/consented/prebid-modules/aus-nz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import '@guardian/prebid.js/modules/adyoulikeBidAdapter';
import '@guardian/prebid.js/modules/appnexusBidAdapter';
import '@guardian/prebid.js/modules/consentManagement';
import '@guardian/prebid.js/modules/consentManagementUsp';
import '@guardian/prebid.js/modules/criteoBidAdapter';
import '@guardian/prebid.js/modules/guAnalyticsAdapter';
import '@guardian/prebid.js/modules/ixBidAdapter';
import '@guardian/prebid.js/modules/openxBidAdapter';
import '@guardian/prebid.js/modules/permutiveRtdProvider';
import '@guardian/prebid.js/modules/prebidServerBidAdapter';
import '@guardian/prebid.js/modules/pubmaticBidAdapter';
import '@guardian/prebid.js/modules/sharedIdSystem';
import '@guardian/prebid.js/modules/tripleliftBidAdapter';
import '@guardian/prebid.js/modules/rubiconBidAdapter';
15 changes: 15 additions & 0 deletions src/init/consented/prebid-modules/row.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import '@guardian/prebid.js/modules/adyoulikeBidAdapter';
import '@guardian/prebid.js/modules/appnexusBidAdapter';
import '@guardian/prebid.js/modules/consentManagement';
import '@guardian/prebid.js/modules/consentManagementUsp';
import '@guardian/prebid.js/modules/criteoBidAdapter';
import '@guardian/prebid.js/modules/guAnalyticsAdapter';
import '@guardian/prebid.js/modules/improvedigitalBidAdapter';
import '@guardian/prebid.js/modules/ixBidAdapter';
import '@guardian/prebid.js/modules/openxBidAdapter';
import '@guardian/prebid.js/modules/ozoneBidAdapter';
import '@guardian/prebid.js/modules/permutiveRtdProvider';
import '@guardian/prebid.js/modules/prebidServerBidAdapter';
import '@guardian/prebid.js/modules/pubmaticBidAdapter';
import '@guardian/prebid.js/modules/sharedIdSystem';
import '@guardian/prebid.js/modules/rubiconBidAdapter';
15 changes: 15 additions & 0 deletions src/init/consented/prebid-modules/uk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import '@guardian/prebid.js/modules/adyoulikeBidAdapter';
import '@guardian/prebid.js/modules/appnexusBidAdapter';
import '@guardian/prebid.js/modules/consentManagement';
import '@guardian/prebid.js/modules/consentManagementUsp';
import '@guardian/prebid.js/modules/criteoBidAdapter';
import '@guardian/prebid.js/modules/guAnalyticsAdapter';
import '@guardian/prebid.js/modules/improvedigitalBidAdapter';
import '@guardian/prebid.js/modules/ixBidAdapter';
import '@guardian/prebid.js/modules/openxBidAdapter';
import '@guardian/prebid.js/modules/ozoneBidAdapter';
import '@guardian/prebid.js/modules/permutiveRtdProvider';
import '@guardian/prebid.js/modules/prebidServerBidAdapter';
import '@guardian/prebid.js/modules/pubmaticBidAdapter';
import '@guardian/prebid.js/modules/sharedIdSystem';
import '@guardian/prebid.js/modules/rubiconBidAdapter';
16 changes: 16 additions & 0 deletions src/init/consented/prebid-modules/us.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import '@guardian/prebid.js/modules/adyoulikeBidAdapter';
import '@guardian/prebid.js/modules/consentManagement';
import '@guardian/prebid.js/modules/consentManagementUsp';
import '@guardian/prebid.js/modules/criteoBidAdapter';
import '@guardian/prebid.js/modules/gridBidAdapter';
import '@guardian/prebid.js/modules/guAnalyticsAdapter';
import '@guardian/prebid.js/modules/ixBidAdapter';
import '@guardian/prebid.js/modules/ozoneBidAdapter';
import '@guardian/prebid.js/modules/permutiveRtdProvider';
import '@guardian/prebid.js/modules/prebidServerBidAdapter';
import '@guardian/prebid.js/modules/pubmaticBidAdapter';
import '@guardian/prebid.js/modules/sharedIdSystem';
import '@guardian/prebid.js/modules/sonobiBidAdapter';
import '@guardian/prebid.js/modules/tripleliftBidAdapter';
import '@guardian/prebid.js/modules/kargoBidAdapter';
import '@guardian/prebid.js/modules/rubiconBidAdapter';
29 changes: 29 additions & 0 deletions src/init/consented/prebid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pbjs from '@guardian/prebid.js';
import { isUserInVariant } from '../../experiments/ab';
import { regionSpecificPrebid } from '../../experiments/tests/region-specific-prebid';
import { isInAuOrNz, isInUk, isInUsa } from '../../lib/geo/geo-utils';

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

void (async () => {
await import(
/* webpackChunkName: "prebid-[request]" */
`./prebid-modules/${prebidVersion()}`
);

pbjs.processQueue();
})();

export { pbjs };
28 changes: 2 additions & 26 deletions src/init/consented/prepare-prebid.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import type { ConsentFramework } from '@guardian/libs';
import { getConsentFor, log, onConsent } from '@guardian/libs';
import { once } from 'lodash-es';
import { isUserInVariant } from '../../experiments/ab';
import { regionSpecificPrebid } from '../../experiments/tests/region-specific-prebid';
import { commercialFeatures } from '../../lib/commercial-features';
import { isGoogleProxy } from '../../lib/detect/detect-google-proxy';
import {
isInAuOrNz,
isInCanada,
isInUk,
isInUsa,
} from '../../lib/geo/geo-utils';
import { isInCanada } from '../../lib/geo/geo-utils';
import { prebid } from '../../lib/header-bidding/prebid/prebid';
import { shouldIncludeOnlyA9 } from '../../lib/header-bidding/utils';

Expand All @@ -23,26 +16,9 @@ const shouldLoadPrebid = () =>
!shouldIncludeOnlyA9 &&
!isInCanada();

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

const loadPrebid = async (framework: ConsentFramework): Promise<void> => {
if (shouldLoadPrebid()) {
await import(
/* webpackChunkName: "Prebid.js" */
`@guardian/prebid.js/build/dist/${prebidVersion()}/prebid`
);
await import(`./prebid`);
prebid.initialise(window, framework);
}
};
Expand Down
8 changes: 8 additions & 0 deletions src/types/modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ declare module '*.svg' {
// eslint-disable-next-line import/no-default-export -- allow svg imports
export default content;
}

declare module '@guardian/prebid.js' {
const pbjs: {
processQueue: () => void;
};
// eslint-disable-next-line import/no-default-export -- allow prebid.js imports
export default pbjs;
}

0 comments on commit 45f7683

Please sign in to comment.