@socialgouv/matomo-postgres 1.1.4 → 1.2.2

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/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @socialgouv/matomo-postgres
2
2
 
3
- Extract matomo data and push to Postgres
3
+ ![header](./header.png)
4
4
 
5
- Use Matomo [`Live.getLastVisitsDetails`](https://developer.matomo.org/api-reference/reporting-api) API to extract visits informations.
5
+ Extract matomo data from [`Live.getLastVisitsDetails`](https://developer.matomo.org/api-reference/reporting-api) API and push events and visits informations to Postgres.
6
6
 
7
7
  ## Usage
8
8
 
package/bin/index.js CHANGED
@@ -6,6 +6,6 @@ if (require.main === module) {
6
6
  const date =
7
7
  (process.argv[process.argv.length - 1].match(/^\d\d\d\d-\d\d-\d\d$/) && process.argv[process.argv.length - 1]) ||
8
8
  "";
9
- console.log(`\nRunning @socialgouv/matomo-metabase ${date}\n`);
9
+ console.log(`\nRunning @socialgouv/matomo-postgres ${date}\n`);
10
10
  run(date);
11
11
  }
package/header.png ADDED
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@socialgouv/matomo-postgres",
3
3
  "description": "Extract visitor events from Matomo API and push to Postgres",
4
- "version": "1.1.4",
4
+ "version": "1.2.2",
5
5
  "types": "types/index.d.ts",
6
6
  "license": "Apache-2.0",
7
7
  "main": "src/index.js",
@@ -10,7 +10,7 @@
10
10
  "access": "public"
11
11
  },
12
12
  "bin": {
13
- "matomo-metabase": "./bin/index.js"
13
+ "matomo-postgres": "./bin/index.js"
14
14
  },
15
15
  "scripts": {
16
16
  "start": "node ./src/index.js",
@@ -21,8 +21,8 @@ Array [
21
21
  ],
22
22
  Array [
23
23
  "insert into matomo
24
- (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, usercustomproperties, usercustomdimensions)
25
- values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)
24
+ (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_title, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, siteSearchKeyword, usercustomproperties, usercustomdimensions)
25
+ values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)
26
26
  ON CONFLICT DO NOTHING",
27
27
  Array [
28
28
  "42",
@@ -42,6 +42,7 @@ Array [
42
42
  "2021-08-20T21:55:12.000Z",
43
43
  "123_0",
44
44
  "event",
45
+ "Evènement",
45
46
  "Ecommerce",
46
47
  "Cart change",
47
48
  "added - Basic Wetsuit",
@@ -49,6 +50,7 @@ Array [
49
50
  48,
50
51
  "2021-08-20T21:35:18.000Z",
51
52
  "https://dive-shop.net/products/basic-wetsuit/",
53
+ undefined,
52
54
  Object {
53
55
  "page-author": "Julien",
54
56
  "post-age": "-430 days",
@@ -64,8 +66,8 @@ Array [
64
66
  ],
65
67
  Array [
66
68
  "insert into matomo
67
- (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, usercustomproperties, usercustomdimensions)
68
- values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)
69
+ (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_title, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, siteSearchKeyword, usercustomproperties, usercustomdimensions)
70
+ values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)
69
71
  ON CONFLICT DO NOTHING",
70
72
  Array [
71
73
  "42",
@@ -85,6 +87,7 @@ Array [
85
87
  "2021-08-20T21:55:12.000Z",
86
88
  "123_1",
87
89
  "action",
90
+ "Divezone Brand Diving Boots - Divezone Store",
88
91
  undefined,
89
92
  undefined,
90
93
  undefined,
@@ -92,6 +95,49 @@ Array [
92
95
  "2",
93
96
  "2021-08-20T21:30:25.000Z",
94
97
  "https://dive-shop.net/products/diving-boots/",
98
+ undefined,
99
+ Object {},
100
+ Object {
101
+ "dimension1": "guest",
102
+ "dimension2": "julien",
103
+ "dimension3": "page",
104
+ "dimension4": "indonesia",
105
+ "dimension5": "diving",
106
+ },
107
+ ],
108
+ ],
109
+ Array [
110
+ "insert into matomo
111
+ (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_title, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, siteSearchKeyword, usercustomproperties, usercustomdimensions)
112
+ values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)
113
+ ON CONFLICT DO NOTHING",
114
+ Array [
115
+ "42",
116
+ 123,
117
+ "2",
118
+ "Argentine",
119
+ "Buenos Aires",
120
+ "Buenos Aires",
121
+ "Mac",
122
+ "Générique Bureau",
123
+ "Inconnu",
124
+ "300",
125
+ "23",
126
+ "returningCustomer",
127
+ "tests",
128
+ "24",
129
+ "2021-08-20T21:55:12.000Z",
130
+ "123_2",
131
+ "search",
132
+ "Divezone Brand Diving Boots - Divezone Store",
133
+ undefined,
134
+ undefined,
135
+ undefined,
136
+ undefined,
137
+ "2",
138
+ "2021-08-20T21:30:22.000Z",
139
+ "https://dive-shop.net/products/diving-boots/",
140
+ "scuba",
95
141
  Object {},
96
142
  Object {
97
143
  "dimension1": "guest",
@@ -104,8 +150,8 @@ Array [
104
150
  ],
105
151
  Array [
106
152
  "insert into matomo
107
- (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, usercustomproperties, usercustomdimensions)
108
- values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)
153
+ (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_title, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, siteSearchKeyword, usercustomproperties, usercustomdimensions)
154
+ values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)
109
155
  ON CONFLICT DO NOTHING",
110
156
  Array [
111
157
  "42",
@@ -125,6 +171,7 @@ Array [
125
171
  "2021-08-20T21:55:12.000Z",
126
172
  "124_0",
127
173
  "event",
174
+ "Evènement",
128
175
  "Ecommerce",
129
176
  "Cart change",
130
177
  "added - Basic Wetsuit",
@@ -132,6 +179,7 @@ Array [
132
179
  48,
133
180
  "2021-08-20T21:35:18.000Z",
134
181
  "https://dive-shop.net/products/basic-wetsuit/",
182
+ undefined,
135
183
  Object {
136
184
  "page-author": "Julien",
137
185
  "post-age": "-430 days",
@@ -147,8 +195,8 @@ Array [
147
195
  ],
148
196
  Array [
149
197
  "insert into matomo
150
- (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, usercustomproperties, usercustomdimensions)
151
- values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)
198
+ (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_title, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, siteSearchKeyword, usercustomproperties, usercustomdimensions)
199
+ values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)
152
200
  ON CONFLICT DO NOTHING",
153
201
  Array [
154
202
  "42",
@@ -168,6 +216,7 @@ Array [
168
216
  "2021-08-20T21:55:12.000Z",
169
217
  "124_1",
170
218
  "action",
219
+ "Divezone Brand Diving Boots - Divezone Store",
171
220
  undefined,
172
221
  undefined,
173
222
  undefined,
@@ -175,6 +224,49 @@ Array [
175
224
  "2",
176
225
  "2021-08-20T21:30:25.000Z",
177
226
  "https://dive-shop.net/products/diving-boots/",
227
+ undefined,
228
+ Object {},
229
+ Object {
230
+ "dimension1": "guest",
231
+ "dimension2": "julien",
232
+ "dimension3": "page",
233
+ "dimension4": "indonesia",
234
+ "dimension5": "diving",
235
+ },
236
+ ],
237
+ ],
238
+ Array [
239
+ "insert into matomo
240
+ (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_title, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, siteSearchKeyword, usercustomproperties, usercustomdimensions)
241
+ values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)
242
+ ON CONFLICT DO NOTHING",
243
+ Array [
244
+ "42",
245
+ 124,
246
+ "2",
247
+ "Argentine",
248
+ "Buenos Aires",
249
+ "Buenos Aires",
250
+ "Mac",
251
+ "Générique Bureau",
252
+ "Inconnu",
253
+ "300",
254
+ "23",
255
+ "returningCustomer",
256
+ "tests",
257
+ "24",
258
+ "2021-08-20T21:55:12.000Z",
259
+ "124_2",
260
+ "search",
261
+ "Divezone Brand Diving Boots - Divezone Store",
262
+ undefined,
263
+ undefined,
264
+ undefined,
265
+ undefined,
266
+ "2",
267
+ "2021-08-20T21:30:22.000Z",
268
+ "https://dive-shop.net/products/diving-boots/",
269
+ "scuba",
178
270
  Object {},
179
271
  Object {
180
272
  "dimension1": "guest",
@@ -10,6 +10,7 @@ Array [
10
10
  "action_id": "124_0",
11
11
  "action_timespent": 48,
12
12
  "action_timestamp": "2021-08-20T21:35:18.000Z",
13
+ "action_title": "Evènement",
13
14
  "action_type": "event",
14
15
  "action_url": "https://dive-shop.net/products/basic-wetsuit/",
15
16
  "actions": "2",
@@ -23,6 +24,7 @@ Array [
23
24
  "operatingsystemname": "Mac",
24
25
  "region": "Buenos Aires",
25
26
  "serverdateprettyfirstaction": "2021-08-20T21:55:12.000Z",
27
+ "siteSearchKeyword": undefined,
26
28
  "sitename": "tests",
27
29
  "usercustomdimensions": Object {
28
30
  "dimension1": "guest",
@@ -47,6 +49,7 @@ Array [
47
49
  "action_id": "124_1",
48
50
  "action_timespent": "2",
49
51
  "action_timestamp": "2021-08-20T21:30:25.000Z",
52
+ "action_title": "Divezone Brand Diving Boots - Divezone Store",
50
53
  "action_type": "action",
51
54
  "action_url": "https://dive-shop.net/products/diving-boots/",
52
55
  "actions": "2",
@@ -60,6 +63,43 @@ Array [
60
63
  "operatingsystemname": "Mac",
61
64
  "region": "Buenos Aires",
62
65
  "serverdateprettyfirstaction": "2021-08-20T21:55:12.000Z",
66
+ "siteSearchKeyword": undefined,
67
+ "sitename": "tests",
68
+ "usercustomdimensions": Object {
69
+ "dimension1": "guest",
70
+ "dimension2": "julien",
71
+ "dimension3": "page",
72
+ "dimension4": "indonesia",
73
+ "dimension5": "diving",
74
+ },
75
+ "usercustomproperties": Object {},
76
+ "userid": "24",
77
+ "visitduration": "300",
78
+ "visitortype": "returningCustomer",
79
+ },
80
+ Object {
81
+ "action_eventaction": undefined,
82
+ "action_eventcategory": undefined,
83
+ "action_eventname": undefined,
84
+ "action_eventvalue": undefined,
85
+ "action_id": "124_2",
86
+ "action_timespent": "2",
87
+ "action_timestamp": "2021-08-20T21:30:22.000Z",
88
+ "action_title": "Divezone Brand Diving Boots - Divezone Store",
89
+ "action_type": "search",
90
+ "action_url": "https://dive-shop.net/products/diving-boots/",
91
+ "actions": "2",
92
+ "city": "Buenos Aires",
93
+ "country": "Argentine",
94
+ "dayssincefirstvisit": "23",
95
+ "devicebrand": "Inconnu",
96
+ "devicemodel": "Générique Bureau",
97
+ "idsite": "42",
98
+ "idvisit": "124",
99
+ "operatingsystemname": "Mac",
100
+ "region": "Buenos Aires",
101
+ "serverdateprettyfirstaction": "2021-08-20T21:55:12.000Z",
102
+ "siteSearchKeyword": "scuba",
63
103
  "sitename": "tests",
64
104
  "usercustomdimensions": Object {
65
105
  "dimension1": "guest",
@@ -80,8 +120,8 @@ exports[`importEvent: should extract events from matomo visit actionsDetails and
80
120
  Array [
81
121
  Array [
82
122
  "insert into matomo
83
- (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, usercustomproperties, usercustomdimensions)
84
- values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)
123
+ (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_title, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, siteSearchKeyword, usercustomproperties, usercustomdimensions)
124
+ values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)
85
125
  ON CONFLICT DO NOTHING",
86
126
  Array [
87
127
  "42",
@@ -101,6 +141,7 @@ Array [
101
141
  "2021-08-20T21:55:12.000Z",
102
142
  "124_0",
103
143
  "event",
144
+ "Evènement",
104
145
  "Ecommerce",
105
146
  "Cart change",
106
147
  "added - Basic Wetsuit",
@@ -108,6 +149,7 @@ Array [
108
149
  48,
109
150
  "2021-08-20T21:35:18.000Z",
110
151
  "https://dive-shop.net/products/basic-wetsuit/",
152
+ undefined,
111
153
  Object {
112
154
  "page-author": "Julien",
113
155
  "post-age": "-430 days",
@@ -123,8 +165,8 @@ Array [
123
165
  ],
124
166
  Array [
125
167
  "insert into matomo
126
- (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, usercustomproperties, usercustomdimensions)
127
- values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)
168
+ (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_title, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, siteSearchKeyword, usercustomproperties, usercustomdimensions)
169
+ values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)
128
170
  ON CONFLICT DO NOTHING",
129
171
  Array [
130
172
  "42",
@@ -144,6 +186,7 @@ Array [
144
186
  "2021-08-20T21:55:12.000Z",
145
187
  "124_1",
146
188
  "action",
189
+ "Divezone Brand Diving Boots - Divezone Store",
147
190
  undefined,
148
191
  undefined,
149
192
  undefined,
@@ -151,6 +194,49 @@ Array [
151
194
  "2",
152
195
  "2021-08-20T21:30:25.000Z",
153
196
  "https://dive-shop.net/products/diving-boots/",
197
+ undefined,
198
+ Object {},
199
+ Object {
200
+ "dimension1": "guest",
201
+ "dimension2": "julien",
202
+ "dimension3": "page",
203
+ "dimension4": "indonesia",
204
+ "dimension5": "diving",
205
+ },
206
+ ],
207
+ ],
208
+ Array [
209
+ "insert into matomo
210
+ (idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_title, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, siteSearchKeyword, usercustomproperties, usercustomdimensions)
211
+ values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)
212
+ ON CONFLICT DO NOTHING",
213
+ Array [
214
+ "42",
215
+ "124",
216
+ "2",
217
+ "Argentine",
218
+ "Buenos Aires",
219
+ "Buenos Aires",
220
+ "Mac",
221
+ "Générique Bureau",
222
+ "Inconnu",
223
+ "300",
224
+ "23",
225
+ "returningCustomer",
226
+ "tests",
227
+ "24",
228
+ "2021-08-20T21:55:12.000Z",
229
+ "124_2",
230
+ "search",
231
+ "Divezone Brand Diving Boots - Divezone Store",
232
+ undefined,
233
+ undefined,
234
+ undefined,
235
+ undefined,
236
+ "2",
237
+ "2021-08-20T21:30:22.000Z",
238
+ "https://dive-shop.net/products/diving-boots/",
239
+ "scuba",
154
240
  Object {},
155
241
  Object {
156
242
  "dimension1": "guest",
@@ -24,12 +24,14 @@ Array [
24
24
  action_eventcategory text,
25
25
  action_eventaction text,
26
26
  action_eventname text,
27
- action_eventvalue text,
27
+ action_eventvalue decimal,
28
28
  action_timespent text,
29
29
  action_timestamp timestamp with time zone,
30
30
  usercustomproperties json,
31
31
  usercustomdimensions json,
32
- action_url text
32
+ action_url text,
33
+ sitesearchkeyword text,
34
+ action_title text
33
35
  )",
34
36
  Array [],
35
37
  ]
@@ -86,8 +86,8 @@ test("importDate: should import when new results", async () => {
86
86
  };
87
87
  //@ts-expect-error
88
88
  const imported = await importDate(fakeClient, matomoSpy, new Date("2021-08-03T00:00:00"));
89
- expect(pgSpy.mock.calls.length).toEqual(3);
90
- expect(imported.length).toEqual(2);
89
+ expect(pgSpy.mock.calls.length).toEqual(4);
90
+ expect(imported.length).toEqual(3);
91
91
  expect(matomoSpy.mock.calls[0][0].filter_offset).toEqual(0);
92
92
  });
93
93
 
@@ -110,8 +110,8 @@ test("importDate: should offset matomo calls when results already exist", async
110
110
  };
111
111
  //@ts-expect-error
112
112
  const imported = await importDate(fakeClient, matomoSpy, new Date("2021-08-03T00:00:00"));
113
- expect(pgSpy.mock.calls.length).toEqual(3);
114
- expect(imported.length).toEqual(2);
113
+ expect(pgSpy.mock.calls.length).toEqual(4);
114
+ expect(imported.length).toEqual(3);
115
115
  expect(matomoSpy.mock.calls[0][0].filter_offset).toEqual(42);
116
116
  });
117
117
 
@@ -12,6 +12,7 @@ const matomoVisit = require("./visit.json");
12
12
 
13
13
  const run = require("../index");
14
14
 
15
+ const NB_REQUEST_TO_INIT_DB = 6; // Number of query to init DB (createTable.js)
15
16
  const TEST_DATE = new Date();
16
17
 
17
18
  // @ts-ignore
@@ -84,10 +85,11 @@ test("run: should fetch the latest event date if no date provided", async () =>
84
85
  expect(mock_matomoApi.mock.calls[0][0].filter_offset).toEqual(0);
85
86
 
86
87
  // check db queries
87
- expect(mock_pgQuery.mock.calls[3][0]).toEqual(
88
+ expect(mock_pgQuery.mock.calls[NB_REQUEST_TO_INIT_DB][0]).toEqual(
88
89
  // call 0 is create table
89
90
  // call 1 is add column usercustomdimension
90
91
  // call 2 is add column action_url
92
+ // ...
91
93
  //
92
94
  "select action_timestamp from matomo order by action_timestamp desc limit 1"
93
95
  );
@@ -128,7 +130,9 @@ test("run: should resume using latest event date - offset if no date provided",
128
130
  expect(mock_matomoApi.mock.calls.length).toEqual(daysCount);
129
131
 
130
132
  // check db queries
131
- expect(mock_pgQuery.mock.calls.length).toEqual(4 + daysCount * 5); // create + alter + alter + select queries + days offset
133
+ console.log("daysCount", daysCount);
134
+ //console.log("mock_pgQuery.mock.calls", mock_pgQuery.mock.calls);
135
+ expect(mock_pgQuery.mock.calls.length).toEqual(NB_REQUEST_TO_INIT_DB + 1 + daysCount * 7); // NB_REQUEST_TO_INIT_DB + select queries + days offset
132
136
  });
133
137
 
134
138
  test("run: should use today date if nothing in DB", async () => {
@@ -152,7 +156,7 @@ test("run: should use today date if nothing in DB", async () => {
152
156
  expect(mock_matomoApi.mock.calls[0][0].date).toEqual(isoDate(TEST_DATE));
153
157
 
154
158
  // check the 4 events inserted
155
- expect(mock_pgQuery.mock.calls.length).toEqual(4 + 3); // create, alter, alter, check date, latest + 2 inserts
159
+ expect(mock_pgQuery.mock.calls.length).toEqual(NB_REQUEST_TO_INIT_DB + 5); // NB_REQUEST_TO_INIT_DB + check date + latest + 2 inserts
156
160
  });
157
161
 
158
162
  test("run: should use given date if any", async () => {
@@ -172,7 +176,7 @@ test("run: should use given date if any", async () => {
172
176
  await run(isoDate(addDays(TEST_DATE, -10)) + "T00:00:00.000Z");
173
177
 
174
178
  expect(mock_matomoApi.mock.calls.length).toEqual(11);
175
- expect(mock_pgQuery.mock.calls.length).toEqual(3 + 11 * 3); // create table + alter + alter + inserts. no initial select as date is provided
179
+ expect(mock_pgQuery.mock.calls.length).toEqual(NB_REQUEST_TO_INIT_DB + 11 * 4); // NB_REQUEST_TO_INIT_DB + inserts. no initial select as date is provided
176
180
  });
177
181
 
178
182
  test("run: should use STARTDATE if any", async () => {
@@ -194,5 +198,5 @@ test("run: should use STARTDATE if any", async () => {
194
198
 
195
199
  expect(mock_matomoApi.mock.calls.length).toEqual(6);
196
200
 
197
- expect(mock_pgQuery.mock.calls.length).toEqual(4 + 6 * 3); // create table + alter + alter + initial select + inserts.
201
+ expect(mock_pgQuery.mock.calls.length).toEqual(NB_REQUEST_TO_INIT_DB + 1 + 6 * 4); // NB_REQUEST_TO_INIT_DB + initial select + inserts.
198
202
  });
@@ -69,6 +69,27 @@
69
69
  "dimension2": "julien",
70
70
  "dimension4": "indonesia",
71
71
  "dimension5": "diving"
72
+ },
73
+ {
74
+ "type": "search",
75
+ "url": "https://dive-shop.net/products/diving-boots/",
76
+ "pageTitle": "Divezone Brand Diving Boots - Divezone Store",
77
+ "pageIdAction": "60",
78
+ "idpageview": "8CDIez",
79
+ "serverTimePretty": "20 août 2021 21:30:25",
80
+ "pageId": "19696664",
81
+ "timeSpent": "2",
82
+ "timeSpentPretty": "2s",
83
+ "pageviewPosition": "5",
84
+ "title": "Divezone Brand Diving Boots - Divezone Store",
85
+ "subtitle": "https://dive-shop.net/products/diving-boots/",
86
+ "icon": "",
87
+ "iconSVG": "plugins/Morpheus/images/action.svg",
88
+ "timestamp": 1629495022,
89
+ "dimension2": "julien",
90
+ "dimension4": "indonesia",
91
+ "dimension5": "diving",
92
+ "siteSearchKeyword": "scuba"
72
93
  }
73
94
  ]
74
95
  }
@@ -1,12 +1,14 @@
1
1
  const { Client } = require("pg");
2
2
 
3
3
  const { DESTINATION_TABLE } = require("./config");
4
+
4
5
  /**
5
6
  *
6
7
  * @param {Client} client
7
8
  */
8
9
  async function createTable(client) {
9
- const text = `CREATE TABLE IF NOT EXISTS ${client.escapeIdentifier(DESTINATION_TABLE)}
10
+ const table = client.escapeIdentifier(DESTINATION_TABLE);
11
+ const text = `CREATE TABLE IF NOT EXISTS ${table}
10
12
  (
11
13
  idsite text,
12
14
  idvisit text,
@@ -28,21 +30,35 @@ async function createTable(client) {
28
30
  action_eventcategory text,
29
31
  action_eventaction text,
30
32
  action_eventname text,
31
- action_eventvalue text,
33
+ action_eventvalue decimal,
32
34
  action_timespent text,
33
35
  action_timestamp timestamp with time zone,
34
36
  usercustomproperties json,
35
37
  usercustomdimensions json,
36
- action_url text
38
+ action_url text,
39
+ sitesearchkeyword text,
40
+ action_title text
37
41
  )`;
42
+
38
43
  await client.query(text, []);
39
- const addUserCustomDimensionColumn = `ALTER TABLE IF EXISTS ${client.escapeIdentifier(DESTINATION_TABLE)}
40
- ADD COLUMN IF NOT EXISTS "usercustomdimensions" json;`;
41
- await client.query(addUserCustomDimensionColumn, []);
42
44
 
43
- const addActionUrlColumn = `ALTER TABLE IF EXISTS ${client.escapeIdentifier(DESTINATION_TABLE)}
44
- ADD COLUMN IF NOT EXISTS "action_url" text;`;
45
- await client.query(addActionUrlColumn, []);
45
+ const migrations = [
46
+ `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "usercustomdimensions" json;`,
47
+ `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "action_url" text;`,
48
+ `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "sitesearchkeyword" text;`,
49
+ `ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "action_title" text;`,
50
+ `ALTER TABLE IF EXISTS ${table} ALTER COLUMN action_eventvalue TYPE decimal USING action_eventvalue::decimal;`,
51
+ ];
52
+
53
+ // --------------------------------------------- //
54
+ // If you add new query: Don't forget to update //
55
+ // const `NB_REQUEST_TO_INIT_DB` (index.test.js) //
56
+ // --------------------------------------------- //
57
+
58
+ for(const query of migrations) {
59
+ await client.query(query, []);
60
+ }
61
+
46
62
  }
47
63
 
48
64
  module.exports = { createTable };
@@ -42,6 +42,7 @@ const matomoProps = [
42
42
  /** @type Record<string, (a: import("types/matomo").ActionDetail) => string | number> */
43
43
  const actionProps = {
44
44
  action_type: (action) => action.type,
45
+ action_title: (action) => action.title,
45
46
  action_eventcategory: (action) => action.eventCategory,
46
47
  action_eventaction: (action) => action.eventAction,
47
48
  action_eventname: (action) => action.eventName,
@@ -49,6 +50,7 @@ const actionProps = {
49
50
  action_timespent: (action) => action.timeSpent,
50
51
  action_timestamp: (action) => new Date(action.timestamp * 1000).toISOString(),
51
52
  action_url: (action) => action.url,
53
+ siteSearchKeyword: (action) => action.siteSearchKeyword,
52
54
  };
53
55
 
54
56
  /**
package/types/index.d.ts CHANGED
@@ -27,4 +27,5 @@ export type Event = {
27
27
  action_url: string;
28
28
  usercustomproperties: Record<string, string>;
29
29
  usercustomdimensions: Record<string, string>;
30
+ siteSearchKeyword: string;
30
31
  };
package/types/matomo.d.ts CHANGED
@@ -157,6 +157,7 @@ export interface ActionDetail {
157
157
  revenueTax?: number;
158
158
  revenueShipping?: number;
159
159
  revenueDiscount?: number;
160
+ siteSearchKeyword: string;
160
161
  }
161
162
 
162
163
  export interface Field {