@mhubcloud/tms_core 3.5.0 → 3.6.0-beta.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/LICENSE +202 -202
- package/dist/index.js +15 -9
- package/package.json +46 -46
- package/.eslintignore +0 -3
- package/.eslintrc.cjs +0 -87
- package/.prettierignore +0 -3
- package/.prettierrc +0 -10
- package/.vscode/extensions.json +0 -12
- package/.vscode/settings.json +0 -51
- package/index.js +0 -17
- package/releasePlan.md +0 -2
- package/src/broker.ts +0 -182
- package/src/defaultPublisher.ts +0 -144
- package/src/index.ts +0 -30
- package/src/publishers/affiliatePort.ts +0 -69
- package/src/publishers/cj.ts +0 -70
- package/src/publishers/facebook.ts +0 -93
- package/src/publishers/googleAds.ts +0 -193
- package/src/publishers/googleAnalytics4.ts +0 -60
- package/src/publishers/piano.ts +0 -71
- package/src/publishers/universalAnalytics.ts +0 -63
- package/src/types/EventPublisher.ts +0 -13
- package/src/types/EventToLog.ts +0 -5
- package/src/types/PlatformPublisher.ts +0 -20
- package/src/types/ServiceBusMessage.ts +0 -10
- package/src/types/UtilTypes.ts +0 -1
- package/src/types/global.d.ts +0 -3
- package/src/utils/testUtils.ts +0 -18
- package/src/utils/utils.ts +0 -423
- package/tests/AffiliatePort.js +0 -133
- package/tests/CJ.js +0 -161
- package/tests/Facebook.js +0 -128
- package/tests/GoogleAds.js +0 -130
- package/tests/GoogleAnalytics4.js +0 -99
- package/tests/Piano.js +0 -120
- package/tests/UniversalAnalytics.js +0 -107
- package/tsconfig.eslint.json +0 -43
- package/tsconfig.json +0 -26
package/tests/Facebook.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
const localSettings = require('../local.settings.json').Values;
|
|
2
|
-
process.env = { ...process.env, ...localSettings };
|
|
3
|
-
const publisher = require('../dist/index.js').publisher.Facebook;
|
|
4
|
-
const defaultPublisher = require('../dist/index.js').DefaultPublisher;
|
|
5
|
-
const utils = require('../dist/index.js').utils;
|
|
6
|
-
const testUtils = require('../dist/index.js').testUtils;
|
|
7
|
-
|
|
8
|
-
describe('test Facebook publisher', function () {
|
|
9
|
-
it('purchase', async function () {
|
|
10
|
-
var serviceBusMessage = {
|
|
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: Date.now(),
|
|
46
|
-
ads: [],
|
|
47
|
-
};
|
|
48
|
-
await test(serviceBusMessage);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Test function
|
|
54
|
-
* @param [object] object obsahující nastavení testovací parametry
|
|
55
|
-
*/
|
|
56
|
-
async function test(serviceBusMessage) {
|
|
57
|
-
await defaultPublisher(
|
|
58
|
-
testUtils.context,
|
|
59
|
-
serviceBusMessage,
|
|
60
|
-
'Facebook',
|
|
61
|
-
publisher,
|
|
62
|
-
trigger,
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
67
|
-
async function trigger(data) {
|
|
68
|
-
const publishers = [];
|
|
69
|
-
let publisher;
|
|
70
|
-
|
|
71
|
-
// Dummy config, replace with your own
|
|
72
|
-
const config = {
|
|
73
|
-
id: process.env.Publisher_Facebook_PixelId,
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
75
|
-
access_token: process.env.Publisher_Facebook_AccessToken,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
switch (data.event?.code) {
|
|
79
|
-
case 'purchase':
|
|
80
|
-
publisher = new FBPurchasePublisher(config);
|
|
81
|
-
publishers.push(publisher);
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
return publishers;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
class FBPurchasePublisher extends utils.EventPublisherBase {
|
|
88
|
-
/**
|
|
89
|
-
* Maps `purchase` event data to Facebook payload
|
|
90
|
-
* @param {Object} data `purchase` event data
|
|
91
|
-
* @returns {Object} Data mapped from incoming Service Bus message to platform payload
|
|
92
|
-
*/
|
|
93
|
-
map(data) {
|
|
94
|
-
return {
|
|
95
|
-
event_name: 'Purchase', // Constant
|
|
96
|
-
event_time: Math.floor(data.enqueuedAt / 1000), // convert to seconds
|
|
97
|
-
action_source: 'website', // Constant
|
|
98
|
-
event_id: data.id, // e.g. OBJ1248035
|
|
99
|
-
event_source_url: data.location, // e.g. https://eshop.com/checkoutSuccess
|
|
100
|
-
opt_out: false, // Constant
|
|
101
|
-
user_data: {
|
|
102
|
-
client_user_agent: data.session?.userAgent, // e.g. Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit
|
|
103
|
-
fbc:
|
|
104
|
-
utils.extractAdCode(
|
|
105
|
-
data,
|
|
106
|
-
'facebook',
|
|
107
|
-
'fbclid',
|
|
108
|
-
(ad) => `fb.1.${ad.visitAt}.${ad.code}`,
|
|
109
|
-
) || undefined, // e.g. fb.1.1623142020900.IwAR3CoXSdAr4nXyoVGo5H72wAiP8BrgPays0hhH1UgxnW_8D7rDhuHgjvvw0_aem_AXjjss7KoC0VSnBGvyUAkPip4VaZV6qytiIx5s8FQrAy5yzamZNRSC_xaCXEeJ8ecyphjuyQ2zbDAMoaIVayYAHxZgFH8TJsMzysJAIikY0How
|
|
110
|
-
fbp: data.identity?.facebook?.id, // e.g. fb.1.1609144040877.1929163682
|
|
111
|
-
client_ip_address: data.session?.ip, // e.g. 31.30.171.18
|
|
112
|
-
em: utils.encodeEmail(data.user?.email),
|
|
113
|
-
},
|
|
114
|
-
custom_data: {
|
|
115
|
-
currency: data.currencyCode, // e.g. EUR
|
|
116
|
-
value: data.revenue, // e.g. 142.52
|
|
117
|
-
contents: data.products.map((pr) => ({
|
|
118
|
-
id: pr.id, // e.g. PRDCT1248035
|
|
119
|
-
quantity: pr.quantity, // e.g. 1
|
|
120
|
-
item_price: pr.price, // e.g. 109
|
|
121
|
-
})),
|
|
122
|
-
content_type: 'product', // Constant
|
|
123
|
-
order_id: data.id, // e.g. OBJ1248035
|
|
124
|
-
content_category: 'Purchase', // Constant
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
}
|
package/tests/GoogleAds.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
const localSettings = require('../local.settings.json').Values;
|
|
2
|
-
process.env = { ...process.env, ...localSettings };
|
|
3
|
-
const publisher = require('../dist/index.js').publisher.GoogleAds;
|
|
4
|
-
const defaultPublisher = require('../dist/index.js').DefaultPublisher;
|
|
5
|
-
const utils = require('../dist/index.js').utils;
|
|
6
|
-
const testUtils = require('../dist/index.js').testUtils;
|
|
7
|
-
|
|
8
|
-
describe('test GoogleAds publisher', function () {
|
|
9
|
-
it('purchase', async function () {
|
|
10
|
-
const serviceBusMessage = {
|
|
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
|
-
adPlatform: 'googleads',
|
|
49
|
-
adCodes: {
|
|
50
|
-
gclid: 'mhubcloud',
|
|
51
|
-
gcl_src: 'aw.ds',
|
|
52
|
-
},
|
|
53
|
-
visitAt: 1727173492000,
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
};
|
|
57
|
-
await test(serviceBusMessage);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Test function
|
|
63
|
-
* @param [object] object obsahující nastavení testovací parametry
|
|
64
|
-
*/
|
|
65
|
-
async function test(serviceBusMessage) {
|
|
66
|
-
await defaultPublisher(
|
|
67
|
-
testUtils.context,
|
|
68
|
-
serviceBusMessage,
|
|
69
|
-
'GoogleAds',
|
|
70
|
-
publisher,
|
|
71
|
-
trigger,
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
76
|
-
async function trigger(data) {
|
|
77
|
-
const publishers = [];
|
|
78
|
-
let publisher;
|
|
79
|
-
|
|
80
|
-
// Dummy config, replace with your own
|
|
81
|
-
const config = {
|
|
82
|
-
client: {
|
|
83
|
-
id: process.env.Publisher_GoogleAds_ClientID,
|
|
84
|
-
secret: process.env.Publisher_GoogleAds_ClientSecret,
|
|
85
|
-
developerToken: process.env.Publisher_GoogleAds_DeveloperToken,
|
|
86
|
-
},
|
|
87
|
-
refreshToken:
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
89
|
-
process.env.Publisher_GoogleAds_RefreshToken,
|
|
90
|
-
customerId:
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
92
|
-
process.env.Publisher_GoogleAds_CustomerID,
|
|
93
|
-
conversionId: process.env.Publisher_GoogleAds_ConversionID_purchase,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
switch (data.event?.code) {
|
|
97
|
-
case 'purchase':
|
|
98
|
-
publisher = new GoogleAdsPurchasePublisher(config);
|
|
99
|
-
publishers.push(publisher);
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return publishers;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
class GoogleAdsPurchasePublisher extends utils.EventPublisherBase {
|
|
107
|
-
/**
|
|
108
|
-
* Maps `purchase` event data to GoogleAds payload
|
|
109
|
-
* @param {Object} data `purchase` event data
|
|
110
|
-
* @returns {Object} Data mapped from incoming Service Bus message to platform payload
|
|
111
|
-
*/
|
|
112
|
-
map(data) {
|
|
113
|
-
const dateTime = new Date(data.enqueuedAt);
|
|
114
|
-
const dateString =
|
|
115
|
-
dateTime.toISOString().replace('T', ' ').split('.')[0] + '+00:00';
|
|
116
|
-
const gclid = utils.extractAdCode(data, 'googleads', 'gclid')?.code;
|
|
117
|
-
const wbraid = utils.extractAdCode(data, 'googleads', 'wbraid')?.code;
|
|
118
|
-
const gbraid = utils.extractAdCode(data, 'googleads', 'gbraid')?.code;
|
|
119
|
-
|
|
120
|
-
return {
|
|
121
|
-
gclid: gclid,
|
|
122
|
-
wbraid: gclid || gbraid ? undefined : wbraid,
|
|
123
|
-
gbraid: gclid || wbraid ? undefined : gbraid,
|
|
124
|
-
orderId: data.event.id,
|
|
125
|
-
conversionDateTime: dateString,
|
|
126
|
-
currencyCode: data.currencyCode, // e.g. EUR
|
|
127
|
-
conversionValue: data.value ? data.value : 0.01, // e.g. 142.52
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
const localSettings = require('../local.settings.json').Values;
|
|
2
|
-
process.env = { ...process.env, ...localSettings };
|
|
3
|
-
const publisher = require('../dist/index.js').publisher.GoogleAnalytics4;
|
|
4
|
-
const defaultPublisher = require('../dist/index.js').DefaultPublisher;
|
|
5
|
-
const utils = require('../dist/index.js').utils;
|
|
6
|
-
const testUtils = require('../dist/index.js').testUtils;
|
|
7
|
-
|
|
8
|
-
describe('test GoogleAnalytics4 publisher', function () {
|
|
9
|
-
it('purchase', async function () {
|
|
10
|
-
var serviceBusMessage = {
|
|
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/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
|
-
await test(serviceBusMessage);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Test function
|
|
54
|
-
* @param [object] object obsahující nastavení testovací parametry
|
|
55
|
-
*/
|
|
56
|
-
async function test(serviceBusMessage) {
|
|
57
|
-
await defaultPublisher(
|
|
58
|
-
testUtils.context,
|
|
59
|
-
serviceBusMessage,
|
|
60
|
-
'GoogleAnalytics4',
|
|
61
|
-
publisher,
|
|
62
|
-
trigger,
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
67
|
-
async function trigger(data) {
|
|
68
|
-
const publishers = [];
|
|
69
|
-
const config = { trackingId: 'G-289495622' };
|
|
70
|
-
|
|
71
|
-
if (data.event?.code === 'pageview') {
|
|
72
|
-
const publisher = GAPageviewPublisher;
|
|
73
|
-
publisher.register(publishers, config);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return publishers;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
class GAPageviewPublisher extends utils.EventPublisherBase {
|
|
80
|
-
/**
|
|
81
|
-
* Maps `pageview` event data to GA payload
|
|
82
|
-
*/
|
|
83
|
-
map(data) {
|
|
84
|
-
return {
|
|
85
|
-
// mandatory for all events
|
|
86
|
-
cid: '456', // client id
|
|
87
|
-
en: 'eventMhubCloud', // event name
|
|
88
|
-
|
|
89
|
-
// mandatory for pageview
|
|
90
|
-
dl: '/', // URL
|
|
91
|
-
|
|
92
|
-
// optional
|
|
93
|
-
// ul : "en-us",
|
|
94
|
-
// sr: "1536x864", //screan resolution
|
|
95
|
-
// dr: "ccc", //refferer
|
|
96
|
-
// dt: "xx" //page title
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|
package/tests/Piano.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
const localSettings = require('../local.settings.json').Values;
|
|
2
|
-
process.env = { ...process.env, ...localSettings };
|
|
3
|
-
const publisher = require('../dist/index.js').publisher.Piano;
|
|
4
|
-
const defaultPublisher = require('../dist/index.js').DefaultPublisher;
|
|
5
|
-
const utils = require('../dist/index.js').utils;
|
|
6
|
-
const testUtils = require('../dist/index.js').testUtils;
|
|
7
|
-
|
|
8
|
-
describe('test Piano publisher', function () {
|
|
9
|
-
it('purchase', async function () {
|
|
10
|
-
var serviceBusMessage = {
|
|
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
|
-
await test(serviceBusMessage);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Test function
|
|
54
|
-
* @param [object] object obsahující nastavení testovací parametry
|
|
55
|
-
*/
|
|
56
|
-
async function test(serviceBusMessage) {
|
|
57
|
-
await defaultPublisher(
|
|
58
|
-
testUtils.context,
|
|
59
|
-
serviceBusMessage,
|
|
60
|
-
'Piano',
|
|
61
|
-
publisher,
|
|
62
|
-
trigger,
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
67
|
-
async function trigger(data) {
|
|
68
|
-
const publishers = [];
|
|
69
|
-
const config = {
|
|
70
|
-
collectionDomain: 'xxxxx.xiti.com', // Secured collection domain
|
|
71
|
-
siteId: '12345', // site-id
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
if (data.event.code === 'purchase') {
|
|
75
|
-
const publisher = PianoPurchasePublisher;
|
|
76
|
-
publisher.register(publishers, config);
|
|
77
|
-
}
|
|
78
|
-
return publishers;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
class PianoPurchasePublisher extends utils.EventPublisherBase {
|
|
82
|
-
/**
|
|
83
|
-
* Converts input data to publishing payload data understood by the publisher
|
|
84
|
-
* @param {Object} data `purchase` event data
|
|
85
|
-
* @returns {Object} Data mapped from incoming Service Bus message to platform payload
|
|
86
|
-
*/
|
|
87
|
-
map(data) {
|
|
88
|
-
return {
|
|
89
|
-
pianoData: {
|
|
90
|
-
// This willbe sent to Piano as payload
|
|
91
|
-
events: [
|
|
92
|
-
{
|
|
93
|
-
name: 'purchase',
|
|
94
|
-
data: {
|
|
95
|
-
event_collection_platform: 'api',
|
|
96
|
-
event_collection_version: 2,
|
|
97
|
-
event_time_ts: Math.floor(data.enqueuedAt / 1000), // convert to seconds
|
|
98
|
-
event_id: data.id,
|
|
99
|
-
event_source_url: data.location,
|
|
100
|
-
// https://developers.atinternet-solutions.com/piano-analytics-tagging-en/event-tagging-piano-analytics-en/events-pattern-en/#common-contextual-properties_9
|
|
101
|
-
// Any properties can go here (name must be [a-z][a-z_0-9]+; prohibited names m_…, visit_…, events)
|
|
102
|
-
// There are some specifically understood properties
|
|
103
|
-
// 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
|
|
104
|
-
// or by suffix '_date', '_utc', '_ts' date in RFC 3339 format (YYYY-MM-DDTHH:mm:ssZ); '_timestamp' - timestamp in seconds
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
},
|
|
109
|
-
aux: {
|
|
110
|
-
// Additional data understood by Piano publisher and passed specificaly (in headers and query string)
|
|
111
|
-
visitorId: data.identity?.piano?.id, // Mandatory idclient=<visitor-id>
|
|
112
|
-
ref: data.referrer, // Mandatory ref=<previous-url>
|
|
113
|
-
// Optional:
|
|
114
|
-
userAgent: data.session?.userAgent,
|
|
115
|
-
referer: data.session?.referrer,
|
|
116
|
-
forwardedFor: data.session?.ip,
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
const localSettings = require('../local.settings.json').Values;
|
|
2
|
-
process.env = { ...process.env, ...localSettings };
|
|
3
|
-
const publisher = require('../dist/index.js').publisher.UniversalAnalytics;
|
|
4
|
-
const defaultPublisher = require('../dist/index.js').DefaultPublisher;
|
|
5
|
-
const utils = require('../dist/index.js').utils;
|
|
6
|
-
const testUtils = require('../dist/index.js').testUtils;
|
|
7
|
-
|
|
8
|
-
describe('test UniversalAnalytics publisher', function () {
|
|
9
|
-
it('pageview', async function () {
|
|
10
|
-
var serviceBusMessage = {
|
|
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
|
-
await test(serviceBusMessage);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Test function
|
|
45
|
-
* @param [object] object obsahující nastavení testovací parametry
|
|
46
|
-
*/
|
|
47
|
-
async function test(serviceBusMessage) {
|
|
48
|
-
await defaultPublisher(
|
|
49
|
-
testUtils.context,
|
|
50
|
-
serviceBusMessage,
|
|
51
|
-
'UniversalAnalytics',
|
|
52
|
-
publisher,
|
|
53
|
-
trigger,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
58
|
-
async function trigger(data) {
|
|
59
|
-
const publishers = [];
|
|
60
|
-
const config = { trackingId: 'UA-xxxxxxx-yy' };
|
|
61
|
-
|
|
62
|
-
if (data.event?.code === 'pageview') {
|
|
63
|
-
const publisher = GAPageviewPublisher;
|
|
64
|
-
publisher.register(publishers, config);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return publishers;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
class GAPageviewPublisher extends utils.EventPublisherBase {
|
|
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
|
|
93
|
-
|
|
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
|
-
}
|
package/tsconfig.eslint.json
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.eslint.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"lib": [
|
|
5
|
-
"es2021", "es2022.error"
|
|
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
|
-
}
|