@mhubcloud/tms_core 1.7.6 → 2.0.0-beta.1
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/.eslintignore +3 -0
- package/.eslintrc.cjs +87 -0
- package/.prettierignore +3 -0
- package/.prettierrc +10 -0
- package/.vscode/extensions.json +12 -0
- package/.vscode/settings.json +52 -0
- package/dist/index.js +609 -0
- package/index.js +1 -0
- package/{lib → js/lib}/defaultPublisher.js +26 -24
- package/js/lib/utils.js +349 -0
- package/js/publishers/AffiliatePort.js +78 -0
- package/{publishers → js/publishers}/CJ.js +7 -5
- package/{publishers → js/publishers}/Facebook.js +6 -4
- package/{publishers → js/publishers}/GoogleAnalytics4.js +8 -6
- package/js/publishers/HttpPublisher.js +64 -0
- package/{publishers → js/publishers}/Piano.js +6 -4
- package/{publishers → js/publishers}/UniversalAnalytics.js +7 -5
- package/package.json +46 -29
- package/releasePlan.md +3 -0
- package/src/defaultPublisher.ts +132 -0
- package/src/index.ts +25 -0
- package/src/publishers/affiliatePort.ts +69 -0
- package/src/publishers/cj.ts +67 -0
- package/src/publishers/facebook.ts +49 -0
- package/src/publishers/googleAnalytics4.ts +60 -0
- package/src/publishers/piano.ts +71 -0
- package/src/publishers/universalAnalytics.ts +63 -0
- package/src/types/EventHubMessage.ts +8 -0
- package/src/types/EventPublisher.ts +9 -0
- package/src/types/PlatformPublisher.ts +19 -0
- package/src/types/UtilTypes.ts +1 -0
- package/src/types/global.d.ts +3 -0
- package/src/utils/utils.ts +358 -0
- package/tests/AffiliatePort.js +107 -85
- package/tests/CJ.js +144 -119
- package/tests/Facebook.js +124 -103
- package/tests/GoogleAnalytics4.js +82 -74
- package/tests/Piano.js +112 -99
- package/tests/UniversalAnalytics.js +90 -77
- package/tests/testUtils.js +7 -0
- package/tsconfig.eslint.json +43 -0
- package/tsconfig.json +26 -0
- package/lib/utils.js +0 -307
- package/publishers/AffiliatePort.js +0 -61
package/tests/Piano.js
CHANGED
|
@@ -1,114 +1,127 @@
|
|
|
1
|
-
const publisher = require(
|
|
2
|
-
const defaultPublisher = require(
|
|
3
|
-
const utils = require(
|
|
1
|
+
const publisher = require('../dist/index.js').publisher.Piano;
|
|
2
|
+
const defaultPublisher = require('../dist/index.js').DefaultPublisher;
|
|
3
|
+
const utils = require('../dist/index.js').utils;
|
|
4
4
|
var assert = require('assert');
|
|
5
|
+
const testUtils = require('./testUtils');
|
|
5
6
|
|
|
6
7
|
describe('test Piano publisher', function () {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
})
|
|
8
|
+
it('purchase', async function () {
|
|
9
|
+
var eventHubMessages = [
|
|
10
|
+
{
|
|
11
|
+
currencyCode: 'CZK',
|
|
12
|
+
event: {
|
|
13
|
+
region: 'MAIN',
|
|
14
|
+
id: '115169112-4870.1657003407533',
|
|
15
|
+
code: 'purchase',
|
|
16
|
+
},
|
|
17
|
+
session: {
|
|
18
|
+
userAgent:
|
|
19
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
|
|
20
|
+
ip: '89.177.126.237',
|
|
21
|
+
referrer: 'https://crossmasters.com/',
|
|
22
|
+
},
|
|
23
|
+
referrer: 'https://crossmasters.com/',
|
|
24
|
+
permissions: [],
|
|
25
|
+
identity: {
|
|
26
|
+
piano: {
|
|
27
|
+
id: '1657003393413.319297501',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
publisher: {
|
|
31
|
+
code: 'mhubcloud.com',
|
|
32
|
+
tm: 'GTM-N7K9L4X',
|
|
33
|
+
tmv: '494',
|
|
34
|
+
},
|
|
35
|
+
$schema: '/mhub/purchase',
|
|
36
|
+
id: '20162351',
|
|
37
|
+
revenue: 440,
|
|
38
|
+
products: [
|
|
39
|
+
{
|
|
40
|
+
id: 'Car',
|
|
41
|
+
price: 440,
|
|
42
|
+
quantity: 1,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
enqueuedAt: 1657003409370,
|
|
46
|
+
ads: [],
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
await test(eventHubMessages);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
50
52
|
|
|
51
53
|
/**
|
|
52
54
|
* Test function
|
|
53
55
|
* @param [object] object obsahující nastavení testovací parametry
|
|
54
56
|
*/
|
|
55
57
|
async function test(eventHubMessages) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
try {
|
|
59
|
+
await defaultPublisher(
|
|
60
|
+
testUtils.context,
|
|
61
|
+
eventHubMessages,
|
|
62
|
+
'Piano',
|
|
63
|
+
publisher,
|
|
64
|
+
trigger,
|
|
65
|
+
);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
assert.equal(
|
|
68
|
+
err.toString(),
|
|
69
|
+
'FetchError: request to https://xxxxx.xiti.com/?s=12345&idclient=1657003393413.319297501&ref=https://crossmasters.com/ failed, reason: getaddrinfo ENOTFOUND xxxxx.xiti.com',
|
|
70
|
+
);
|
|
71
|
+
}
|
|
61
72
|
}
|
|
62
73
|
|
|
63
74
|
function trigger(data) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
75
|
+
const publishers = [];
|
|
76
|
+
const config = {
|
|
77
|
+
collectionDomain: 'xxxxx.xiti.com', // Secured collection domain
|
|
78
|
+
siteId: '12345', // site-id
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
if (data.event.code === 'purchase') {
|
|
82
|
+
const publisher = PianoPurchasePublisher;
|
|
83
|
+
publisher.register(publishers, config);
|
|
84
|
+
}
|
|
85
|
+
return publishers;
|
|
86
|
+
}
|
|
76
87
|
|
|
77
88
|
class PianoPurchasePublisher extends utils.EventPublisherBase {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
]
|
|
89
|
+
/**
|
|
90
|
+
* Converts input data to publishing payload data understood by the publisher
|
|
91
|
+
* @param {Object} data `purchase` event data
|
|
92
|
+
* @returns {Object} Data mapped from incomming Event Hub message to platform payload
|
|
93
|
+
*/
|
|
94
|
+
map(data) {
|
|
95
|
+
return {
|
|
96
|
+
pianoData: {
|
|
97
|
+
// This willbe sent to Piano as payload
|
|
98
|
+
events: [
|
|
99
|
+
{
|
|
100
|
+
name: 'purchase',
|
|
101
|
+
data: {
|
|
102
|
+
event_collection_platform: 'api',
|
|
103
|
+
event_collection_version: 2,
|
|
104
|
+
event_time_ts: Math.floor(data.enqueuedAt / 1000), // convert to seconds
|
|
105
|
+
event_id: data.id,
|
|
106
|
+
event_source_url: data.location,
|
|
107
|
+
// https://developers.atinternet-solutions.com/piano-analytics-tagging-en/event-tagging-piano-analytics-en/events-pattern-en/#common-contextual-properties_9
|
|
108
|
+
// Any properties can go here (name must be [a-z][a-z_0-9]+; prohibited names m_…, visit_…, events)
|
|
109
|
+
// There are some specifically understood properties
|
|
110
|
+
// Type of property if not obvious from JSON can be forcec by prefix: 's:' string, 'n:' integer, 'f:' float, 'd:' date, 'b:' boolean, 'a:s:' array of strings, 'a:n:' array of integers, 'a:f:' array of floats
|
|
111
|
+
// or by suffix '_date', '_utc', '_ts' date in RFC 3339 format (YYYY-MM-DDTHH:mm:ssZ); '_timestamp' - timestamp in seconds
|
|
103
112
|
},
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
aux: {
|
|
117
|
+
// Additional data understood by Piano publisher and passed specificaly (in headers and query string)
|
|
118
|
+
visitorId: data.identity?.piano?.id, // Mandatory idclient=<visitor-id>
|
|
119
|
+
ref: data.referrer, // Mandatory ref=<previous-url>
|
|
120
|
+
// Optional:
|
|
121
|
+
userAgent: data.session?.userAgent,
|
|
122
|
+
referer: data.session?.referrer,
|
|
123
|
+
forwardedFor: data.session?.ip,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -1,94 +1,107 @@
|
|
|
1
|
-
const publisher = require(
|
|
2
|
-
const defaultPublisher = require(
|
|
3
|
-
const utils = require(
|
|
1
|
+
const publisher = require('../dist/index.js').publisher.UniversalAnalytics;
|
|
2
|
+
const defaultPublisher = require('../dist/index.js').DefaultPublisher;
|
|
3
|
+
const utils = require('../dist/index.js').utils;
|
|
4
4
|
var assert = require('assert');
|
|
5
|
+
const testUtils = require('./testUtils');
|
|
5
6
|
|
|
6
7
|
describe('test UniversalAnalytics publisher', function () {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
})
|
|
8
|
+
it('pageview', async function () {
|
|
9
|
+
var eventHubMessages = [
|
|
10
|
+
{
|
|
11
|
+
currencyCode: 'CZK',
|
|
12
|
+
event: {
|
|
13
|
+
region: 'MAIN',
|
|
14
|
+
id: '115169112-4870.1657003407533',
|
|
15
|
+
code: 'pageview',
|
|
16
|
+
},
|
|
17
|
+
session: {
|
|
18
|
+
userAgent:
|
|
19
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
|
|
20
|
+
ip: '89.177.126.237',
|
|
21
|
+
referrer: 'https://crossmasters.com/',
|
|
22
|
+
},
|
|
23
|
+
referrer: 'https://crossmasters.com/',
|
|
24
|
+
permissions: [],
|
|
25
|
+
identity: {
|
|
26
|
+
piano: {
|
|
27
|
+
id: '1657003393413.319297501',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
publisher: {
|
|
31
|
+
code: 'mhubcloud.com',
|
|
32
|
+
tm: 'GTM-N7K9L4X',
|
|
33
|
+
tmv: '494',
|
|
34
|
+
},
|
|
35
|
+
$schema: '/mhub/pageview',
|
|
36
|
+
enqueuedAt: 1657003409370,
|
|
37
|
+
ads: [],
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
await test(eventHubMessages);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
41
43
|
|
|
42
44
|
/**
|
|
43
45
|
* Test function
|
|
44
46
|
* @param [object] object obsahující nastavení testovací parametry
|
|
45
47
|
*/
|
|
46
48
|
async function test(eventHubMessages) {
|
|
47
|
-
|
|
49
|
+
await defaultPublisher(
|
|
50
|
+
testUtils.context,
|
|
51
|
+
eventHubMessages,
|
|
52
|
+
'UniversalAnalytics',
|
|
53
|
+
publisher,
|
|
54
|
+
trigger,
|
|
55
|
+
);
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
function trigger(data) {
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
const publishers = [];
|
|
60
|
+
const config = { trackingId: 'UA-xxxxxxx-yy' };
|
|
53
61
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
if (data.event?.code === 'pageview') {
|
|
63
|
+
const publisher = GAPageviewPublisher;
|
|
64
|
+
publisher.register(publishers, config);
|
|
65
|
+
}
|
|
58
66
|
|
|
59
|
-
|
|
60
|
-
}
|
|
67
|
+
return publishers;
|
|
68
|
+
}
|
|
61
69
|
|
|
62
70
|
class GAPageviewPublisher extends utils.EventPublisherBase {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Maps `pageview` event data to GA payload
|
|
73
|
+
*/
|
|
74
|
+
map(data) {
|
|
75
|
+
/** @type {AdCodeInfo} */
|
|
76
|
+
let gclid = utils.extractAdCode(data, 'googleads', 'gclid');
|
|
77
|
+
/** @type {AdCodeInfo} */
|
|
78
|
+
let referrer = utils.extractAdCode(data, 'referrerPlatform', 'referrer');
|
|
79
|
+
/** @type {Ad} */
|
|
80
|
+
let utm = utils.extractAdCode(
|
|
81
|
+
data,
|
|
82
|
+
'googleAnalytics',
|
|
83
|
+
'utm_source',
|
|
84
|
+
(_, data) => (data.adCodes ? data : null),
|
|
85
|
+
); // Only supports new format
|
|
86
|
+
|
|
87
|
+
// https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#event
|
|
88
|
+
// https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dr
|
|
89
|
+
return {
|
|
90
|
+
// mandatory for all events
|
|
91
|
+
t: 'pageview',
|
|
92
|
+
cid: '456', // TODO
|
|
73
93
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
cm: utm?.adCodes?.utm_medium,
|
|
89
|
-
cc: utm?.adCodes?.utm_content,
|
|
90
|
-
gclid: gclid?.code,
|
|
91
|
-
dr: referrer?.code
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
};
|
|
94
|
+
// mandatory for pageview
|
|
95
|
+
dp: '/',
|
|
96
|
+
|
|
97
|
+
// Traffic Sources - optional
|
|
98
|
+
// TODO not tested
|
|
99
|
+
cn: utm?.adCodes?.utm_campaign,
|
|
100
|
+
cs: utm?.adCodes?.utm_source,
|
|
101
|
+
cm: utm?.adCodes?.utm_medium,
|
|
102
|
+
cc: utm?.adCodes?.utm_content,
|
|
103
|
+
gclid: gclid?.code,
|
|
104
|
+
dr: referrer?.code,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"display": "Default",
|
|
4
|
+
"extends": "@tsconfig/recommended/tsconfig.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"allowSyntheticDefaultImports": true,
|
|
8
|
+
"checkJs": false,
|
|
9
|
+
"composite": false,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"declarationDir": "./types",
|
|
12
|
+
"declarationMap": true,
|
|
13
|
+
"inlineSources": false,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"moduleResolution": "node",
|
|
16
|
+
"noEmit": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"noImplicitOverride": true,
|
|
19
|
+
"noImplicitReturns": true,
|
|
20
|
+
"noUncheckedIndexedAccess": true,
|
|
21
|
+
"noUnusedLocals": true,
|
|
22
|
+
"noUnusedParameters": true,
|
|
23
|
+
"preserveWatchOutput": true,
|
|
24
|
+
"removeComments": true,
|
|
25
|
+
"resolveJsonModule": true,
|
|
26
|
+
"sourceMap": true,
|
|
27
|
+
"strictNullChecks": true,
|
|
28
|
+
"useDefineForClassFields": true,
|
|
29
|
+
"useUnknownInCatchVariables": true,
|
|
30
|
+
"strict": true,
|
|
31
|
+
"outDir": "dist"
|
|
32
|
+
},
|
|
33
|
+
"include": [
|
|
34
|
+
".eslintrc.cjs",
|
|
35
|
+
"**/*"
|
|
36
|
+
// "build_scripts/post-build.mjs"
|
|
37
|
+
],
|
|
38
|
+
"exclude": [
|
|
39
|
+
"node_modules",
|
|
40
|
+
"build",
|
|
41
|
+
"dist"
|
|
42
|
+
]
|
|
43
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.eslint.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"lib": [
|
|
5
|
+
"es2021"
|
|
6
|
+
],
|
|
7
|
+
"module": "commonjs",
|
|
8
|
+
"target": "es2021",
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"experimentalDecorators": true,
|
|
11
|
+
"types": [
|
|
12
|
+
"node"
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"**/*.ts",
|
|
17
|
+
"tsconfig.eslint.json"
|
|
18
|
+
],
|
|
19
|
+
"exclude": [
|
|
20
|
+
"node_modules",
|
|
21
|
+
"build",
|
|
22
|
+
"dist",
|
|
23
|
+
"tests",
|
|
24
|
+
"js"
|
|
25
|
+
]
|
|
26
|
+
}
|