@guardian/commercial-core 4.22.0 → 4.23.0

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,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildImaAdTagUrl = void 0;
4
+ const libs_1 = require("@guardian/libs");
4
5
  const build_page_targeting_1 = require("./build-page-targeting");
5
6
  /**
6
7
  * @param {Record<string, MaybeArray<string|number|boolean>>
@@ -17,9 +18,25 @@ const encodeCustomParams = (params) => {
17
18
  .join('&');
18
19
  return encodedParams;
19
20
  };
20
- const buildImaAdTagUrl = (adUnit, customParams, consentState) => {
21
- const pageTargeting = (0, build_page_targeting_1.buildPageTargeting)(consentState, false);
21
+ const mergeCustomParamsWithTargeting = (customParams, consentState) => {
22
+ let pageTargeting = {};
23
+ try {
24
+ pageTargeting = (0, build_page_targeting_1.buildPageTargeting)(consentState, false);
25
+ }
26
+ catch (e) {
27
+ /**
28
+ * Defensive error handling in case YoutubeAtom is used in an
29
+ * environment where guardian.config, cookies, localstorage etc
30
+ * are not available
31
+ */
32
+ (0, libs_1.log)('commercial', 'Error building YouTube IMA custom params', e);
33
+ return customParams;
34
+ }
22
35
  const mergedCustomParams = { ...customParams, ...pageTargeting };
36
+ return mergedCustomParams;
37
+ };
38
+ const buildImaAdTagUrl = (adUnit, customParams, consentState) => {
39
+ const mergedCustomParams = mergeCustomParamsWithTargeting(customParams, consentState);
23
40
  const queryParams = {
24
41
  iu: adUnit,
25
42
  tfcd: '0',
@@ -1,3 +1,4 @@
1
+ import { log } from '@guardian/libs';
1
2
  import { buildPageTargeting, filterValues } from './build-page-targeting';
2
3
  /**
3
4
  * @param {Record<string, MaybeArray<string|number|boolean>>
@@ -14,9 +15,25 @@ const encodeCustomParams = (params) => {
14
15
  .join('&');
15
16
  return encodedParams;
16
17
  };
17
- const buildImaAdTagUrl = (adUnit, customParams, consentState) => {
18
- const pageTargeting = buildPageTargeting(consentState, false);
18
+ const mergeCustomParamsWithTargeting = (customParams, consentState) => {
19
+ let pageTargeting = {};
20
+ try {
21
+ pageTargeting = buildPageTargeting(consentState, false);
22
+ }
23
+ catch (e) {
24
+ /**
25
+ * Defensive error handling in case YoutubeAtom is used in an
26
+ * environment where guardian.config, cookies, localstorage etc
27
+ * are not available
28
+ */
29
+ log('commercial', 'Error building YouTube IMA custom params', e);
30
+ return customParams;
31
+ }
19
32
  const mergedCustomParams = { ...customParams, ...pageTargeting };
33
+ return mergedCustomParams;
34
+ };
35
+ const buildImaAdTagUrl = (adUnit, customParams, consentState) => {
36
+ const mergedCustomParams = mergeCustomParamsWithTargeting(customParams, consentState);
20
37
  const queryParams = {
21
38
  iu: adUnit,
22
39
  tfcd: '0',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guardian/commercial-core",
3
- "version": "4.22.0",
3
+ "version": "4.23.0",
4
4
  "description": "Guardian advertising business logic",
5
5
  "homepage": "https://github.com/guardian/commercial-core#readme",
6
6
  "bugs": {