@highfivve/ad-tag 5.11.8 → 5.11.9

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]) => {
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
  }
@@ -1,3 +1,3 @@
1
1
  export const packageJson = {
2
- version: '5.11.8'
2
+ version: '5.11.9'
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.9",
4
4
  "license": "Apache-2.0",
5
5
  "description": "An ad tag implementation called moli",
6
6
  "main": "./lib/index.js",