@mhubcloud/tms_core 3.5.1 → 3.6.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/tests/CJ.js DELETED
@@ -1,161 +0,0 @@
1
- const localSettings = require('../local.settings.json').Values;
2
- process.env = { ...process.env, ...localSettings };
3
- const publisher = require('../dist/index.js').publisher.CJ;
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 CJ 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
- adPlatform: 'cjaffiliate',
49
- adCodes: {
50
- cjevent: '816f5670dbf52c3dc27a7e849903c327d705ef643993fbab3',
51
- },
52
- visitAt: 1658392668000,
53
- },
54
- ],
55
- };
56
- var serviceBusMessage2 = {
57
- currencyCode: 'CZK',
58
- event: {
59
- region: 'MAIN',
60
- id: '115169112-4870.1657003407533',
61
- code: 'purchase',
62
- },
63
- session: {
64
- userAgent:
65
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
66
- ip: '89.177.126.237',
67
- referrer: 'https://crossmasters.com/',
68
- },
69
- referrer: 'https://crossmasters.com/',
70
- permissions: [],
71
- identity: {
72
- piano: {
73
- id: '1657003393413.319297501',
74
- },
75
- },
76
- publisher: {
77
- code: 'mhubcloud.com',
78
- tm: 'GTM-N7K9L4X',
79
- tmv: '494',
80
- },
81
- $schema: '/mhub/purchase',
82
- id: '20162351',
83
- revenue: 440,
84
- products: [
85
- {
86
- id: 'Car',
87
- price: 440,
88
- quantity: 1,
89
- },
90
- ],
91
- enqueuedAt: 1657003409370,
92
- ads: [
93
- {
94
- adPlatform: 'cjaffiliate',
95
- adCodes: {
96
- cjevent: '816f5670dbf52c3dc27a7e849903c327d705ef643993fbab3',
97
- },
98
- visitAt: 1658392668000,
99
- },
100
- ],
101
- };
102
- await test(serviceBusMessage);
103
- await test(serviceBusMessage2);
104
- });
105
- });
106
-
107
- /**
108
- * Test function
109
- * @param [object] object obsahující nastavení testovací parametry
110
- */
111
- async function test(serviceBusMessage) {
112
- await defaultPublisher(
113
- testUtils.context,
114
- serviceBusMessage,
115
- 'CJ',
116
- publisher,
117
- trigger,
118
- );
119
- }
120
-
121
- // eslint-disable-next-line @typescript-eslint/require-await
122
- async function trigger(data, log) {
123
- const publishers = [];
124
- if (data.event.code === 'purchase') {
125
- let publisher = CJPurchasePublisher;
126
-
127
- publisher.register(publishers, { cid: '1', type: '1111111' });
128
- }
129
- return publishers;
130
- }
131
-
132
- class CJPurchasePublisher extends utils.EventPublisherBase {
133
- /**
134
- * Converts input data to publishing payload data understood by the publisher
135
- * @param {Object} data `purchase` event data
136
- * @returns {Object} Data mapped from incoming Service Bus message to platform payload
137
- */
138
- map(data, log) {
139
- const ret = {
140
- cjevent: utils.extractAdCode(data, 'cjaffiliate', 'cjevent')?.code,
141
- cust_status: data.user?.ts?.indexOf('customer') >= 0 ? 'return' : 'new',
142
- coupon: data.coupon,
143
- discount: data.localDiscount,
144
- method: 'S2S',
145
- currency: data.localCurrencyCode,
146
- oid: data.id,
147
- // eventTime: "" // This parameters is ignored, as the time is determined by the CJ server
148
- };
149
- if (data.products instanceof Array) {
150
- let i = 0;
151
- for (const product of data.products) {
152
- i++;
153
- ret[`item${i}`] = product.id;
154
- ret[`amt${i}`] = product.localPrice;
155
- ret[`qty${i}`] = product.quantity;
156
- }
157
- }
158
-
159
- return ret;
160
- }
161
- }
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
- }
@@ -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
- }