swetrix 2.4.0 → 3.0.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/.prettierrc.js +13 -0
- package/dist/esnext/Lib.d.ts +32 -14
- package/dist/esnext/Lib.js +38 -78
- package/dist/esnext/Lib.js.map +1 -1
- package/dist/esnext/index.js +1 -1
- package/dist/esnext/index.js.map +1 -1
- package/dist/esnext/utils.js.map +1 -1
- package/dist/swetrix.cjs.js +40 -83
- package/dist/swetrix.es5.js +40 -83
- package/dist/swetrix.js +1 -1
- package/dist/swetrix.orig.js +40 -83
- package/package.json +5 -5
- package/src/Lib.ts +88 -99
- package/src/index.ts +2 -4
package/.prettierrc.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
printWidth: 120, // max 120 chars in line, code is easy to read
|
|
3
|
+
useTabs: false, // use spaces instead of tabs
|
|
4
|
+
tabWidth: 2, // "visual width" of of the "tab"
|
|
5
|
+
trailingComma: 'all', // add trailing commas in objects, arrays, etc.
|
|
6
|
+
semi: false, // Only add semicolons at the beginning of lines that may introduce ASI failures
|
|
7
|
+
singleQuote: true, // '' for stings instead of ""
|
|
8
|
+
bracketSpacing: true, // import { some } ... instead of import {some} ...
|
|
9
|
+
arrowParens: 'always', // braces even for single param in arrow functions (a) => { }
|
|
10
|
+
jsxSingleQuote: true, // '' for react props
|
|
11
|
+
bracketSameLine: false, // pretty JSX
|
|
12
|
+
endOfLine: 'lf', // 'lf' for linux, 'crlf' for windows, we need to use 'lf' for git
|
|
13
|
+
}
|
package/dist/esnext/Lib.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export interface LibOptions {
|
|
2
2
|
/**
|
|
3
|
-
* When set to `true`,
|
|
3
|
+
* When set to `true`, localhost events will be sent to server.
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
devMode?: boolean;
|
|
6
6
|
/**
|
|
7
7
|
* When set to `true`, the tracking library won't send any data to server.
|
|
8
8
|
* Useful for development purposes when this value is set based on `.env` var.
|
|
@@ -25,6 +25,26 @@ export interface TrackEventOptions {
|
|
|
25
25
|
[key: string]: string;
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
export interface IPageViewPayload {
|
|
29
|
+
lc: string | undefined;
|
|
30
|
+
tz: string | undefined;
|
|
31
|
+
ref: string | undefined;
|
|
32
|
+
so: string | undefined;
|
|
33
|
+
me: string | undefined;
|
|
34
|
+
ca: string | undefined;
|
|
35
|
+
pg: string | null | undefined;
|
|
36
|
+
prev: string | null | undefined;
|
|
37
|
+
}
|
|
38
|
+
interface IPerfPayload {
|
|
39
|
+
dns: number;
|
|
40
|
+
tls: number;
|
|
41
|
+
conn: number;
|
|
42
|
+
response: number;
|
|
43
|
+
render: number;
|
|
44
|
+
dom_load: number;
|
|
45
|
+
page_load: number;
|
|
46
|
+
ttfb: number;
|
|
47
|
+
}
|
|
28
48
|
/**
|
|
29
49
|
* The object returned by `trackPageViews()`, used to stop tracking pages.
|
|
30
50
|
*/
|
|
@@ -44,16 +64,8 @@ export interface PageViewsOptions {
|
|
|
44
64
|
* This param is useful when tracking single-page landing websites.
|
|
45
65
|
*/
|
|
46
66
|
unique?: boolean;
|
|
47
|
-
/** A list of Regular Expressions or string pathes to ignore. */
|
|
48
|
-
ignore?: Array<string | RegExp>;
|
|
49
|
-
/** Do not send paths from ignore list to API. If set to `false`, the page view information will be sent to the Swetrix API, but the page will be displayed as a 'Redacted page' in the dashboard. */
|
|
50
|
-
doNotAnonymise?: boolean;
|
|
51
|
-
/** Do not send Heartbeat requests to the server. */
|
|
52
|
-
noHeartbeat?: boolean;
|
|
53
67
|
/** Send Heartbeat requests when the website tab is not active in the browser. */
|
|
54
68
|
heartbeatOnBackground?: boolean;
|
|
55
|
-
/** Disable user-flow */
|
|
56
|
-
noUserFlow?: boolean;
|
|
57
69
|
/**
|
|
58
70
|
* Set to `true` to enable hash-based routing.
|
|
59
71
|
* For example if you have pages like /#/path or want to track pages like /path#hash
|
|
@@ -64,6 +76,13 @@ export interface PageViewsOptions {
|
|
|
64
76
|
* For example if you have pages like /path?search
|
|
65
77
|
*/
|
|
66
78
|
search?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Callback to edit / prevent sending pageviews.
|
|
81
|
+
*
|
|
82
|
+
* @param payload - The pageview payload.
|
|
83
|
+
* @returns The edited payload or `false` to prevent sending the pageview. If `true` is returned, the payload will be sent as-is.
|
|
84
|
+
*/
|
|
85
|
+
callback?: (payload: IPageViewPayload) => IPageViewPayload | boolean;
|
|
67
86
|
}
|
|
68
87
|
export declare const defaultPageActions: {
|
|
69
88
|
stop(): void;
|
|
@@ -78,14 +97,13 @@ export declare class Lib {
|
|
|
78
97
|
constructor(projectID: string, options?: LibOptions | undefined);
|
|
79
98
|
track(event: TrackEventOptions): void;
|
|
80
99
|
trackPageViews(options?: PageViewsOptions): PageActions;
|
|
81
|
-
getPerformanceStats():
|
|
100
|
+
getPerformanceStats(): IPerfPayload | {};
|
|
82
101
|
private heartbeat;
|
|
83
|
-
private checkIgnore;
|
|
84
102
|
private trackPathChange;
|
|
85
103
|
private getPreviousPage;
|
|
86
104
|
private trackPage;
|
|
87
|
-
submitPageView(pg:
|
|
88
|
-
private debug;
|
|
105
|
+
submitPageView(pg: string, prev: string | null | undefined, unique: boolean, perf: IPerfPayload | {}, evokeCallback?: boolean): void;
|
|
89
106
|
private canTrack;
|
|
90
107
|
private sendRequest;
|
|
91
108
|
}
|
|
109
|
+
export {};
|
package/dist/esnext/Lib.js
CHANGED
|
@@ -19,6 +19,7 @@ export class Lib {
|
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
const data = {
|
|
22
|
+
...event,
|
|
22
23
|
pid: this.projectID,
|
|
23
24
|
pg: this.activePage,
|
|
24
25
|
lc: getLocale(),
|
|
@@ -27,7 +28,6 @@ export class Lib {
|
|
|
27
28
|
so: getUTMSource(),
|
|
28
29
|
me: getUTMMedium(),
|
|
29
30
|
ca: getUTMCampaign(),
|
|
30
|
-
...event,
|
|
31
31
|
};
|
|
32
32
|
this.sendRequest('custom', data);
|
|
33
33
|
}
|
|
@@ -39,14 +39,12 @@ export class Lib {
|
|
|
39
39
|
return this.pageData.actions;
|
|
40
40
|
}
|
|
41
41
|
this.pageViewsOptions = options;
|
|
42
|
-
let
|
|
42
|
+
let interval;
|
|
43
43
|
if (!options?.unique) {
|
|
44
44
|
interval = setInterval(this.trackPathChange, 2000);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
hbInterval = setInterval(this.heartbeat, 28000);
|
|
49
|
-
}
|
|
46
|
+
setTimeout(this.heartbeat, 3000);
|
|
47
|
+
const hbInterval = setInterval(this.heartbeat, 28000);
|
|
50
48
|
const path = getPath({
|
|
51
49
|
hash: options?.hash,
|
|
52
50
|
search: options?.search,
|
|
@@ -74,23 +72,17 @@ export class Lib {
|
|
|
74
72
|
this.perfStatsCollected = true;
|
|
75
73
|
return {
|
|
76
74
|
// Network
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// @ts-ignore
|
|
84
|
-
response: perf.responseEnd - perf.responseStart,
|
|
75
|
+
dns: perf.domainLookupEnd - perf.domainLookupStart, // DNS Resolution
|
|
76
|
+
tls: perf.secureConnectionStart ? perf.requestStart - perf.secureConnectionStart : 0, // TLS Setup; checking if secureConnectionStart is not 0 (it's 0 for non-https websites)
|
|
77
|
+
conn: perf.secureConnectionStart
|
|
78
|
+
? perf.secureConnectionStart - perf.connectStart
|
|
79
|
+
: perf.connectEnd - perf.connectStart, // Connection time
|
|
80
|
+
response: perf.responseEnd - perf.responseStart, // Response Time (Download)
|
|
85
81
|
// Frontend
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
//
|
|
89
|
-
dom_load: perf.domContentLoadedEventEnd - perf.responseEnd,
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
page_load: perf.loadEventStart,
|
|
82
|
+
render: perf.domComplete - perf.domContentLoadedEventEnd, // Browser rendering the HTML time
|
|
83
|
+
dom_load: perf.domContentLoadedEventEnd - perf.responseEnd, // DOM loading timing
|
|
84
|
+
page_load: perf.loadEventStart, // Page load time
|
|
92
85
|
// Backend
|
|
93
|
-
// @ts-ignore
|
|
94
86
|
ttfb: perf.responseStart - perf.requestStart,
|
|
95
87
|
};
|
|
96
88
|
}
|
|
@@ -103,19 +95,6 @@ export class Lib {
|
|
|
103
95
|
};
|
|
104
96
|
this.sendRequest('hb', data);
|
|
105
97
|
}
|
|
106
|
-
checkIgnore(path) {
|
|
107
|
-
const ignore = this.pageViewsOptions?.ignore;
|
|
108
|
-
if (Array.isArray(ignore)) {
|
|
109
|
-
for (let i = 0; i < ignore.length; ++i) {
|
|
110
|
-
if (ignore[i] === path)
|
|
111
|
-
return true;
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
if (ignore[i] instanceof RegExp && ignore[i].test(path))
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
98
|
// Tracking path changes. If path changes -> calling this.trackPage method
|
|
120
99
|
trackPathChange() {
|
|
121
100
|
if (!this.pageData)
|
|
@@ -133,11 +112,7 @@ export class Lib {
|
|
|
133
112
|
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
134
113
|
// That method of getting previous page works for SPA websites
|
|
135
114
|
if (this.activePage) {
|
|
136
|
-
|
|
137
|
-
if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise) {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
return shouldIgnore ? null : this.activePage;
|
|
115
|
+
return this.activePage;
|
|
141
116
|
}
|
|
142
117
|
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
143
118
|
if (typeof URL === 'function') {
|
|
@@ -153,11 +128,7 @@ export class Lib {
|
|
|
153
128
|
if (host !== refHost) {
|
|
154
129
|
return null;
|
|
155
130
|
}
|
|
156
|
-
|
|
157
|
-
if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise) {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
return shouldIgnore ? null : pathname;
|
|
131
|
+
return pathname;
|
|
161
132
|
}
|
|
162
133
|
catch {
|
|
163
134
|
return null;
|
|
@@ -169,56 +140,45 @@ export class Lib {
|
|
|
169
140
|
if (!this.pageData)
|
|
170
141
|
return;
|
|
171
142
|
this.pageData.path = pg;
|
|
172
|
-
const shouldIgnore = this.checkIgnore(pg);
|
|
173
|
-
if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise)
|
|
174
|
-
return;
|
|
175
143
|
const perf = this.getPerformanceStats();
|
|
176
|
-
|
|
177
|
-
if (!this.pageViewsOptions?.noUserFlow) {
|
|
178
|
-
prev = this.getPreviousPage();
|
|
179
|
-
}
|
|
144
|
+
const prev = this.getPreviousPage();
|
|
180
145
|
this.activePage = pg;
|
|
181
|
-
this.submitPageView(
|
|
146
|
+
this.submitPageView(pg, prev, unique, perf, true);
|
|
182
147
|
}
|
|
183
|
-
submitPageView(pg, prev, unique, perf) {
|
|
184
|
-
const
|
|
148
|
+
submitPageView(pg, prev, unique, perf, evokeCallback) {
|
|
149
|
+
const privateData = {
|
|
185
150
|
pid: this.projectID,
|
|
151
|
+
perf,
|
|
152
|
+
unique,
|
|
153
|
+
};
|
|
154
|
+
const pvPayload = {
|
|
186
155
|
lc: getLocale(),
|
|
187
156
|
tz: getTimezone(),
|
|
188
157
|
ref: getReferrer(),
|
|
189
158
|
so: getUTMSource(),
|
|
190
159
|
me: getUTMMedium(),
|
|
191
160
|
ca: getUTMCampaign(),
|
|
192
|
-
unique,
|
|
193
161
|
pg,
|
|
194
|
-
perf,
|
|
195
162
|
prev,
|
|
196
163
|
};
|
|
197
|
-
this.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
164
|
+
if (evokeCallback && this.pageViewsOptions?.callback) {
|
|
165
|
+
const callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
166
|
+
if (callbackResult === false) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (callbackResult && typeof callbackResult === 'object') {
|
|
170
|
+
Object.assign(pvPayload, callbackResult);
|
|
171
|
+
}
|
|
202
172
|
}
|
|
173
|
+
Object.assign(pvPayload, privateData);
|
|
174
|
+
this.sendRequest('', pvPayload);
|
|
203
175
|
}
|
|
204
176
|
canTrack() {
|
|
205
|
-
if (this.options?.disabled
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
this.debug('Tracking disabled: script does not run in browser environment.');
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
if (this.options?.respectDNT && window.navigator?.doNotTrack === '1') {
|
|
214
|
-
this.debug('Tracking disabled: respecting user\'s \'Do Not Track\' preference.');
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
if (!this.options?.debug && isLocalhost()) {
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
if (isAutomated()) {
|
|
221
|
-
this.debug('Tracking disabled: navigation is automated by WebDriver.');
|
|
177
|
+
if (this.options?.disabled ||
|
|
178
|
+
!isInBrowser() ||
|
|
179
|
+
(this.options?.respectDNT && window.navigator?.doNotTrack === '1') ||
|
|
180
|
+
(!this.options?.devMode && isLocalhost()) ||
|
|
181
|
+
isAutomated()) {
|
|
222
182
|
return false;
|
|
223
183
|
}
|
|
224
184
|
return true;
|
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,
|
|
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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AAW,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,WAAW,CAAC,IAAY,EAAE,IAAY;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,IAAI,gBAAgB,CAAA;QACrD,MAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAA;QAChC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,IAAI,EAAE,EAAE,IAAI,CAAC,CAAA;QACzC,GAAG,CAAC,gBAAgB,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAA;QACxD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IAChC,CAAC;CACF"}
|
package/dist/esnext/index.js
CHANGED
package/dist/esnext/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAgE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAE7G,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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,CAAA;AAE9D,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAA;AAElE;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAiB,EAAU,EAAE;IACnD,IAAI,MAAM,GAAG,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAA;IAEpC,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAC5C,MAAM,UAAU,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAA;QACzF,MAAM,IAAI,UAAU,CAAA;IACtB,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAC5C,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QAClG,MAAM,IAAI,YAAY,CAAA;IACxB,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
package/dist/swetrix.cjs.js
CHANGED
|
@@ -114,7 +114,7 @@ var Lib = /** @class */ (function () {
|
|
|
114
114
|
if (!this.canTrack()) {
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
|
-
var data = __assign({ pid: this.projectID, pg: this.activePage, lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() }
|
|
117
|
+
var data = __assign(__assign({}, event), { pid: this.projectID, pg: this.activePage, lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() });
|
|
118
118
|
this.sendRequest('custom', data);
|
|
119
119
|
};
|
|
120
120
|
Lib.prototype.trackPageViews = function (options) {
|
|
@@ -125,14 +125,12 @@ var Lib = /** @class */ (function () {
|
|
|
125
125
|
return this.pageData.actions;
|
|
126
126
|
}
|
|
127
127
|
this.pageViewsOptions = options;
|
|
128
|
-
var
|
|
128
|
+
var interval;
|
|
129
129
|
if (!(options === null || options === void 0 ? void 0 : options.unique)) {
|
|
130
130
|
interval = setInterval(this.trackPathChange, 2000);
|
|
131
131
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
hbInterval = setInterval(this.heartbeat, 28000);
|
|
135
|
-
}
|
|
132
|
+
setTimeout(this.heartbeat, 3000);
|
|
133
|
+
var hbInterval = setInterval(this.heartbeat, 28000);
|
|
136
134
|
var path = getPath({
|
|
137
135
|
hash: options === null || options === void 0 ? void 0 : options.hash,
|
|
138
136
|
search: options === null || options === void 0 ? void 0 : options.search,
|
|
@@ -161,23 +159,17 @@ var Lib = /** @class */ (function () {
|
|
|
161
159
|
this.perfStatsCollected = true;
|
|
162
160
|
return {
|
|
163
161
|
// Network
|
|
164
|
-
//
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
// @ts-ignore
|
|
171
|
-
response: perf.responseEnd - perf.responseStart,
|
|
162
|
+
dns: perf.domainLookupEnd - perf.domainLookupStart, // DNS Resolution
|
|
163
|
+
tls: perf.secureConnectionStart ? perf.requestStart - perf.secureConnectionStart : 0, // TLS Setup; checking if secureConnectionStart is not 0 (it's 0 for non-https websites)
|
|
164
|
+
conn: perf.secureConnectionStart
|
|
165
|
+
? perf.secureConnectionStart - perf.connectStart
|
|
166
|
+
: perf.connectEnd - perf.connectStart, // Connection time
|
|
167
|
+
response: perf.responseEnd - perf.responseStart, // Response Time (Download)
|
|
172
168
|
// Frontend
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
//
|
|
176
|
-
dom_load: perf.domContentLoadedEventEnd - perf.responseEnd,
|
|
177
|
-
// @ts-ignore
|
|
178
|
-
page_load: perf.loadEventStart,
|
|
169
|
+
render: perf.domComplete - perf.domContentLoadedEventEnd, // Browser rendering the HTML time
|
|
170
|
+
dom_load: perf.domContentLoadedEventEnd - perf.responseEnd, // DOM loading timing
|
|
171
|
+
page_load: perf.loadEventStart, // Page load time
|
|
179
172
|
// Backend
|
|
180
|
-
// @ts-ignore
|
|
181
173
|
ttfb: perf.responseStart - perf.requestStart,
|
|
182
174
|
};
|
|
183
175
|
};
|
|
@@ -191,20 +183,6 @@ var Lib = /** @class */ (function () {
|
|
|
191
183
|
};
|
|
192
184
|
this.sendRequest('hb', data);
|
|
193
185
|
};
|
|
194
|
-
Lib.prototype.checkIgnore = function (path) {
|
|
195
|
-
var _a;
|
|
196
|
-
var ignore = (_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.ignore;
|
|
197
|
-
if (Array.isArray(ignore)) {
|
|
198
|
-
for (var i = 0; i < ignore.length; ++i) {
|
|
199
|
-
if (ignore[i] === path)
|
|
200
|
-
return true;
|
|
201
|
-
// @ts-ignore
|
|
202
|
-
if (ignore[i] instanceof RegExp && ignore[i].test(path))
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return false;
|
|
207
|
-
};
|
|
208
186
|
// Tracking path changes. If path changes -> calling this.trackPage method
|
|
209
187
|
Lib.prototype.trackPathChange = function () {
|
|
210
188
|
var _a, _b;
|
|
@@ -220,15 +198,10 @@ var Lib = /** @class */ (function () {
|
|
|
220
198
|
}
|
|
221
199
|
};
|
|
222
200
|
Lib.prototype.getPreviousPage = function () {
|
|
223
|
-
var _a, _b;
|
|
224
201
|
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
225
202
|
// That method of getting previous page works for SPA websites
|
|
226
203
|
if (this.activePage) {
|
|
227
|
-
|
|
228
|
-
if (shouldIgnore && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.doNotAnonymise)) {
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
return shouldIgnore ? null : this.activePage;
|
|
204
|
+
return this.activePage;
|
|
232
205
|
}
|
|
233
206
|
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
234
207
|
if (typeof URL === 'function') {
|
|
@@ -244,76 +217,60 @@ var Lib = /** @class */ (function () {
|
|
|
244
217
|
if (host !== refHost) {
|
|
245
218
|
return null;
|
|
246
219
|
}
|
|
247
|
-
|
|
248
|
-
if (shouldIgnore && ((_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.doNotAnonymise)) {
|
|
249
|
-
return null;
|
|
250
|
-
}
|
|
251
|
-
return shouldIgnore ? null : pathname;
|
|
220
|
+
return pathname;
|
|
252
221
|
}
|
|
253
|
-
catch (
|
|
222
|
+
catch (_a) {
|
|
254
223
|
return null;
|
|
255
224
|
}
|
|
256
225
|
}
|
|
257
226
|
return null;
|
|
258
227
|
};
|
|
259
228
|
Lib.prototype.trackPage = function (pg, unique) {
|
|
260
|
-
var _a, _b;
|
|
261
229
|
if (unique === void 0) { unique = false; }
|
|
262
230
|
if (!this.pageData)
|
|
263
231
|
return;
|
|
264
232
|
this.pageData.path = pg;
|
|
265
|
-
var shouldIgnore = this.checkIgnore(pg);
|
|
266
|
-
if (shouldIgnore && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.doNotAnonymise))
|
|
267
|
-
return;
|
|
268
233
|
var perf = this.getPerformanceStats();
|
|
269
|
-
var prev;
|
|
270
|
-
if (!((_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.noUserFlow)) {
|
|
271
|
-
prev = this.getPreviousPage();
|
|
272
|
-
}
|
|
234
|
+
var prev = this.getPreviousPage();
|
|
273
235
|
this.activePage = pg;
|
|
274
|
-
this.submitPageView(
|
|
236
|
+
this.submitPageView(pg, prev, unique, perf, true);
|
|
275
237
|
};
|
|
276
|
-
Lib.prototype.submitPageView = function (pg, prev, unique, perf) {
|
|
277
|
-
var
|
|
238
|
+
Lib.prototype.submitPageView = function (pg, prev, unique, perf, evokeCallback) {
|
|
239
|
+
var _a;
|
|
240
|
+
var privateData = {
|
|
278
241
|
pid: this.projectID,
|
|
242
|
+
perf: perf,
|
|
243
|
+
unique: unique,
|
|
244
|
+
};
|
|
245
|
+
var pvPayload = {
|
|
279
246
|
lc: getLocale(),
|
|
280
247
|
tz: getTimezone(),
|
|
281
248
|
ref: getReferrer(),
|
|
282
249
|
so: getUTMSource(),
|
|
283
250
|
me: getUTMMedium(),
|
|
284
251
|
ca: getUTMCampaign(),
|
|
285
|
-
unique: unique,
|
|
286
252
|
pg: pg,
|
|
287
|
-
perf: perf,
|
|
288
253
|
prev: prev,
|
|
289
254
|
};
|
|
290
|
-
this.
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
255
|
+
if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
|
|
256
|
+
var callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
257
|
+
if (callbackResult === false) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (callbackResult && typeof callbackResult === 'object') {
|
|
261
|
+
Object.assign(pvPayload, callbackResult);
|
|
262
|
+
}
|
|
296
263
|
}
|
|
264
|
+
Object.assign(pvPayload, privateData);
|
|
265
|
+
this.sendRequest('', pvPayload);
|
|
297
266
|
};
|
|
298
267
|
Lib.prototype.canTrack = function () {
|
|
299
268
|
var _a, _b, _c, _d;
|
|
300
|
-
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.disabled)
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
this.debug('Tracking disabled: script does not run in browser environment.');
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
if (((_b = this.options) === null || _b === void 0 ? void 0 : _b.respectDNT) && ((_c = window.navigator) === null || _c === void 0 ? void 0 : _c.doNotTrack) === '1') {
|
|
309
|
-
this.debug('Tracking disabled: respecting user\'s \'Do Not Track\' preference.');
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
if (!((_d = this.options) === null || _d === void 0 ? void 0 : _d.debug) && isLocalhost()) {
|
|
313
|
-
return false;
|
|
314
|
-
}
|
|
315
|
-
if (isAutomated()) {
|
|
316
|
-
this.debug('Tracking disabled: navigation is automated by WebDriver.');
|
|
269
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.disabled) ||
|
|
270
|
+
!isInBrowser() ||
|
|
271
|
+
(((_b = this.options) === null || _b === void 0 ? void 0 : _b.respectDNT) && ((_c = window.navigator) === null || _c === void 0 ? void 0 : _c.doNotTrack) === '1') ||
|
|
272
|
+
(!((_d = this.options) === null || _d === void 0 ? void 0 : _d.devMode) && isLocalhost()) ||
|
|
273
|
+
isAutomated()) {
|
|
317
274
|
return false;
|
|
318
275
|
}
|
|
319
276
|
return true;
|