@guardian/commercial-core 0.27.0 → 0.31.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.
- package/dist/cjs/EventTimer.d.ts +2 -2
- package/dist/cjs/EventTimer.js +10 -7
- package/dist/cjs/ad-targeting-youtube.js +2 -2
- package/dist/cjs/targeting/content.d.ts +189 -0
- package/dist/cjs/targeting/content.js +90 -0
- package/dist/cjs/targeting/personalised.d.ts +78 -0
- package/dist/cjs/targeting/personalised.js +148 -0
- package/dist/cjs/targeting/session.d.ts +98 -0
- package/dist/cjs/targeting/session.js +57 -0
- package/dist/cjs/types.d.ts +5 -5
- package/dist/esm/EventTimer.d.ts +2 -2
- package/dist/esm/EventTimer.js +10 -7
- package/dist/esm/ad-targeting-youtube.js +1 -1
- package/dist/esm/targeting/content.d.ts +189 -0
- package/dist/esm/targeting/content.js +86 -0
- package/dist/esm/targeting/personalised.d.ts +78 -0
- package/dist/esm/targeting/personalised.js +145 -0
- package/dist/esm/targeting/session.d.ts +98 -0
- package/dist/esm/targeting/session.js +53 -0
- package/dist/esm/types.d.ts +5 -5
- package/package.json +23 -21
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Participations } from '@guardian/ab-core';
|
|
2
|
+
import type { CountryCode } from '@guardian/libs';
|
|
3
|
+
import type { False, True } from '../types';
|
|
4
|
+
declare const referrers: readonly [{
|
|
5
|
+
readonly id: "facebook";
|
|
6
|
+
readonly match: "facebook.com";
|
|
7
|
+
}, {
|
|
8
|
+
readonly id: "google";
|
|
9
|
+
readonly match: "www.google";
|
|
10
|
+
}, {
|
|
11
|
+
readonly id: "twitter";
|
|
12
|
+
readonly match: "/t.co/";
|
|
13
|
+
}, {
|
|
14
|
+
readonly id: "reddit";
|
|
15
|
+
readonly match: "reddit.com";
|
|
16
|
+
}];
|
|
17
|
+
/**
|
|
18
|
+
* Session Targeting is based on the browser session
|
|
19
|
+
*
|
|
20
|
+
* Includes information such as the country of origin, referrer, page view ID.
|
|
21
|
+
*
|
|
22
|
+
* These values identify a browser session are either generated client-side,
|
|
23
|
+
* read from a cookie or passed down from the server.
|
|
24
|
+
*/
|
|
25
|
+
export declare type SessionTargeting = {
|
|
26
|
+
/**
|
|
27
|
+
* **AB** Tests – [see on Ad Manager][gam]
|
|
28
|
+
*
|
|
29
|
+
* Type: _Dynamic_
|
|
30
|
+
*
|
|
31
|
+
* Values: typically start with `ab`
|
|
32
|
+
*
|
|
33
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=186327
|
|
34
|
+
*/
|
|
35
|
+
ab: string[] | null;
|
|
36
|
+
/**
|
|
37
|
+
* **A**d **T**est – [see on Ad Manager][gam]
|
|
38
|
+
*
|
|
39
|
+
* Used for testing purposes, based on query param and/or cookie.
|
|
40
|
+
*
|
|
41
|
+
* Type: _Dynamic_
|
|
42
|
+
*
|
|
43
|
+
* [See Current values](https://frontend.gutools.co.uk/commercial/adtests)
|
|
44
|
+
*
|
|
45
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=177567
|
|
46
|
+
*/
|
|
47
|
+
at: string | null;
|
|
48
|
+
/**
|
|
49
|
+
* **C**ountry **C**ode – [see on Ad Manager][gam]
|
|
50
|
+
*
|
|
51
|
+
* Type: _Dynamic_
|
|
52
|
+
*
|
|
53
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=11703293
|
|
54
|
+
*/
|
|
55
|
+
cc: CountryCode;
|
|
56
|
+
/**
|
|
57
|
+
* Ophan **P**age **V**iew id – [see on Ad Manager][gam]
|
|
58
|
+
*
|
|
59
|
+
* ID Generated client-side, usually available on
|
|
60
|
+
* `guardian.config.ophan.pageViewId`
|
|
61
|
+
*
|
|
62
|
+
* Used mainly for internal reporting
|
|
63
|
+
*
|
|
64
|
+
* Type: _Dynamic_
|
|
65
|
+
*
|
|
66
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=206127
|
|
67
|
+
*/
|
|
68
|
+
pv: string;
|
|
69
|
+
/**
|
|
70
|
+
* **Ref**errer – [see on Ad Manager][gam]
|
|
71
|
+
*
|
|
72
|
+
* Type: _Dynamic_
|
|
73
|
+
*
|
|
74
|
+
* Sample values:
|
|
75
|
+
* - `facebook`
|
|
76
|
+
* - `google`
|
|
77
|
+
* - `googleplus`
|
|
78
|
+
* - `reddit`
|
|
79
|
+
* - `twitter`
|
|
80
|
+
*
|
|
81
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=228567
|
|
82
|
+
*/
|
|
83
|
+
ref: typeof referrers[number]['id'] | null;
|
|
84
|
+
/**
|
|
85
|
+
* **S**igned **I**n – [see on Ad Manager][gam]
|
|
86
|
+
*
|
|
87
|
+
*Whether a user is signed in. Based on presence of a cookie.
|
|
88
|
+
*
|
|
89
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=215727
|
|
90
|
+
*/
|
|
91
|
+
si: True | False;
|
|
92
|
+
};
|
|
93
|
+
export declare type AllParticipations = {
|
|
94
|
+
clientSideParticipations: Participations;
|
|
95
|
+
serverSideParticipations: Record<string, 'control' | 'variant'>;
|
|
96
|
+
};
|
|
97
|
+
export declare const getSessionTargeting: (referrer: string, participations: AllParticipations, targeting: Omit<SessionTargeting, 'ab' | 'ref'>) => SessionTargeting;
|
|
98
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { isString } from '@guardian/libs';
|
|
2
|
+
/* -- Types -- */
|
|
3
|
+
const referrers = [
|
|
4
|
+
{
|
|
5
|
+
id: 'facebook',
|
|
6
|
+
match: 'facebook.com',
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
id: 'google',
|
|
10
|
+
match: 'www.google',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: 'twitter',
|
|
14
|
+
match: '/t.co/',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: 'reddit',
|
|
18
|
+
match: 'reddit.com',
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
/* -- Methods -- */
|
|
22
|
+
const getReferrer = (referrer) => {
|
|
23
|
+
if (referrer === '')
|
|
24
|
+
return null;
|
|
25
|
+
const matchedRef = referrers.find((referrerType) => referrer.includes(referrerType.match)) ?? null;
|
|
26
|
+
return matchedRef ? matchedRef.id : null;
|
|
27
|
+
};
|
|
28
|
+
const experimentsTargeting = ({ clientSideParticipations, serverSideParticipations, }) => {
|
|
29
|
+
const testToParams = (testName, variant) => {
|
|
30
|
+
if (variant === 'notintest')
|
|
31
|
+
return null;
|
|
32
|
+
// GAM key-value pairs accept value strings up to 40 characters long
|
|
33
|
+
return `${testName}-${variant}`.substring(0, 40);
|
|
34
|
+
};
|
|
35
|
+
const clientSideExperiment = Object.entries(clientSideParticipations)
|
|
36
|
+
.map((test) => {
|
|
37
|
+
const [name, variant] = test;
|
|
38
|
+
return testToParams(name, variant.variant);
|
|
39
|
+
})
|
|
40
|
+
.filter(isString);
|
|
41
|
+
const serverSideExperiments = Object.entries(serverSideParticipations)
|
|
42
|
+
.map((test) => testToParams(...test))
|
|
43
|
+
.filter(isString);
|
|
44
|
+
if (clientSideExperiment.length + serverSideExperiments.length === 0)
|
|
45
|
+
return null;
|
|
46
|
+
return [...clientSideExperiment, ...serverSideExperiments];
|
|
47
|
+
};
|
|
48
|
+
/* -- Targeting -- */
|
|
49
|
+
export const getSessionTargeting = (referrer, participations, targeting) => ({
|
|
50
|
+
ref: getReferrer(referrer),
|
|
51
|
+
ab: experimentsTargeting(participations),
|
|
52
|
+
...targeting,
|
|
53
|
+
});
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
export declare type
|
|
1
|
+
export declare type TagAttribute = {
|
|
2
2
|
name: string;
|
|
3
3
|
value: string;
|
|
4
4
|
};
|
|
5
|
-
export declare type GetThirdPartyTag = (arg0: {
|
|
6
|
-
shouldRun: boolean;
|
|
7
|
-
}) => ThirdPartyTag;
|
|
8
5
|
export declare type ThirdPartyTag = {
|
|
9
6
|
async?: boolean;
|
|
10
|
-
attrs?:
|
|
7
|
+
attrs?: TagAttribute[];
|
|
11
8
|
beforeLoad?: () => void;
|
|
12
9
|
insertSnippet?: () => void;
|
|
13
10
|
loaded?: boolean;
|
|
@@ -17,6 +14,9 @@ export declare type ThirdPartyTag = {
|
|
|
17
14
|
url?: string;
|
|
18
15
|
useImage?: boolean;
|
|
19
16
|
};
|
|
17
|
+
export declare type GetThirdPartyTag = (arg0: {
|
|
18
|
+
shouldRun: boolean;
|
|
19
|
+
}) => ThirdPartyTag;
|
|
20
20
|
export declare type GuardianAnalyticsConfig = {
|
|
21
21
|
trackers: Record<string, string>;
|
|
22
22
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guardian/commercial-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Guardian advertising business logic",
|
|
5
5
|
"homepage": "https://github.com/guardian/commercial-core#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -41,42 +41,44 @@
|
|
|
41
41
|
},
|
|
42
42
|
"prettier": "@guardian/prettier",
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@commitlint/cli": "^
|
|
45
|
-
"@commitlint/config-conventional": "^
|
|
46
|
-
"@guardian/
|
|
47
|
-
"@guardian/
|
|
48
|
-
"@guardian/
|
|
49
|
-
"@guardian/
|
|
50
|
-
"@
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
44
|
+
"@commitlint/cli": "^15.0.0",
|
|
45
|
+
"@commitlint/config-conventional": "^15.0.0",
|
|
46
|
+
"@guardian/ab-core": "^2.0.0",
|
|
47
|
+
"@guardian/consent-management-platform": "^8.0.1",
|
|
48
|
+
"@guardian/eslint-config-typescript": "^0.7.0",
|
|
49
|
+
"@guardian/libs": "3.5.1",
|
|
50
|
+
"@guardian/prettier": "^0.7.0",
|
|
51
|
+
"@octokit/core": "^3.5.1",
|
|
52
|
+
"@semantic-release/github": "^8.0.2",
|
|
53
53
|
"@types/google.analytics": "^0.0.42",
|
|
54
|
-
"@types/
|
|
55
|
-
"@
|
|
56
|
-
"@typescript-eslint/
|
|
54
|
+
"@types/googletag": "^1.1.4",
|
|
55
|
+
"@types/jest": "^27.0.3",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
57
|
+
"@typescript-eslint/parser": "^5.5.0",
|
|
57
58
|
"commitizen": "^4.2.4",
|
|
58
59
|
"cz-conventional-changelog": "^3.3.0",
|
|
59
|
-
"eslint": "^
|
|
60
|
+
"eslint": "^8.3.0",
|
|
60
61
|
"eslint-config-prettier": "^8.3.0",
|
|
61
62
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
62
|
-
"eslint-plugin-import": "^2.25.
|
|
63
|
-
"eslint-plugin-jest": "^25.
|
|
63
|
+
"eslint-plugin-import": "^2.25.3",
|
|
64
|
+
"eslint-plugin-jest": "^25.3.0",
|
|
64
65
|
"eslint-plugin-prettier": "^4.0.0",
|
|
65
66
|
"husky": "^7.0.4",
|
|
66
|
-
"jest": "^27.
|
|
67
|
-
"lint-staged": "^
|
|
67
|
+
"jest": "^27.4.1",
|
|
68
|
+
"lint-staged": "^12.1.2",
|
|
68
69
|
"mockdate": "^3.0.5",
|
|
69
70
|
"npm-run-all": "^4.1.5",
|
|
70
|
-
"prettier": "^2.
|
|
71
|
-
"semantic-release": "^18.0.
|
|
71
|
+
"prettier": "^2.5.0",
|
|
72
|
+
"semantic-release": "^18.0.1",
|
|
72
73
|
"ts-jest": "^27.0.7",
|
|
73
|
-
"typescript": "^4.
|
|
74
|
+
"typescript": "^4.5.2",
|
|
74
75
|
"web-vitals": "^2.1.2"
|
|
75
76
|
},
|
|
76
77
|
"publishConfig": {
|
|
77
78
|
"access": "public"
|
|
78
79
|
},
|
|
79
80
|
"peerDependencies": {
|
|
81
|
+
"@guardian/ab-core": "^2.0.0",
|
|
80
82
|
"@guardian/libs": "^3.3.0"
|
|
81
83
|
}
|
|
82
84
|
}
|