swetrix 2.3.1 → 3.0.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/.prettierrc.js +13 -0
- package/dist/esnext/Lib.d.ts +42 -13
- package/dist/esnext/Lib.js +49 -80
- package/dist/esnext/Lib.js.map +1 -1
- package/dist/esnext/index.d.ts +10 -0
- package/dist/esnext/index.js +15 -1
- package/dist/esnext/index.js.map +1 -1
- package/dist/esnext/utils.d.ts +20 -1
- package/dist/esnext/utils.js +27 -3
- package/dist/esnext/utils.js.map +1 -1
- package/dist/swetrix.cjs.js +94 -88
- package/dist/swetrix.es5.js +94 -89
- package/dist/swetrix.js +1 -1
- package/dist/swetrix.orig.js +94 -88
- package/package.json +5 -5
- package/src/Lib.ts +110 -99
- package/src/index.ts +16 -3
- package/src/utils.ts +35 -3
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;
|
|
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,25 @@ 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
|
-
/**
|
|
56
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Set to `true` to enable hash-based routing.
|
|
71
|
+
* For example if you have pages like /#/path or want to track pages like /path#hash
|
|
72
|
+
*/
|
|
73
|
+
hash?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Set to `true` to enable search-based routing.
|
|
76
|
+
* For example if you have pages like /path?search
|
|
77
|
+
*/
|
|
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;
|
|
57
86
|
}
|
|
58
87
|
export declare const defaultPageActions: {
|
|
59
88
|
stop(): void;
|
|
@@ -68,13 +97,13 @@ export declare class Lib {
|
|
|
68
97
|
constructor(projectID: string, options?: LibOptions | undefined);
|
|
69
98
|
track(event: TrackEventOptions): void;
|
|
70
99
|
trackPageViews(options?: PageViewsOptions): PageActions;
|
|
71
|
-
getPerformanceStats():
|
|
100
|
+
getPerformanceStats(): IPerfPayload | {};
|
|
72
101
|
private heartbeat;
|
|
73
|
-
private checkIgnore;
|
|
74
102
|
private trackPathChange;
|
|
75
103
|
private getPreviousPage;
|
|
76
104
|
private trackPage;
|
|
77
|
-
|
|
105
|
+
submitPageView(pg: string, prev: string | null | undefined, unique: boolean, perf: IPerfPayload | {}, evokeCallback?: boolean): void;
|
|
78
106
|
private canTrack;
|
|
79
107
|
private sendRequest;
|
|
80
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,15 +39,16 @@ 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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
setTimeout(this.heartbeat, 3000);
|
|
47
|
+
const hbInterval = setInterval(this.heartbeat, 28000);
|
|
48
|
+
const path = getPath({
|
|
49
|
+
hash: options?.hash,
|
|
50
|
+
search: options?.search,
|
|
51
|
+
});
|
|
51
52
|
this.pageData = {
|
|
52
53
|
path,
|
|
53
54
|
actions: {
|
|
@@ -71,23 +72,17 @@ export class Lib {
|
|
|
71
72
|
this.perfStatsCollected = true;
|
|
72
73
|
return {
|
|
73
74
|
// Network
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
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)
|
|
82
81
|
// Frontend
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
//
|
|
86
|
-
dom_load: perf.domContentLoadedEventEnd - perf.responseEnd,
|
|
87
|
-
// @ts-ignore
|
|
88
|
-
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
|
|
89
85
|
// Backend
|
|
90
|
-
// @ts-ignore
|
|
91
86
|
ttfb: perf.responseStart - perf.requestStart,
|
|
92
87
|
};
|
|
93
88
|
}
|
|
@@ -100,24 +95,14 @@ export class Lib {
|
|
|
100
95
|
};
|
|
101
96
|
this.sendRequest('hb', data);
|
|
102
97
|
}
|
|
103
|
-
checkIgnore(path) {
|
|
104
|
-
const ignore = this.pageViewsOptions?.ignore;
|
|
105
|
-
if (Array.isArray(ignore)) {
|
|
106
|
-
for (let i = 0; i < ignore.length; ++i) {
|
|
107
|
-
if (ignore[i] === path)
|
|
108
|
-
return true;
|
|
109
|
-
// @ts-ignore
|
|
110
|
-
if (ignore[i] instanceof RegExp && ignore[i].test(path))
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
98
|
// Tracking path changes. If path changes -> calling this.trackPage method
|
|
117
99
|
trackPathChange() {
|
|
118
100
|
if (!this.pageData)
|
|
119
101
|
return;
|
|
120
|
-
const newPath = getPath(
|
|
102
|
+
const newPath = getPath({
|
|
103
|
+
hash: this.pageViewsOptions?.hash,
|
|
104
|
+
search: this.pageViewsOptions?.search,
|
|
105
|
+
});
|
|
121
106
|
const { path } = this.pageData;
|
|
122
107
|
if (path !== newPath) {
|
|
123
108
|
this.trackPage(newPath, false);
|
|
@@ -127,11 +112,7 @@ export class Lib {
|
|
|
127
112
|
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
128
113
|
// That method of getting previous page works for SPA websites
|
|
129
114
|
if (this.activePage) {
|
|
130
|
-
|
|
131
|
-
if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
return shouldIgnore ? null : this.activePage;
|
|
115
|
+
return this.activePage;
|
|
135
116
|
}
|
|
136
117
|
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
137
118
|
if (typeof URL === 'function') {
|
|
@@ -147,11 +128,7 @@ export class Lib {
|
|
|
147
128
|
if (host !== refHost) {
|
|
148
129
|
return null;
|
|
149
130
|
}
|
|
150
|
-
|
|
151
|
-
if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise) {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
return shouldIgnore ? null : pathname;
|
|
131
|
+
return pathname;
|
|
155
132
|
}
|
|
156
133
|
catch {
|
|
157
134
|
return null;
|
|
@@ -163,53 +140,45 @@ export class Lib {
|
|
|
163
140
|
if (!this.pageData)
|
|
164
141
|
return;
|
|
165
142
|
this.pageData.path = pg;
|
|
166
|
-
const shouldIgnore = this.checkIgnore(pg);
|
|
167
|
-
if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise)
|
|
168
|
-
return;
|
|
169
143
|
const perf = this.getPerformanceStats();
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
144
|
+
const prev = this.getPreviousPage();
|
|
145
|
+
this.activePage = pg;
|
|
146
|
+
this.submitPageView(pg, prev, unique, perf, true);
|
|
147
|
+
}
|
|
148
|
+
submitPageView(pg, prev, unique, perf, evokeCallback) {
|
|
149
|
+
const privateData = {
|
|
175
150
|
pid: this.projectID,
|
|
151
|
+
perf,
|
|
152
|
+
unique,
|
|
153
|
+
};
|
|
154
|
+
const pvPayload = {
|
|
176
155
|
lc: getLocale(),
|
|
177
156
|
tz: getTimezone(),
|
|
178
157
|
ref: getReferrer(),
|
|
179
158
|
so: getUTMSource(),
|
|
180
159
|
me: getUTMMedium(),
|
|
181
160
|
ca: getUTMCampaign(),
|
|
182
|
-
|
|
183
|
-
pg: shouldIgnore ? null : pg,
|
|
184
|
-
perf,
|
|
161
|
+
pg,
|
|
185
162
|
prev,
|
|
186
163
|
};
|
|
187
|
-
this.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
+
}
|
|
193
172
|
}
|
|
173
|
+
Object.assign(pvPayload, privateData);
|
|
174
|
+
this.sendRequest('', pvPayload);
|
|
194
175
|
}
|
|
195
176
|
canTrack() {
|
|
196
|
-
if (this.options?.disabled
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
this.debug('Tracking disabled: script does not run in browser environment.');
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
if (this.options?.respectDNT && window.navigator?.doNotTrack === '1') {
|
|
205
|
-
this.debug('Tracking disabled: respecting user\'s \'Do Not Track\' preference.');
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
if (!this.options?.debug && isLocalhost()) {
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
if (isAutomated()) {
|
|
212
|
-
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()) {
|
|
213
182
|
return false;
|
|
214
183
|
}
|
|
215
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,EACX,WAAW,EACX,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,OAAO,GACR,MAAM,SAAS,CAAA;AA0GhB,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,IAAI,KAAI,CAAC;CACV,CAAA;AAED,MAAM,gBAAgB,GAAG,6BAA6B,CAAA;AAEtD,MAAM,OAAO,GAAG;IAMd,YAAoB,SAAiB,EAAU,OAAoB;QAA/C,cAAS,GAAT,SAAS,CAAQ;QAAU,YAAO,GAAP,OAAO,CAAa;QAL3D,aAAQ,GAAoB,IAAI,CAAA;QAChC,qBAAgB,GAAwC,IAAI,CAAA;QAC5D,uBAAkB,GAAY,KAAK,CAAA;QACnC,eAAU,GAAkB,IAAI,CAAA;QAGtC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACtD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;IAED,KAAK,CAAC,KAAwB;QAC5B,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;YACrB,OAAM;QACR,CAAC;QAED,MAAM,IAAI,GAAG;YACX,GAAG,KAAK;YACR,GAAG,EAAE,IAAI,CAAC,SAAS;YACnB,EAAE,EAAE,IAAI,CAAC,UAAU;YACnB,EAAE,EAAE,SAAS,EAAE;YACf,EAAE,EAAE,WAAW,EAAE;YACjB,GAAG,EAAE,WAAW,EAAE;YAClB,EA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AC;gBACzD,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;YAC1C,CAAC;QACH,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;QAErC,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,SAAS,CAAC,CAAA;IACjC,CAAC;IAEO,QAAQ;QACd,IACE,IAAI,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,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.d.ts
CHANGED
|
@@ -25,3 +25,13 @@ export declare function track(event: TrackEventOptions): void;
|
|
|
25
25
|
* @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
|
|
26
26
|
*/
|
|
27
27
|
export declare function trackViews(options?: PageViewsOptions): Promise<PageActions>;
|
|
28
|
+
/**
|
|
29
|
+
* This function is used to manually track a page view event.
|
|
30
|
+
* It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
|
|
31
|
+
*
|
|
32
|
+
* @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
33
|
+
* @param prev Path of the previous page.
|
|
34
|
+
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
35
|
+
* @returns void
|
|
36
|
+
*/
|
|
37
|
+
export declare function trackPageview(path: string, prev?: string, unique?: boolean): void;
|
package/dist/esnext/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lib, defaultPageActions
|
|
1
|
+
import { Lib, defaultPageActions } from './Lib';
|
|
2
2
|
export let LIB_INSTANCE = null;
|
|
3
3
|
/**
|
|
4
4
|
* Initialise the tracking library instance (other methods won't work if the library is not initialised).
|
|
@@ -51,4 +51,18 @@ export function trackViews(options) {
|
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* This function is used to manually track a page view event.
|
|
56
|
+
* It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
|
|
57
|
+
*
|
|
58
|
+
* @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
59
|
+
* @param prev Path of the previous page.
|
|
60
|
+
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
61
|
+
* @returns void
|
|
62
|
+
*/
|
|
63
|
+
export function trackPageview(path, prev, unique) {
|
|
64
|
+
if (!LIB_INSTANCE)
|
|
65
|
+
return;
|
|
66
|
+
LIB_INSTANCE.submitPageView(path, prev || null, Boolean(unique), {});
|
|
67
|
+
}
|
|
54
68
|
//# sourceMappingURL=index.js.map
|
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,OAA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I,EAAE,IAAI,IAAI,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;AACtE,CAAC"}
|
package/dist/esnext/utils.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
interface IGetPath {
|
|
2
|
+
hash?: boolean;
|
|
3
|
+
search?: boolean;
|
|
4
|
+
}
|
|
1
5
|
export declare const isInBrowser: () => boolean;
|
|
2
6
|
export declare const isLocalhost: () => boolean;
|
|
3
7
|
export declare const isAutomated: () => boolean;
|
|
@@ -7,4 +11,19 @@ export declare const getReferrer: () => string | undefined;
|
|
|
7
11
|
export declare const getUTMSource: () => string | undefined;
|
|
8
12
|
export declare const getUTMMedium: () => string | undefined;
|
|
9
13
|
export declare const getUTMCampaign: () => string | undefined;
|
|
10
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Function used to track the current page (path) of the application.
|
|
16
|
+
* Will work in cases where the path looks like:
|
|
17
|
+
* - /path
|
|
18
|
+
* - /#/path
|
|
19
|
+
* - /path?search
|
|
20
|
+
* - /path?search#hash
|
|
21
|
+
* - /path#hash?search
|
|
22
|
+
*
|
|
23
|
+
* @param options - Options for the function.
|
|
24
|
+
* @param options.hash - Whether to trigger on hash change.
|
|
25
|
+
* @param options.search - Whether to trigger on search change.
|
|
26
|
+
* @returns The path of the current page.
|
|
27
|
+
*/
|
|
28
|
+
export declare const getPath: (options: IGetPath) => string;
|
|
29
|
+
export {};
|
package/dist/esnext/utils.js
CHANGED
|
@@ -31,8 +31,32 @@ export const getReferrer = () => {
|
|
|
31
31
|
export const getUTMSource = () => findInSearch(utmSourceRegex);
|
|
32
32
|
export const getUTMMedium = () => findInSearch(utmMediumRegex);
|
|
33
33
|
export const getUTMCampaign = () => findInSearch(utmCampaignRegex);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Function used to track the current page (path) of the application.
|
|
36
|
+
* Will work in cases where the path looks like:
|
|
37
|
+
* - /path
|
|
38
|
+
* - /#/path
|
|
39
|
+
* - /path?search
|
|
40
|
+
* - /path?search#hash
|
|
41
|
+
* - /path#hash?search
|
|
42
|
+
*
|
|
43
|
+
* @param options - Options for the function.
|
|
44
|
+
* @param options.hash - Whether to trigger on hash change.
|
|
45
|
+
* @param options.search - Whether to trigger on search change.
|
|
46
|
+
* @returns The path of the current page.
|
|
47
|
+
*/
|
|
48
|
+
export const getPath = (options) => {
|
|
49
|
+
let result = location.pathname || '';
|
|
50
|
+
if (options.hash) {
|
|
51
|
+
const hashIndex = location.hash.indexOf('?');
|
|
52
|
+
const hashString = hashIndex > -1 ? location.hash.substring(0, hashIndex) : location.hash;
|
|
53
|
+
result += hashString;
|
|
54
|
+
}
|
|
55
|
+
if (options.search) {
|
|
56
|
+
const hashIndex = location.hash.indexOf('?');
|
|
57
|
+
const searchString = location.search || (hashIndex > -1 ? location.hash.substring(hashIndex) : '');
|
|
58
|
+
result += searchString;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
37
61
|
};
|
|
38
62
|
//# sourceMappingURL=utils.js.map
|
package/dist/esnext/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAKA,MAAM,YAAY,GAAG,CAAC,GAAW,EAAsB,EAAE;IACvD,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACtC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,CAAA;AACrC,CAAC,CAAA;AAED,MAAM,cAAc,GAAG,sCAAsC,CAAA;AAC7D,MAAM,gBAAgB,GAAG,6BAA6B,CAAA;AACtD,MAAM,cAAc,GAAG,2BAA2B,CAAA;AAElD,MAAM,CAAC,MAAM,WA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