@highfivve/ad-tag 5.11.8 → 5.11.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,29 @@
1
- const extractDeviceIdParam = (context, advertiserIdKey) => {
2
- const deviceId = context.config__.targeting?.keyValues[advertiserIdKey];
1
+ const extractDeviceIdParam = (targeting, advertiserIdKey) => {
2
+ const deviceId = targeting[advertiserIdKey];
3
3
  if (deviceId) {
4
4
  return `&device_id=${typeof deviceId === 'string' ? deviceId : deviceId[0]}`;
5
5
  }
6
6
  return '';
7
7
  };
8
+ const extractKeywordsParam = (targeting, keywordsKey) => {
9
+ const keywords = keywordsKey ? targeting[keywordsKey] : undefined;
10
+ if (keywords) {
11
+ const value = typeof keywords === 'string' ? keywords : keywords.join(',');
12
+ return `&keywords=${encodeURIComponent(value)}`;
13
+ }
14
+ return '';
15
+ };
8
16
  export const trackInApp = (context, appConfig, additionalIdentifier, additionalCustomParams, document) => {
9
- const deviceIdParam = extractDeviceIdParam(context, appConfig.advertiserIdKey);
17
+ const targeting = {
18
+ ...context.config__.targeting?.keyValues,
19
+ ...context.runtimeConfig__.keyValues
20
+ };
21
+ const deviceIdParam = extractDeviceIdParam(targeting, appConfig.advertiserIdKey);
10
22
  const consentString = context.tcData__.gdprApplies
11
23
  ? `gdpr=1&gdpr_consent=${context.tcData__.tcString}`
12
24
  : 'gdpr=0';
13
- const linkParam = appConfig.linkOrKeyword.link
14
- ? `&link=${encodeURIComponent(appConfig.linkOrKeyword.link)}`
15
- : '';
16
- const keywordsParam = appConfig.linkOrKeyword.keywords
17
- ? `&keywords=${encodeURIComponent(appConfig.linkOrKeyword.keywords)}`
18
- : '';
25
+ const linkParam = `&link=${encodeURIComponent(context.window__.location.href)}`;
26
+ const keywordsParam = extractKeywordsParam(targeting, appConfig.keywordsKey);
19
27
  let additionalIdsParam = '';
20
28
  const identifiers = { ...appConfig.additionalIdentifier, ...additionalIdentifier };
21
29
  Object.entries(identifiers).forEach(([key, value]) => {
@@ -0,0 +1,34 @@
1
+ import { mkInitStep } from 'ad-tag/ads/adPipeline';
2
+ const name = 'styles loader';
3
+ export const createStylesLoader = () => {
4
+ let stylesConfig = null;
5
+ const config__ = () => stylesConfig;
6
+ const configure__ = (moduleConfig) => {
7
+ if (moduleConfig?.styles?.enabled) {
8
+ stylesConfig = moduleConfig.styles;
9
+ }
10
+ };
11
+ const loadStylesheet = (context, config) => {
12
+ const link = context.window__.document.createElement('link');
13
+ link.rel = 'stylesheet';
14
+ link.href = config.href;
15
+ link.addEventListener('error', () => context.logger__.error(name, `failed to load stylesheet ${config.href}`));
16
+ context.window__.document.head.prepend(link);
17
+ return Promise.resolve();
18
+ };
19
+ const initSteps__ = () => {
20
+ const config = stylesConfig;
21
+ return config ? [mkInitStep('styles-init', ctx => loadStylesheet(ctx, config))] : [];
22
+ };
23
+ return {
24
+ name,
25
+ configKey: 'styles',
26
+ description: "injects the publisher's stylesheet as a base layer in <head>",
27
+ moduleType: 'creatives',
28
+ config__,
29
+ configure__,
30
+ initSteps__,
31
+ configureSteps__: () => [],
32
+ prepareRequestAdsSteps__: () => []
33
+ };
34
+ };
package/lib/ads/moli.js CHANGED
@@ -231,6 +231,16 @@ export const createMoliTag = (window) => {
231
231
  }
232
232
  return Promise.resolve(null);
233
233
  }
234
+ function refreshQueuedInfiniteSlots(config, runtimeConfig) {
235
+ const { refreshInfiniteSlots } = runtimeConfig;
236
+ if (refreshInfiniteSlots.length === 0) {
237
+ return config;
238
+ }
239
+ const log = getLogger(runtimeConfig, window);
240
+ const configWithInfiniteSlots = refreshInfiniteSlots.reduce((currentConfig, slot) => addNewInfiniteSlotToConfig(currentConfig, slot.idOfConfiguredSlot, slot.artificialDomId, log), config);
241
+ adService.refreshAdSlots(refreshInfiniteSlots.map(slot => slot.artificialDomId), configWithInfiniteSlots, runtimeConfig);
242
+ return configWithInfiniteSlots;
243
+ }
234
244
  function requestAds() {
235
245
  switch (state.state) {
236
246
  case 'configurable': {
@@ -324,7 +334,8 @@ export const createMoliTag = (window) => {
324
334
  const validateLocation = config.spa?.validateLocation ?? 'href';
325
335
  if (state.state === 'spa-requestAds' &&
326
336
  allowRefreshAdSlot(validateLocation, state.href, window.location)) {
327
- const { config, runtimeConfig } = state;
337
+ const { runtimeConfig } = state;
338
+ const config = refreshQueuedInfiniteSlots(state.config, runtimeConfig);
328
339
  if (state.runtimeConfig.refreshSlots.length > 0) {
329
340
  adService.refreshAdSlots(runtimeConfig.refreshSlots, config, runtimeConfig);
330
341
  }
@@ -336,6 +347,7 @@ export const createMoliTag = (window) => {
336
347
  afterRequestAds.forEach(hook => hook('spa-finished'));
337
348
  const finishedState = {
338
349
  ...state,
350
+ config,
339
351
  state: 'spa-finished',
340
352
  nextRuntimeConfig: newEmptyRuntimeConfig(state.runtimeConfig),
341
353
  runtimeConfig: newEmptyRuntimeConfig(state.runtimeConfig, { keepTargeting: true })
@@ -432,8 +444,9 @@ export const createMoliTag = (window) => {
432
444
  }
433
445
  return adService.requestAds(config, nextRuntimeConfig).then(() => config);
434
446
  })
435
- .then(config => {
447
+ .then(requestedConfig => {
436
448
  const runtimeConfig = state.runtimeConfig;
449
+ const config = refreshQueuedInfiniteSlots(requestedConfig, runtimeConfig);
437
450
  if (state.runtimeConfig.refreshSlots.length > 0) {
438
451
  adService.refreshAdSlots(state.runtimeConfig.refreshSlots, config, state.runtimeConfig);
439
452
  }
@@ -0,0 +1,2 @@
1
+ import { createStylesLoader } from '../ads/modules/styles';
2
+ window.moli.registerModule(createStylesLoader());
@@ -321,6 +321,8 @@ const MoliAnalyticsModule = ({ config }) => (React.createElement(React.Fragment,
321
321
  "delay: ",
322
322
  config.batchDelay ?? 100,
323
323
  "ms"))));
324
+ const StylesModule = ({ config }) => (React.createElement(Row, { label: "Stylesheet" },
325
+ React.createElement(Tag, null, config.href)));
324
326
  const GenericModule = ({ config, subEntry }) => (React.createElement(React.Fragment, null, Object.entries(config)
325
327
  .filter(([key]) => key !== 'enabled')
326
328
  .map(([key, value]) => (React.createElement(TagContainer, { key: key, subEntry: subEntry },
@@ -338,6 +340,7 @@ const moduleComponents = {
338
340
  identitylink: IdentityLinkModule,
339
341
  pubstack: PubstackModule,
340
342
  skin: SkinModule,
343
+ styles: StylesModule,
341
344
  stickyHeaderAd: StickyHeaderAdModule,
342
345
  utiq: UtiqModule,
343
346
  prebidFirstPartyData: PrebidFirstPartyDataModule,
@@ -1,3 +1,3 @@
1
1
  export const packageJson = {
2
- version: '5.11.8'
2
+ version: '5.11.10'
3
3
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@highfivve/ad-tag",
3
- "version": "5.11.8",
3
+ "version": "5.11.10",
4
4
  "license": "Apache-2.0",
5
5
  "description": "An ad tag implementation called moli",
6
6
  "main": "./lib/index.js",