swetrix 3.2.0 → 3.3.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/esnext/Lib.d.ts +1 -1
- package/dist/esnext/Lib.js +13 -9
- package/dist/esnext/Lib.js.map +1 -1
- package/dist/esnext/index.d.ts +2 -1
- package/dist/esnext/index.js +2 -2
- package/dist/esnext/index.js.map +1 -1
- package/dist/swetrix.cjs.js +90 -17
- package/dist/swetrix.es5.js +90 -17
- package/dist/swetrix.js +1 -1
- package/dist/swetrix.orig.js +90 -17
- package/package.json +1 -1
- package/src/Lib.ts +13 -10
- package/src/index.ts +13 -2
package/dist/esnext/Lib.d.ts
CHANGED
|
@@ -140,7 +140,7 @@ export declare class Lib {
|
|
|
140
140
|
captureError(event: ErrorEvent): void;
|
|
141
141
|
trackErrors(options?: ErrorOptions): ErrorActions;
|
|
142
142
|
submitError(payload: IErrorEventPayload, evokeCallback?: boolean): void;
|
|
143
|
-
track(event: TrackEventOptions): void
|
|
143
|
+
track(event: TrackEventOptions): Promise<void>;
|
|
144
144
|
trackPageViews(options?: PageViewsOptions): PageActions;
|
|
145
145
|
getPerformanceStats(): IPerfPayload | {};
|
|
146
146
|
private heartbeat;
|
package/dist/esnext/Lib.js
CHANGED
|
@@ -75,7 +75,7 @@ export class Lib {
|
|
|
75
75
|
Object.assign(errorPayload, privateData);
|
|
76
76
|
this.sendRequest('error', errorPayload);
|
|
77
77
|
}
|
|
78
|
-
track(event) {
|
|
78
|
+
async track(event) {
|
|
79
79
|
if (!this.canTrack()) {
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
@@ -90,7 +90,7 @@ export class Lib {
|
|
|
90
90
|
me: getUTMMedium(),
|
|
91
91
|
ca: getUTMCampaign(),
|
|
92
92
|
};
|
|
93
|
-
this.sendRequest('custom', data);
|
|
93
|
+
await this.sendRequest('custom', data);
|
|
94
94
|
}
|
|
95
95
|
trackPageViews(options) {
|
|
96
96
|
if (!this.canTrack()) {
|
|
@@ -202,11 +202,11 @@ export class Lib {
|
|
|
202
202
|
return;
|
|
203
203
|
this.pageData.path = pg;
|
|
204
204
|
const perf = this.getPerformanceStats();
|
|
205
|
-
const prev = this.getPreviousPage();
|
|
206
205
|
this.activePage = pg;
|
|
207
|
-
this.submitPageView({ pg
|
|
206
|
+
this.submitPageView({ pg }, unique, perf, true);
|
|
208
207
|
}
|
|
209
208
|
submitPageView(payload, unique, perf, evokeCallback) {
|
|
209
|
+
const prev = this.getPreviousPage();
|
|
210
210
|
const privateData = {
|
|
211
211
|
pid: this.projectID,
|
|
212
212
|
perf,
|
|
@@ -219,6 +219,7 @@ export class Lib {
|
|
|
219
219
|
so: getUTMSource(),
|
|
220
220
|
me: getUTMMedium(),
|
|
221
221
|
ca: getUTMCampaign(),
|
|
222
|
+
prev,
|
|
222
223
|
...payload,
|
|
223
224
|
};
|
|
224
225
|
if (evokeCallback && this.pageViewsOptions?.callback) {
|
|
@@ -243,12 +244,15 @@ export class Lib {
|
|
|
243
244
|
}
|
|
244
245
|
return true;
|
|
245
246
|
}
|
|
246
|
-
sendRequest(path, body) {
|
|
247
|
+
async sendRequest(path, body) {
|
|
247
248
|
const host = this.options?.apiURL || DEFAULT_API_HOST;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
await fetch(`${host}/${path}`, {
|
|
250
|
+
method: 'POST',
|
|
251
|
+
headers: {
|
|
252
|
+
'Content-Type': 'application/json',
|
|
253
|
+
},
|
|
254
|
+
body: JSON.stringify(body),
|
|
255
|
+
});
|
|
252
256
|
}
|
|
253
257
|
}
|
|
254
258
|
//# sourceMappingURL=Lib.js.map
|
package/dist/esnext/Lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lib.js","sourceRoot":"","sources":["../../src/Lib.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,WAAW,EACX,WAAW,EACX,SAAS,EACT,WAAW,EACX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I,CAAC,OAAO,EAAE,QAAQ;YACtB,CAAC,WAAW,EAAE;YACd,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,IAAI,MAAM,CAAC,SAAS,EAAE,UAAU,KAAK,GAAG,CAAC;YAClE,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,CAAC;YACzC,WAAW,EAAE,EACb,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,IAAY,EAAE,IAAY;QAClD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,IAAI,gBAAgB,CAAA;QACrD,MAAM,KAAK,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,EAAE;YAC7B,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/dist/esnext/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare function init(pid: string, options?: LibOptions): Lib;
|
|
|
15
15
|
*
|
|
16
16
|
* @param {TrackEventOptions} event The options related to the custom event.
|
|
17
17
|
*/
|
|
18
|
-
export declare function track(event: TrackEventOptions): void
|
|
18
|
+
export declare function track(event: TrackEventOptions): Promise<void>;
|
|
19
19
|
/**
|
|
20
20
|
* With this function you are able to automatically track pageviews across your application.
|
|
21
21
|
*
|
|
@@ -54,3 +54,4 @@ export interface IPageviewOptions {
|
|
|
54
54
|
unique?: boolean;
|
|
55
55
|
}
|
|
56
56
|
export declare function pageview(options: IPageviewOptions): void;
|
|
57
|
+
export { LibOptions, TrackEventOptions, PageViewsOptions, ErrorOptions, PageActions, ErrorActions, IErrorEventPayload, IPageViewPayload, };
|
package/dist/esnext/index.js
CHANGED
|
@@ -20,10 +20,10 @@ export function init(pid, options) {
|
|
|
20
20
|
*
|
|
21
21
|
* @param {TrackEventOptions} event The options related to the custom event.
|
|
22
22
|
*/
|
|
23
|
-
export function track(event) {
|
|
23
|
+
export async function track(event) {
|
|
24
24
|
if (!LIB_INSTANCE)
|
|
25
25
|
return;
|
|
26
|
-
LIB_INSTANCE.track(event);
|
|
26
|
+
await LIB_INSTANCE.track(event);
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* With this function you are able to automatically track pageviews across your application.
|
package/dist/esnext/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAOH,cAAc,GAGf,MAAM,OAAO,CAAA;AAEd,MAAM,CAAC,IAAI,YAAY,GAAe,IAAI,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,IAAI,CAAC,GAAW,EAAE,OAAoB;IACpD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACtC,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAC,KAAwB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAOH,cAAc,GAGf,MAAM,OAAO,CAAA;AAEd,MAAM,CAAC,IAAI,YAAY,GAAe,IAAI,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,IAAI,CAAC,GAAW,EAAE,OAAoB;IACpD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACtC,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,KA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AE,EAAE,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;AAC9E,CAAC;AAOD,MAAM,UAAU,QAAQ,CAAC,OAAyB;IAChD,IAAI,CAAC,YAAY;QAAE,OAAM;IAEzB,YAAY,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;AAC3E,CAAC"}
|
package/dist/swetrix.cjs.js
CHANGED
|
@@ -28,6 +28,44 @@ var __assign = function() {
|
|
|
28
28
|
return __assign.apply(this, arguments);
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
32
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
34
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
35
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
36
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
37
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function __generator(thisArg, body) {
|
|
42
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
44
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
|
+
function step(op) {
|
|
46
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
48
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
49
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
|
+
switch (op[0]) {
|
|
51
|
+
case 0: case 1: t = op; break;
|
|
52
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
53
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
54
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
55
|
+
default:
|
|
56
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
57
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
58
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
59
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
60
|
+
if (t[2]) _.ops.pop();
|
|
61
|
+
_.trys.pop(); continue;
|
|
62
|
+
}
|
|
63
|
+
op = body.call(thisArg, _);
|
|
64
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
65
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
31
69
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
32
70
|
var e = new Error(message);
|
|
33
71
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
@@ -170,11 +208,22 @@ var Lib = /** @class */ (function () {
|
|
|
170
208
|
this.sendRequest('error', errorPayload);
|
|
171
209
|
};
|
|
172
210
|
Lib.prototype.track = function (event) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
211
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
212
|
+
var data;
|
|
213
|
+
return __generator(this, function (_a) {
|
|
214
|
+
switch (_a.label) {
|
|
215
|
+
case 0:
|
|
216
|
+
if (!this.canTrack()) {
|
|
217
|
+
return [2 /*return*/];
|
|
218
|
+
}
|
|
219
|
+
data = __assign(__assign({}, event), { pid: this.projectID, pg: this.activePage, lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() });
|
|
220
|
+
return [4 /*yield*/, this.sendRequest('custom', data)];
|
|
221
|
+
case 1:
|
|
222
|
+
_a.sent();
|
|
223
|
+
return [2 /*return*/];
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
178
227
|
};
|
|
179
228
|
Lib.prototype.trackPageViews = function (options) {
|
|
180
229
|
if (!this.canTrack()) {
|
|
@@ -290,18 +339,18 @@ var Lib = /** @class */ (function () {
|
|
|
290
339
|
return;
|
|
291
340
|
this.pageData.path = pg;
|
|
292
341
|
var perf = this.getPerformanceStats();
|
|
293
|
-
var prev = this.getPreviousPage();
|
|
294
342
|
this.activePage = pg;
|
|
295
|
-
this.submitPageView({ pg: pg
|
|
343
|
+
this.submitPageView({ pg: pg }, unique, perf, true);
|
|
296
344
|
};
|
|
297
345
|
Lib.prototype.submitPageView = function (payload, unique, perf, evokeCallback) {
|
|
298
346
|
var _a;
|
|
347
|
+
var prev = this.getPreviousPage();
|
|
299
348
|
var privateData = {
|
|
300
349
|
pid: this.projectID,
|
|
301
350
|
perf: perf,
|
|
302
351
|
unique: unique,
|
|
303
352
|
};
|
|
304
|
-
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() }, payload);
|
|
353
|
+
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign(), prev: prev }, payload);
|
|
305
354
|
if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
|
|
306
355
|
var callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
307
356
|
if (callbackResult === false) {
|
|
@@ -326,12 +375,26 @@ var Lib = /** @class */ (function () {
|
|
|
326
375
|
return true;
|
|
327
376
|
};
|
|
328
377
|
Lib.prototype.sendRequest = function (path, body) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
378
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
379
|
+
var host;
|
|
380
|
+
var _a;
|
|
381
|
+
return __generator(this, function (_b) {
|
|
382
|
+
switch (_b.label) {
|
|
383
|
+
case 0:
|
|
384
|
+
host = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.apiURL) || DEFAULT_API_HOST;
|
|
385
|
+
return [4 /*yield*/, fetch("".concat(host, "/").concat(path), {
|
|
386
|
+
method: 'POST',
|
|
387
|
+
headers: {
|
|
388
|
+
'Content-Type': 'application/json',
|
|
389
|
+
},
|
|
390
|
+
body: JSON.stringify(body),
|
|
391
|
+
})];
|
|
392
|
+
case 1:
|
|
393
|
+
_b.sent();
|
|
394
|
+
return [2 /*return*/];
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
});
|
|
335
398
|
};
|
|
336
399
|
return Lib;
|
|
337
400
|
}());
|
|
@@ -358,9 +421,19 @@ function init(pid, options) {
|
|
|
358
421
|
* @param {TrackEventOptions} event The options related to the custom event.
|
|
359
422
|
*/
|
|
360
423
|
function track(event) {
|
|
361
|
-
|
|
362
|
-
return
|
|
363
|
-
|
|
424
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
425
|
+
return __generator(this, function (_a) {
|
|
426
|
+
switch (_a.label) {
|
|
427
|
+
case 0:
|
|
428
|
+
if (!exports.LIB_INSTANCE)
|
|
429
|
+
return [2 /*return*/];
|
|
430
|
+
return [4 /*yield*/, exports.LIB_INSTANCE.track(event)];
|
|
431
|
+
case 1:
|
|
432
|
+
_a.sent();
|
|
433
|
+
return [2 /*return*/];
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
});
|
|
364
437
|
}
|
|
365
438
|
/**
|
|
366
439
|
* With this function you are able to automatically track pageviews across your application.
|
package/dist/swetrix.es5.js
CHANGED
|
@@ -24,6 +24,44 @@ var __assign = function() {
|
|
|
24
24
|
return __assign.apply(this, arguments);
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
28
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
29
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
30
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
31
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
32
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
33
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function __generator(thisArg, body) {
|
|
38
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
+
function step(op) {
|
|
42
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
44
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
45
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
+
switch (op[0]) {
|
|
47
|
+
case 0: case 1: t = op; break;
|
|
48
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
+
default:
|
|
52
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
+
if (t[2]) _.ops.pop();
|
|
57
|
+
_.trys.pop(); continue;
|
|
58
|
+
}
|
|
59
|
+
op = body.call(thisArg, _);
|
|
60
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
27
65
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
28
66
|
var e = new Error(message);
|
|
29
67
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
@@ -166,11 +204,22 @@ var Lib = /** @class */ (function () {
|
|
|
166
204
|
this.sendRequest('error', errorPayload);
|
|
167
205
|
};
|
|
168
206
|
Lib.prototype.track = function (event) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
207
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
208
|
+
var data;
|
|
209
|
+
return __generator(this, function (_a) {
|
|
210
|
+
switch (_a.label) {
|
|
211
|
+
case 0:
|
|
212
|
+
if (!this.canTrack()) {
|
|
213
|
+
return [2 /*return*/];
|
|
214
|
+
}
|
|
215
|
+
data = __assign(__assign({}, event), { pid: this.projectID, pg: this.activePage, lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() });
|
|
216
|
+
return [4 /*yield*/, this.sendRequest('custom', data)];
|
|
217
|
+
case 1:
|
|
218
|
+
_a.sent();
|
|
219
|
+
return [2 /*return*/];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
});
|
|
174
223
|
};
|
|
175
224
|
Lib.prototype.trackPageViews = function (options) {
|
|
176
225
|
if (!this.canTrack()) {
|
|
@@ -286,18 +335,18 @@ var Lib = /** @class */ (function () {
|
|
|
286
335
|
return;
|
|
287
336
|
this.pageData.path = pg;
|
|
288
337
|
var perf = this.getPerformanceStats();
|
|
289
|
-
var prev = this.getPreviousPage();
|
|
290
338
|
this.activePage = pg;
|
|
291
|
-
this.submitPageView({ pg: pg
|
|
339
|
+
this.submitPageView({ pg: pg }, unique, perf, true);
|
|
292
340
|
};
|
|
293
341
|
Lib.prototype.submitPageView = function (payload, unique, perf, evokeCallback) {
|
|
294
342
|
var _a;
|
|
343
|
+
var prev = this.getPreviousPage();
|
|
295
344
|
var privateData = {
|
|
296
345
|
pid: this.projectID,
|
|
297
346
|
perf: perf,
|
|
298
347
|
unique: unique,
|
|
299
348
|
};
|
|
300
|
-
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() }, payload);
|
|
349
|
+
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign(), prev: prev }, payload);
|
|
301
350
|
if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
|
|
302
351
|
var callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
303
352
|
if (callbackResult === false) {
|
|
@@ -322,12 +371,26 @@ var Lib = /** @class */ (function () {
|
|
|
322
371
|
return true;
|
|
323
372
|
};
|
|
324
373
|
Lib.prototype.sendRequest = function (path, body) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
374
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
375
|
+
var host;
|
|
376
|
+
var _a;
|
|
377
|
+
return __generator(this, function (_b) {
|
|
378
|
+
switch (_b.label) {
|
|
379
|
+
case 0:
|
|
380
|
+
host = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.apiURL) || DEFAULT_API_HOST;
|
|
381
|
+
return [4 /*yield*/, fetch("".concat(host, "/").concat(path), {
|
|
382
|
+
method: 'POST',
|
|
383
|
+
headers: {
|
|
384
|
+
'Content-Type': 'application/json',
|
|
385
|
+
},
|
|
386
|
+
body: JSON.stringify(body),
|
|
387
|
+
})];
|
|
388
|
+
case 1:
|
|
389
|
+
_b.sent();
|
|
390
|
+
return [2 /*return*/];
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
});
|
|
331
394
|
};
|
|
332
395
|
return Lib;
|
|
333
396
|
}());
|
|
@@ -354,9 +417,19 @@ function init(pid, options) {
|
|
|
354
417
|
* @param {TrackEventOptions} event The options related to the custom event.
|
|
355
418
|
*/
|
|
356
419
|
function track(event) {
|
|
357
|
-
|
|
358
|
-
return
|
|
359
|
-
|
|
420
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
421
|
+
return __generator(this, function (_a) {
|
|
422
|
+
switch (_a.label) {
|
|
423
|
+
case 0:
|
|
424
|
+
if (!LIB_INSTANCE)
|
|
425
|
+
return [2 /*return*/];
|
|
426
|
+
return [4 /*yield*/, LIB_INSTANCE.track(event)];
|
|
427
|
+
case 1:
|
|
428
|
+
_a.sent();
|
|
429
|
+
return [2 /*return*/];
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
});
|
|
360
433
|
}
|
|
361
434
|
/**
|
|
362
435
|
* With this function you are able to automatically track pageviews across your application.
|
package/dist/swetrix.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).swetrix={})}(this,function(
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).swetrix={})}(this,function(r){"use strict";var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function t(t,a,s,c){return new(s=s||Promise)(function(n,e){function r(t){try{i(c.next(t))}catch(t){e(t)}}function o(t){try{i(c.throw(t))}catch(t){e(t)}}function i(t){var e;t.done?n(t.value):((e=t.value)instanceof s?e:new s(function(t){t(e)})).then(r,o)}i((c=c.apply(t,a||[])).next())})}function o(r,o){var i,a,s,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},u={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function t(n){return function(t){var e=[n,t];if(i)throw new TypeError("Generator is already executing.");for(;c=u&&e[u=0]?0:c;)try{if(i=1,a&&(s=2&e[0]?a.return:e[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,e[1])).done)return s;switch(a=0,(e=s?[2&e[0],s.value]:e)[0]){case 0:case 1:s=e;break;case 4:return c.label++,{value:e[1],done:!1};case 5:c.label++,a=e[1],e=[0];continue;case 7:e=c.ops.pop(),c.trys.pop();continue;default:if(!(s=0<(s=c.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){c=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3]))c.label=e[1];else if(6===e[0]&&c.label<s[1])c.label=s[1],s=e;else{if(!(s&&c.label<s[2])){s[2]&&c.ops.pop(),c.trys.pop();continue}c.label=s[2],c.ops.push(e)}}e=o.call(r,c)}catch(t){e=[6,t],a=0}finally{i=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}}}function e(t){return(t=location.search.match(t))&&t[2]||void 0}function a(){return void 0!==navigator.languages?navigator.languages[0]:navigator.language}function s(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(t){}}function c(){return document.referrer||void 0}function u(){return e(n)}function l(){return e(f)}function h(){return e(d)}function p(t){var e,n=location.pathname||"";return t.hash&&(n+=-1<(e=location.hash.indexOf("?"))?location.hash.substring(0,e):location.hash),t.search&&(e=location.hash.indexOf("?"),n+=location.search||(-1<e?location.hash.substring(e):"")),n}var n=/[?&](ref|source|utm_source)=([^?&]+)/,d=/[?&](utm_campaign)=([^?&]+)/,f=/[?&](utm_medium)=([^?&]+)/,v={stop:function(){}},g=(m.prototype.captureError=function(t){var e;"number"==typeof(null==(e=this.errorsOptions)?void 0:e.sampleRate)&&this.errorsOptions.sampleRate>Math.random()||this.submitError({filename:t.filename,lineno:t.lineno,colno:t.colno,name:(null==(e=t.error)?void 0:e.name)||"Error",message:(null==(e=t.error)?void 0:e.message)||t.message},!0)},m.prototype.trackErrors=function(t){var e=this;return this.errorListenerExists||!this.canTrack()?v:(this.errorsOptions=t,window.addEventListener("error",this.captureError),this.errorListenerExists=!0,{stop:function(){window.removeEventListener("error",e.captureError)}})},m.prototype.submitError=function(t,e){var n={pid:this.projectID},r=i({pg:this.activePage||p({hash:null==(r=this.pageViewsOptions)?void 0:r.hash,search:null==(r=this.pageViewsOptions)?void 0:r.search}),lc:a(),tz:s()},t);if(e&&null!=(t=this.errorsOptions)&&t.callback){e=this.errorsOptions.callback(r);if(!1===e)return;e&&"object"==typeof e&&Object.assign(r,e)}Object.assign(r,n),this.sendRequest("error",r)},m.prototype.track=function(n){return t(this,void 0,void 0,function(){var e;return o(this,function(t){switch(t.label){case 0:return this.canTrack()?(e=i(i({},n),{pid:this.projectID,pg:this.activePage,lc:a(),tz:s(),ref:c(),so:u(),me:l(),ca:h()}),[4,this.sendRequest("custom",e)]):[2];case 1:return t.sent(),[2]}})})},m.prototype.trackPageViews=function(t){var e,n,r;return this.canTrack()?(this.pageData||(null!=(this.pageViewsOptions=t)&&t.unique||(e=setInterval(this.trackPathChange,2e3)),setTimeout(this.heartbeat,3e3),n=setInterval(this.heartbeat,28e3),r=p({hash:null==t?void 0:t.hash,search:null==t?void 0:t.search}),this.pageData={path:r,actions:{stop:function(){clearInterval(e),clearInterval(n)}}},this.trackPage(r,null==t?void 0:t.unique)),this.pageData.actions):v},m.prototype.getPerformanceStats=function(){var t;return this.canTrack()&&!this.perfStatsCollected&&null!=(t=window.performance)&&t.getEntriesByType&&(t=window.performance.getEntriesByType("navigation")[0])?(this.perfStatsCollected=!0,{dns:t.domainLookupEnd-t.domainLookupStart,tls:t.secureConnectionStart?t.requestStart-t.secureConnectionStart:0,conn:t.secureConnectionStart?t.secureConnectionStart-t.connectStart:t.connectEnd-t.connectStart,response:t.responseEnd-t.responseStart,render:t.domComplete-t.domContentLoadedEventEnd,dom_load:t.domContentLoadedEventEnd-t.responseEnd,page_load:t.loadEventStart,ttfb:t.responseStart-t.requestStart}):{}},m.prototype.heartbeat=function(){var t;(null!=(t=this.pageViewsOptions)&&t.heartbeatOnBackground||"hidden"!==document.visibilityState)&&(t={pid:this.projectID},this.sendRequest("hb",t))},m.prototype.trackPathChange=function(){var t;this.pageData&&(t=p({hash:null==(t=this.pageViewsOptions)?void 0:t.hash,search:null==(t=this.pageViewsOptions)?void 0:t.search}),this.pageData.path!==t)&&this.trackPage(t,!1)},m.prototype.getPreviousPage=function(){if(this.activePage)return this.activePage;if("function"==typeof URL){var t=c();if(!t)return null;var e=location.host;try{var n=new URL(t),r=n.host,o=n.pathname;return e!==r?null:o}catch(t){}}return null},m.prototype.trackPage=function(t,e){var n;void 0===e&&(e=!1),this.pageData&&(this.pageData.path=t,n=this.getPerformanceStats(),this.activePage=t,this.submitPageView({pg:t},e,n,!0))},m.prototype.submitPageView=function(t,e,n,r){var o=this.getPreviousPage(),n={pid:this.projectID,perf:n,unique:e},e=i({lc:a(),tz:s(),ref:c(),so:u(),me:l(),ca:h(),prev:o},t);if(r&&null!=(o=this.pageViewsOptions)&&o.callback){t=this.pageViewsOptions.callback(e);if(!1===t)return;t&&"object"==typeof t&&Object.assign(e,t)}Object.assign(e,n),this.sendRequest("",e)},m.prototype.canTrack=function(){var t;return!(null!=(t=this.options)&&t.disabled||"undefined"==typeof window||null!=(t=this.options)&&t.respectDNT&&"1"===(null==(t=window.navigator)?void 0:t.doNotTrack)||(null==(t=this.options)||!t.devMode)&&("localhost"===(null===location||void 0===location?void 0:location.hostname)||"127.0.0.1"===(null===location||void 0===location?void 0:location.hostname)||""===(null===location||void 0===location?void 0:location.hostname))||null!==navigator&&void 0!==navigator&&navigator.webdriver)},m.prototype.sendRequest=function(n,r){return t(this,void 0,void 0,function(){var e;return o(this,function(t){switch(t.label){case 0:return e=(null==(e=this.options)?void 0:e.apiURL)||"https://api.swetrix.com/log",[4,fetch("".concat(e,"/").concat(n),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 1:return t.sent(),[2]}})})},m);function m(t,e){this.projectID=t,this.options=e,this.pageData=null,this.pageViewsOptions=null,this.errorsOptions=null,this.perfStatsCollected=!1,this.activePage=null,this.errorListenerExists=!1,this.trackPathChange=this.trackPathChange.bind(this),this.heartbeat=this.heartbeat.bind(this),this.captureError=this.captureError.bind(this)}r.LIB_INSTANCE=null,r.init=function(t,e){return r.LIB_INSTANCE||(r.LIB_INSTANCE=new g(t,e)),r.LIB_INSTANCE},r.pageview=function(t){r.LIB_INSTANCE&&r.LIB_INSTANCE.submitPageView(t.payload,Boolean(t.unique),{})},r.track=function(e){return t(this,void 0,void 0,function(){return o(this,function(t){switch(t.label){case 0:return r.LIB_INSTANCE?[4,r.LIB_INSTANCE.track(e)]:[2];case 1:return t.sent(),[2]}})})},r.trackError=function(t){r.LIB_INSTANCE&&r.LIB_INSTANCE.submitError(t,!1)},r.trackErrors=function(t){return r.LIB_INSTANCE?r.LIB_INSTANCE.trackErrors(t):v},r.trackPageview=function(t,e,n){r.LIB_INSTANCE&&r.LIB_INSTANCE.submitPageView({pg:t,prev:e||null},Boolean(n),{})},r.trackViews=function(e){return new Promise(function(t){r.LIB_INSTANCE?"undefined"==typeof document||"complete"===document.readyState?t(r.LIB_INSTANCE.trackPageViews(e)):window.addEventListener("load",function(){t(r.LIB_INSTANCE.trackPageViews(e))}):t(v)})},Object.defineProperty(r,"__esModule",{value:!0})});
|
package/dist/swetrix.orig.js
CHANGED
|
@@ -30,6 +30,44 @@
|
|
|
30
30
|
return __assign.apply(this, arguments);
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
34
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
35
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
36
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
37
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
38
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
39
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function __generator(thisArg, body) {
|
|
44
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
45
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
46
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
47
|
+
function step(op) {
|
|
48
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
49
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
50
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
51
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
52
|
+
switch (op[0]) {
|
|
53
|
+
case 0: case 1: t = op; break;
|
|
54
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
55
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
56
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
57
|
+
default:
|
|
58
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
59
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
60
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
61
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
62
|
+
if (t[2]) _.ops.pop();
|
|
63
|
+
_.trys.pop(); continue;
|
|
64
|
+
}
|
|
65
|
+
op = body.call(thisArg, _);
|
|
66
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
67
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
33
71
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
34
72
|
var e = new Error(message);
|
|
35
73
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
@@ -172,11 +210,22 @@
|
|
|
172
210
|
this.sendRequest('error', errorPayload);
|
|
173
211
|
};
|
|
174
212
|
Lib.prototype.track = function (event) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
213
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
214
|
+
var data;
|
|
215
|
+
return __generator(this, function (_a) {
|
|
216
|
+
switch (_a.label) {
|
|
217
|
+
case 0:
|
|
218
|
+
if (!this.canTrack()) {
|
|
219
|
+
return [2 /*return*/];
|
|
220
|
+
}
|
|
221
|
+
data = __assign(__assign({}, event), { pid: this.projectID, pg: this.activePage, lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() });
|
|
222
|
+
return [4 /*yield*/, this.sendRequest('custom', data)];
|
|
223
|
+
case 1:
|
|
224
|
+
_a.sent();
|
|
225
|
+
return [2 /*return*/];
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
});
|
|
180
229
|
};
|
|
181
230
|
Lib.prototype.trackPageViews = function (options) {
|
|
182
231
|
if (!this.canTrack()) {
|
|
@@ -292,18 +341,18 @@
|
|
|
292
341
|
return;
|
|
293
342
|
this.pageData.path = pg;
|
|
294
343
|
var perf = this.getPerformanceStats();
|
|
295
|
-
var prev = this.getPreviousPage();
|
|
296
344
|
this.activePage = pg;
|
|
297
|
-
this.submitPageView({ pg: pg
|
|
345
|
+
this.submitPageView({ pg: pg }, unique, perf, true);
|
|
298
346
|
};
|
|
299
347
|
Lib.prototype.submitPageView = function (payload, unique, perf, evokeCallback) {
|
|
300
348
|
var _a;
|
|
349
|
+
var prev = this.getPreviousPage();
|
|
301
350
|
var privateData = {
|
|
302
351
|
pid: this.projectID,
|
|
303
352
|
perf: perf,
|
|
304
353
|
unique: unique,
|
|
305
354
|
};
|
|
306
|
-
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() }, payload);
|
|
355
|
+
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign(), prev: prev }, payload);
|
|
307
356
|
if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
|
|
308
357
|
var callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
309
358
|
if (callbackResult === false) {
|
|
@@ -328,12 +377,26 @@
|
|
|
328
377
|
return true;
|
|
329
378
|
};
|
|
330
379
|
Lib.prototype.sendRequest = function (path, body) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
380
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
381
|
+
var host;
|
|
382
|
+
var _a;
|
|
383
|
+
return __generator(this, function (_b) {
|
|
384
|
+
switch (_b.label) {
|
|
385
|
+
case 0:
|
|
386
|
+
host = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.apiURL) || DEFAULT_API_HOST;
|
|
387
|
+
return [4 /*yield*/, fetch("".concat(host, "/").concat(path), {
|
|
388
|
+
method: 'POST',
|
|
389
|
+
headers: {
|
|
390
|
+
'Content-Type': 'application/json',
|
|
391
|
+
},
|
|
392
|
+
body: JSON.stringify(body),
|
|
393
|
+
})];
|
|
394
|
+
case 1:
|
|
395
|
+
_b.sent();
|
|
396
|
+
return [2 /*return*/];
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
});
|
|
337
400
|
};
|
|
338
401
|
return Lib;
|
|
339
402
|
}());
|
|
@@ -360,9 +423,19 @@
|
|
|
360
423
|
* @param {TrackEventOptions} event The options related to the custom event.
|
|
361
424
|
*/
|
|
362
425
|
function track(event) {
|
|
363
|
-
|
|
364
|
-
return
|
|
365
|
-
|
|
426
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
427
|
+
return __generator(this, function (_a) {
|
|
428
|
+
switch (_a.label) {
|
|
429
|
+
case 0:
|
|
430
|
+
if (!exports.LIB_INSTANCE)
|
|
431
|
+
return [2 /*return*/];
|
|
432
|
+
return [4 /*yield*/, exports.LIB_INSTANCE.track(event)];
|
|
433
|
+
case 1:
|
|
434
|
+
_a.sent();
|
|
435
|
+
return [2 /*return*/];
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
});
|
|
366
439
|
}
|
|
367
440
|
/**
|
|
368
441
|
* With this function you are able to automatically track pageviews across your application.
|
package/package.json
CHANGED
package/src/Lib.ts
CHANGED
|
@@ -261,7 +261,7 @@ export class Lib {
|
|
|
261
261
|
this.sendRequest('error', errorPayload)
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
track(event: TrackEventOptions): void {
|
|
264
|
+
async track(event: TrackEventOptions): Promise<void> {
|
|
265
265
|
if (!this.canTrack()) {
|
|
266
266
|
return
|
|
267
267
|
}
|
|
@@ -277,7 +277,7 @@ export class Lib {
|
|
|
277
277
|
me: getUTMMedium(),
|
|
278
278
|
ca: getUTMCampaign(),
|
|
279
279
|
}
|
|
280
|
-
this.sendRequest('custom', data)
|
|
280
|
+
await this.sendRequest('custom', data)
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
trackPageViews(options?: PageViewsOptions): PageActions {
|
|
@@ -417,10 +417,8 @@ export class Lib {
|
|
|
417
417
|
|
|
418
418
|
const perf = this.getPerformanceStats()
|
|
419
419
|
|
|
420
|
-
const prev = this.getPreviousPage()
|
|
421
|
-
|
|
422
420
|
this.activePage = pg
|
|
423
|
-
this.submitPageView({ pg
|
|
421
|
+
this.submitPageView({ pg }, unique, perf, true)
|
|
424
422
|
}
|
|
425
423
|
|
|
426
424
|
submitPageView(
|
|
@@ -429,6 +427,7 @@ export class Lib {
|
|
|
429
427
|
perf: IPerfPayload | {},
|
|
430
428
|
evokeCallback?: boolean,
|
|
431
429
|
): void {
|
|
430
|
+
const prev = this.getPreviousPage()
|
|
432
431
|
const privateData = {
|
|
433
432
|
pid: this.projectID,
|
|
434
433
|
perf,
|
|
@@ -442,6 +441,7 @@ export class Lib {
|
|
|
442
441
|
so: getUTMSource(),
|
|
443
442
|
me: getUTMMedium(),
|
|
444
443
|
ca: getUTMCampaign(),
|
|
444
|
+
prev,
|
|
445
445
|
...payload,
|
|
446
446
|
}
|
|
447
447
|
|
|
@@ -476,11 +476,14 @@ export class Lib {
|
|
|
476
476
|
return true
|
|
477
477
|
}
|
|
478
478
|
|
|
479
|
-
private sendRequest(path: string, body: object): void {
|
|
479
|
+
private async sendRequest(path: string, body: object): Promise<void> {
|
|
480
480
|
const host = this.options?.apiURL || DEFAULT_API_HOST
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
481
|
+
await fetch(`${host}/${path}`, {
|
|
482
|
+
method: 'POST',
|
|
483
|
+
headers: {
|
|
484
|
+
'Content-Type': 'application/json',
|
|
485
|
+
},
|
|
486
|
+
body: JSON.stringify(body),
|
|
487
|
+
})
|
|
485
488
|
}
|
|
486
489
|
}
|
package/src/index.ts
CHANGED
|
@@ -35,10 +35,10 @@ export function init(pid: string, options?: LibOptions): Lib {
|
|
|
35
35
|
*
|
|
36
36
|
* @param {TrackEventOptions} event The options related to the custom event.
|
|
37
37
|
*/
|
|
38
|
-
export function track(event: TrackEventOptions): void {
|
|
38
|
+
export async function track(event: TrackEventOptions): Promise<void> {
|
|
39
39
|
if (!LIB_INSTANCE) return
|
|
40
40
|
|
|
41
|
-
LIB_INSTANCE.track(event)
|
|
41
|
+
await LIB_INSTANCE.track(event)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -119,3 +119,14 @@ export function pageview(options: IPageviewOptions): void {
|
|
|
119
119
|
|
|
120
120
|
LIB_INSTANCE.submitPageView(options.payload, Boolean(options.unique), {})
|
|
121
121
|
}
|
|
122
|
+
|
|
123
|
+
export {
|
|
124
|
+
LibOptions,
|
|
125
|
+
TrackEventOptions,
|
|
126
|
+
PageViewsOptions,
|
|
127
|
+
ErrorOptions,
|
|
128
|
+
PageActions,
|
|
129
|
+
ErrorActions,
|
|
130
|
+
IErrorEventPayload,
|
|
131
|
+
IPageViewPayload,
|
|
132
|
+
}
|