@guardian/commercial-core 6.0.0 → 6.2.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,5 +1,5 @@
1
1
  import type { SizeMapping } from './ad-sizes';
2
- type SlotName = 'carrot' | 'comments-expanded' | 'comments' | 'epic' | 'high-merch-lucky' | 'high-merch-paid' | 'high-merch' | 'im' | 'inline' | 'mobile-sticky' | 'mostpop' | 'top-above-nav';
2
+ type SlotName = 'carrot' | 'comments-expanded' | 'comments' | 'epic' | 'exclusion' | 'high-merch-lucky' | 'high-merch-paid' | 'high-merch' | 'im' | 'inline' | 'mobile-sticky' | 'mostpop' | 'top-above-nav';
3
3
  type CreateSlotOptions = {
4
4
  classes?: string;
5
5
  name?: string;
@@ -33,6 +33,7 @@ type PageTargeting = PartialWithNulls<{
33
33
  skinsize: 'l' | 's';
34
34
  urlkw: string[];
35
35
  vl: string;
36
+ allkw: string[];
36
37
  [_: string]: string | string[];
37
38
  } & SharedTargeting>;
38
39
  declare const filterValues: (pageTargets: Record<string, unknown>) => Record<string, string | string[]>;
@@ -28,6 +28,9 @@ exports.filterValues = filterValues;
28
28
  const buildPageTargeting = ({ adFree, clientSideParticipations, consentState, youtube = false, }) => {
29
29
  const { page, isDotcomRendering } = window.guardian.config;
30
30
  const adFreeTargeting = adFree ? { af: 't' } : {};
31
+ const sharedAdTargeting = page.sharedAdTargeting
32
+ ? (0, shared_1.getSharedTargeting)(page.sharedAdTargeting)
33
+ : {};
31
34
  const contentTargeting = (0, content_1.getContentTargeting)({
32
35
  webPublicationDate: page.webPublicationDate,
33
36
  eligibleForDCR: page.dcrCouldRender,
@@ -38,6 +41,7 @@ const buildPageTargeting = ({ adFree, clientSideParticipations, consentState, yo
38
41
  section: page.section,
39
42
  sensitive: page.isSensitive,
40
43
  videoLength: page.videoDuration,
44
+ keywords: sharedAdTargeting.k ?? [],
41
45
  });
42
46
  const getReferrer = () => document.referrer || '';
43
47
  const sessionTargeting = (0, session_1.getSessionTargeting)({
@@ -61,9 +65,6 @@ const buildPageTargeting = ({ adFree, clientSideParticipations, consentState, yo
61
65
  viewPortWidth: getViewport().width,
62
66
  cmpBannerWillShow: !consent_management_platform_1.cmp.hasInitialised() || consent_management_platform_1.cmp.willShowPrivacyMessageSync(),
63
67
  });
64
- const sharedAdTargeting = page.sharedAdTargeting
65
- ? (0, shared_1.getSharedTargeting)(page.sharedAdTargeting)
66
- : {};
67
68
  const personalisedTargeting = (0, personalised_1.getPersonalisedTargeting)({
68
69
  state: consentState,
69
70
  youtube,
@@ -63,6 +63,14 @@ type ContentTargeting = {
63
63
  * [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=195087
64
64
  */
65
65
  vl: null | (typeof videoLengths)[number];
66
+ /**
67
+ * **All** **K**ey**w**ords - [see on Ad Manager][gam]
68
+ * This is a list of all keywords on the page, including the section and the URL keywords
69
+ * Type: _Dynamic_
70
+ *
71
+ * [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=13995840
72
+ */
73
+ allkw: string[];
66
74
  };
67
75
  type Content = {
68
76
  eligibleForDCR: boolean;
@@ -72,7 +80,8 @@ type Content = {
72
80
  sensitive: boolean;
73
81
  videoLength?: number;
74
82
  webPublicationDate: number;
83
+ keywords: string[];
75
84
  };
76
- declare const getContentTargeting: ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, webPublicationDate, }: Content) => ContentTargeting;
85
+ declare const getContentTargeting: ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, webPublicationDate, keywords, }: Content) => ContentTargeting;
77
86
  export { getContentTargeting };
78
87
  export type { ContentTargeting };
@@ -28,6 +28,9 @@ const getUrlKeywords = (url) => {
28
28
  .slice(-1)[0];
29
29
  return (0, libs_1.isString)(lastSegment) ? lastSegment.split('-').filter(Boolean) : [];
30
30
  };
31
+ const concatUnique = (a, b) => [
32
+ ...new Set([...a, ...b]),
33
+ ];
31
34
  // "0" means content < 2 hours old
32
35
  // "1" means content between 2 hours and 24 hours old.
33
36
  // "2" means content between 24 hours and 3 days old
@@ -57,15 +60,17 @@ const calculateRecentlyPublishedBucket = (webPublicationDate) => {
57
60
  return '6';
58
61
  return '7';
59
62
  };
60
- const getContentTargeting = ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, webPublicationDate, }) => {
63
+ const getContentTargeting = ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, webPublicationDate, keywords, }) => {
64
+ const urlkw = getUrlKeywords(path);
61
65
  return {
62
66
  dcre: eligibleForDCR ? 't' : 'f',
63
67
  rc: calculateRecentlyPublishedBucket(webPublicationDate),
64
68
  rp: renderingPlatform,
65
69
  s: section,
66
70
  sens: sensitive ? 't' : 'f',
67
- urlkw: getUrlKeywords(path),
71
+ urlkw,
68
72
  vl: videoLength ? getVideoLength(videoLength) : null,
73
+ allkw: concatUnique(urlkw, keywords),
69
74
  };
70
75
  };
71
76
  exports.getContentTargeting = getContentTargeting;
@@ -1,5 +1,5 @@
1
1
  import type { SizeMapping } from './ad-sizes';
2
- type SlotName = 'carrot' | 'comments-expanded' | 'comments' | 'epic' | 'high-merch-lucky' | 'high-merch-paid' | 'high-merch' | 'im' | 'inline' | 'mobile-sticky' | 'mostpop' | 'top-above-nav';
2
+ type SlotName = 'carrot' | 'comments-expanded' | 'comments' | 'epic' | 'exclusion' | 'high-merch-lucky' | 'high-merch-paid' | 'high-merch' | 'im' | 'inline' | 'mobile-sticky' | 'mostpop' | 'top-above-nav';
3
3
  type CreateSlotOptions = {
4
4
  classes?: string;
5
5
  name?: string;
@@ -33,6 +33,7 @@ type PageTargeting = PartialWithNulls<{
33
33
  skinsize: 'l' | 's';
34
34
  urlkw: string[];
35
35
  vl: string;
36
+ allkw: string[];
36
37
  [_: string]: string | string[];
37
38
  } & SharedTargeting>;
38
39
  declare const filterValues: (pageTargets: Record<string, unknown>) => Record<string, string | string[]>;
@@ -24,6 +24,9 @@ const filterValues = (pageTargets) => {
24
24
  const buildPageTargeting = ({ adFree, clientSideParticipations, consentState, youtube = false, }) => {
25
25
  const { page, isDotcomRendering } = window.guardian.config;
26
26
  const adFreeTargeting = adFree ? { af: 't' } : {};
27
+ const sharedAdTargeting = page.sharedAdTargeting
28
+ ? getSharedTargeting(page.sharedAdTargeting)
29
+ : {};
27
30
  const contentTargeting = getContentTargeting({
28
31
  webPublicationDate: page.webPublicationDate,
29
32
  eligibleForDCR: page.dcrCouldRender,
@@ -34,6 +37,7 @@ const buildPageTargeting = ({ adFree, clientSideParticipations, consentState, yo
34
37
  section: page.section,
35
38
  sensitive: page.isSensitive,
36
39
  videoLength: page.videoDuration,
40
+ keywords: sharedAdTargeting.k ?? [],
37
41
  });
38
42
  const getReferrer = () => document.referrer || '';
39
43
  const sessionTargeting = getSessionTargeting({
@@ -57,9 +61,6 @@ const buildPageTargeting = ({ adFree, clientSideParticipations, consentState, yo
57
61
  viewPortWidth: getViewport().width,
58
62
  cmpBannerWillShow: !cmp.hasInitialised() || cmp.willShowPrivacyMessageSync(),
59
63
  });
60
- const sharedAdTargeting = page.sharedAdTargeting
61
- ? getSharedTargeting(page.sharedAdTargeting)
62
- : {};
63
64
  const personalisedTargeting = getPersonalisedTargeting({
64
65
  state: consentState,
65
66
  youtube,
@@ -63,6 +63,14 @@ type ContentTargeting = {
63
63
  * [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=195087
64
64
  */
65
65
  vl: null | (typeof videoLengths)[number];
66
+ /**
67
+ * **All** **K**ey**w**ords - [see on Ad Manager][gam]
68
+ * This is a list of all keywords on the page, including the section and the URL keywords
69
+ * Type: _Dynamic_
70
+ *
71
+ * [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=13995840
72
+ */
73
+ allkw: string[];
66
74
  };
67
75
  type Content = {
68
76
  eligibleForDCR: boolean;
@@ -72,7 +80,8 @@ type Content = {
72
80
  sensitive: boolean;
73
81
  videoLength?: number;
74
82
  webPublicationDate: number;
83
+ keywords: string[];
75
84
  };
76
- declare const getContentTargeting: ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, webPublicationDate, }: Content) => ContentTargeting;
85
+ declare const getContentTargeting: ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, webPublicationDate, keywords, }: Content) => ContentTargeting;
77
86
  export { getContentTargeting };
78
87
  export type { ContentTargeting };
@@ -25,6 +25,9 @@ const getUrlKeywords = (url) => {
25
25
  .slice(-1)[0];
26
26
  return isString(lastSegment) ? lastSegment.split('-').filter(Boolean) : [];
27
27
  };
28
+ const concatUnique = (a, b) => [
29
+ ...new Set([...a, ...b]),
30
+ ];
28
31
  // "0" means content < 2 hours old
29
32
  // "1" means content between 2 hours and 24 hours old.
30
33
  // "2" means content between 24 hours and 3 days old
@@ -54,15 +57,17 @@ const calculateRecentlyPublishedBucket = (webPublicationDate) => {
54
57
  return '6';
55
58
  return '7';
56
59
  };
57
- const getContentTargeting = ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, webPublicationDate, }) => {
60
+ const getContentTargeting = ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, webPublicationDate, keywords, }) => {
61
+ const urlkw = getUrlKeywords(path);
58
62
  return {
59
63
  dcre: eligibleForDCR ? 't' : 'f',
60
64
  rc: calculateRecentlyPublishedBucket(webPublicationDate),
61
65
  rp: renderingPlatform,
62
66
  s: section,
63
67
  sens: sensitive ? 't' : 'f',
64
- urlkw: getUrlKeywords(path),
68
+ urlkw,
65
69
  vl: videoLength ? getVideoLength(videoLength) : null,
70
+ allkw: concatUnique(urlkw, keywords),
66
71
  };
67
72
  };
68
73
  export { getContentTargeting };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guardian/commercial-core",
3
- "version": "6.0.0",
3
+ "version": "6.2.0",
4
4
  "description": "Guardian advertising business logic",
5
5
  "homepage": "https://github.com/guardian/commercial-core#readme",
6
6
  "bugs": {