swetrix 2.1.0 → 2.2.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/.github/funding.yml +1 -0
- package/dist/esnext/Lib.d.ts +3 -0
- package/dist/esnext/Lib.js +40 -1
- package/dist/esnext/Lib.js.map +1 -1
- package/dist/swetrix.cjs.js +41 -1
- package/dist/swetrix.es5.js +41 -1
- package/dist/swetrix.js +1 -1
- package/dist/swetrix.orig.js +41 -1
- package/package.json +6 -6
- package/src/Lib.ts +54 -1
package/.github/funding.yml
CHANGED
package/dist/esnext/Lib.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export interface PageViewsOptions {
|
|
|
46
46
|
noHeartbeat?: boolean;
|
|
47
47
|
/** Send Heartbeat requests when the website tab is not active in the browser. */
|
|
48
48
|
heartbeatOnBackground?: boolean;
|
|
49
|
+
/** Disable user-flow */
|
|
50
|
+
noUserFlow?: boolean;
|
|
49
51
|
}
|
|
50
52
|
export declare const defaultPageActions: {
|
|
51
53
|
stop(): void;
|
|
@@ -64,6 +66,7 @@ export declare class Lib {
|
|
|
64
66
|
private heartbeat;
|
|
65
67
|
private checkIgnore;
|
|
66
68
|
private trackPathChange;
|
|
69
|
+
private getPreviousPage;
|
|
67
70
|
private trackPage;
|
|
68
71
|
private debug;
|
|
69
72
|
private canTrack;
|
package/dist/esnext/Lib.js
CHANGED
|
@@ -123,14 +123,51 @@ export class Lib {
|
|
|
123
123
|
this.trackPage(newPath, false);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
+
getPreviousPage() {
|
|
127
|
+
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
128
|
+
// That method of getting previous page works for SPA websites
|
|
129
|
+
if (this.activePage) {
|
|
130
|
+
if (this.checkIgnore(this.activePage)) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
return this.activePage;
|
|
134
|
+
}
|
|
135
|
+
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
136
|
+
if (typeof URL === 'function') {
|
|
137
|
+
// That method of getting previous page works for websites with page reloads
|
|
138
|
+
const referrer = getReferrer();
|
|
139
|
+
if (!referrer) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
const { host } = location;
|
|
143
|
+
try {
|
|
144
|
+
const url = new URL(referrer);
|
|
145
|
+
const { host: refHost, pathname } = url;
|
|
146
|
+
if (host !== refHost) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
if (this.checkIgnore(pathname)) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
return pathname;
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
126
160
|
trackPage(pg, unique = false) {
|
|
127
161
|
if (!this.pageData)
|
|
128
162
|
return;
|
|
129
163
|
this.pageData.path = pg;
|
|
130
164
|
if (this.checkIgnore(pg))
|
|
131
165
|
return;
|
|
132
|
-
this.activePage = pg;
|
|
133
166
|
const perf = this.getPerformanceStats();
|
|
167
|
+
let prev;
|
|
168
|
+
if (!this.pageViewsOptions?.noUserFlow) {
|
|
169
|
+
prev = this.getPreviousPage();
|
|
170
|
+
}
|
|
134
171
|
const data = {
|
|
135
172
|
pid: this.projectID,
|
|
136
173
|
lc: getLocale(),
|
|
@@ -142,7 +179,9 @@ export class Lib {
|
|
|
142
179
|
unique,
|
|
143
180
|
pg,
|
|
144
181
|
perf,
|
|
182
|
+
prev,
|
|
145
183
|
};
|
|
184
|
+
this.activePage = pg;
|
|
146
185
|
this.sendRequest('', data);
|
|
147
186
|
}
|
|
148
187
|
debug(message) {
|
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,EAAE,WAAW,EAAE,WA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,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IAChC,CAAC;CACF"}
|
package/dist/swetrix.cjs.js
CHANGED
|
@@ -183,15 +183,53 @@ var Lib = /** @class */ (function () {
|
|
|
183
183
|
this.trackPage(newPath, false);
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
|
+
Lib.prototype.getPreviousPage = function () {
|
|
187
|
+
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
188
|
+
// That method of getting previous page works for SPA websites
|
|
189
|
+
if (this.activePage) {
|
|
190
|
+
if (this.checkIgnore(this.activePage)) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
return this.activePage;
|
|
194
|
+
}
|
|
195
|
+
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
196
|
+
if (typeof URL === 'function') {
|
|
197
|
+
// That method of getting previous page works for websites with page reloads
|
|
198
|
+
var referrer = getReferrer();
|
|
199
|
+
if (!referrer) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
var host = location.host;
|
|
203
|
+
try {
|
|
204
|
+
var url = new URL(referrer);
|
|
205
|
+
var refHost = url.host, pathname = url.pathname;
|
|
206
|
+
if (host !== refHost) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
if (this.checkIgnore(pathname)) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return pathname;
|
|
213
|
+
}
|
|
214
|
+
catch (_a) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
};
|
|
186
220
|
Lib.prototype.trackPage = function (pg, unique) {
|
|
221
|
+
var _a;
|
|
187
222
|
if (unique === void 0) { unique = false; }
|
|
188
223
|
if (!this.pageData)
|
|
189
224
|
return;
|
|
190
225
|
this.pageData.path = pg;
|
|
191
226
|
if (this.checkIgnore(pg))
|
|
192
227
|
return;
|
|
193
|
-
this.activePage = pg;
|
|
194
228
|
var perf = this.getPerformanceStats();
|
|
229
|
+
var prev;
|
|
230
|
+
if (!((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.noUserFlow)) {
|
|
231
|
+
prev = this.getPreviousPage();
|
|
232
|
+
}
|
|
195
233
|
var data = {
|
|
196
234
|
pid: this.projectID,
|
|
197
235
|
lc: getLocale(),
|
|
@@ -203,7 +241,9 @@ var Lib = /** @class */ (function () {
|
|
|
203
241
|
unique: unique,
|
|
204
242
|
pg: pg,
|
|
205
243
|
perf: perf,
|
|
244
|
+
prev: prev,
|
|
206
245
|
};
|
|
246
|
+
this.activePage = pg;
|
|
207
247
|
this.sendRequest('', data);
|
|
208
248
|
};
|
|
209
249
|
Lib.prototype.debug = function (message) {
|
package/dist/swetrix.es5.js
CHANGED
|
@@ -179,15 +179,53 @@ var Lib = /** @class */ (function () {
|
|
|
179
179
|
this.trackPage(newPath, false);
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
|
+
Lib.prototype.getPreviousPage = function () {
|
|
183
|
+
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
184
|
+
// That method of getting previous page works for SPA websites
|
|
185
|
+
if (this.activePage) {
|
|
186
|
+
if (this.checkIgnore(this.activePage)) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
return this.activePage;
|
|
190
|
+
}
|
|
191
|
+
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
192
|
+
if (typeof URL === 'function') {
|
|
193
|
+
// That method of getting previous page works for websites with page reloads
|
|
194
|
+
var referrer = getReferrer();
|
|
195
|
+
if (!referrer) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
var host = location.host;
|
|
199
|
+
try {
|
|
200
|
+
var url = new URL(referrer);
|
|
201
|
+
var refHost = url.host, pathname = url.pathname;
|
|
202
|
+
if (host !== refHost) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
if (this.checkIgnore(pathname)) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
return pathname;
|
|
209
|
+
}
|
|
210
|
+
catch (_a) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
};
|
|
182
216
|
Lib.prototype.trackPage = function (pg, unique) {
|
|
217
|
+
var _a;
|
|
183
218
|
if (unique === void 0) { unique = false; }
|
|
184
219
|
if (!this.pageData)
|
|
185
220
|
return;
|
|
186
221
|
this.pageData.path = pg;
|
|
187
222
|
if (this.checkIgnore(pg))
|
|
188
223
|
return;
|
|
189
|
-
this.activePage = pg;
|
|
190
224
|
var perf = this.getPerformanceStats();
|
|
225
|
+
var prev;
|
|
226
|
+
if (!((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.noUserFlow)) {
|
|
227
|
+
prev = this.getPreviousPage();
|
|
228
|
+
}
|
|
191
229
|
var data = {
|
|
192
230
|
pid: this.projectID,
|
|
193
231
|
lc: getLocale(),
|
|
@@ -199,7 +237,9 @@ var Lib = /** @class */ (function () {
|
|
|
199
237
|
unique: unique,
|
|
200
238
|
pg: pg,
|
|
201
239
|
perf: perf,
|
|
240
|
+
prev: prev,
|
|
202
241
|
};
|
|
242
|
+
this.activePage = pg;
|
|
203
243
|
this.sendRequest('', data);
|
|
204
244
|
};
|
|
205
245
|
Lib.prototype.debug = function (message) {
|
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(n){"use strict";function t(t){return(t=location.search.match(t))&&t[2]||void 0}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(n){"use strict";function t(t){return(t=location.search.match(t))&&t[2]||void 0}function a(){return void 0!==navigator.languages?navigator.languages[0]:navigator.language}function r(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(t){}}function s(){return document.referrer||void 0}function c(){return t(o)}function u(){return t(d)}function l(){return t(p)}function i(){return location.pathname||""}var e=function(){return(e=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},o=/[?&](ref|source|utm_source)=([^?&]+)/,p=/[?&](utm_campaign)=([^?&]+)/,d=/[?&](utm_medium)=([^?&]+)/,h={stop:function(){}},g=(f.prototype.track=function(t){this.canTrack()&&(t=e({pid:this.projectID,pg:this.activePage,lc:a(),tz:r(),ref:s(),so:c(),me:u(),ca:l()},t),this.sendRequest("custom",t))},f.prototype.trackPageViews=function(t){var e,n,o;return this.canTrack()?(this.pageData||(null!=(this.pageViewsOptions=t)&&t.unique||(n=setInterval(this.trackPathChange,2e3)),null!=t&&t.noHeartbeat||(setTimeout(this.heartbeat,3e3),e=setInterval(this.heartbeat,28e3)),o=i(),this.pageData={path:o,actions:{stop:function(){clearInterval(n),clearInterval(e)}}},this.trackPage(o,null==t?void 0:t.unique)),this.pageData.actions):h},f.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}):{}},f.prototype.heartbeat=function(){var t;(null!=(t=this.pageViewsOptions)&&t.heartbeatOnBackground||"hidden"!==document.visibilityState)&&(t={pid:this.projectID},this.sendRequest("hb",t))},f.prototype.checkIgnore=function(t){var e,n=null==(e=this.pageViewsOptions)?void 0:e.ignore;if(Array.isArray(n))for(var o=0;o<n.length;++o){if(n[o]===t)return!0;if(n[o]instanceof RegExp&&n[o].test(t))return!0}return!1},f.prototype.trackPathChange=function(){var t;this.pageData&&(t=i(),this.pageData.path!==t)&&this.trackPage(t,!1)},f.prototype.getPreviousPage=function(){if(this.activePage)return this.checkIgnore(this.activePage)?null:this.activePage;if("function"==typeof URL){var t=s();if(!t)return null;var e=location.host;try{var n=new URL(t),o=n.host,i=n.pathname;return e!==o?null:this.checkIgnore(i)?null:i}catch(t){}}return null},f.prototype.trackPage=function(t,e){var n,o,i;void 0===e&&(e=!1),this.pageData&&(this.pageData.path=t,this.checkIgnore(t)||(n=this.getPerformanceStats(),null!=(i=this.pageViewsOptions)&&i.noUserFlow||(o=this.getPreviousPage()),i={pid:this.projectID,lc:a(),tz:r(),ref:s(),so:c(),me:u(),ca:l(),unique:e,pg:t,perf:n,prev:o},this.activePage=t,this.sendRequest("",i)))},f.prototype.debug=function(t){var e;null!=(e=this.options)&&e.debug&&console.log("[Swetrix]",t)},f.prototype.canTrack=function(){var t;return null!=(t=this.options)&&t.disabled?(this.debug("Tracking disabled: the 'disabled' setting is set to true."),!1):"undefined"==typeof window?(this.debug("Tracking disabled: script does not run in browser environment."),!1):null!=(t=this.options)&&t.respectDNT&&"1"===(null==(t=window.navigator)?void 0:t.doNotTrack)?(this.debug("Tracking disabled: respecting user's 'Do Not Track' preference."),!1):!(!(null!=(t=this.options)&&t.debug||"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&&(this.debug("Tracking disabled: navigation is automated by WebDriver."),1))},f.prototype.sendRequest=function(t,e){var n=(null==(n=this.options)?void 0:n.apiURL)||"https://api.swetrix.com/log",o=new XMLHttpRequest;o.open("POST","".concat(n,"/").concat(t),!0),o.setRequestHeader("Content-Type","application/json"),o.send(JSON.stringify(e))},f);function f(t,e){this.projectID=t,this.options=e,this.pageData=null,this.pageViewsOptions=null,this.perfStatsCollected=!1,this.activePage=null,this.trackPathChange=this.trackPathChange.bind(this),this.heartbeat=this.heartbeat.bind(this)}n.LIB_INSTANCE=null,n.init=function(t,e){return n.LIB_INSTANCE||(n.LIB_INSTANCE=new g(t,e)),n.LIB_INSTANCE},n.track=function(t){n.LIB_INSTANCE&&n.LIB_INSTANCE.track(t)},n.trackViews=function(e){return new Promise(function(t){n.LIB_INSTANCE?"undefined"==typeof document||"complete"===document.readyState?t(n.LIB_INSTANCE.trackPageViews(e)):window.addEventListener("load",function(){t(n.LIB_INSTANCE.trackPageViews(e))}):t(h)})},Object.defineProperty(n,"__esModule",{value:!0})});
|
package/dist/swetrix.orig.js
CHANGED
|
@@ -185,15 +185,53 @@
|
|
|
185
185
|
this.trackPage(newPath, false);
|
|
186
186
|
}
|
|
187
187
|
};
|
|
188
|
+
Lib.prototype.getPreviousPage = function () {
|
|
189
|
+
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
190
|
+
// That method of getting previous page works for SPA websites
|
|
191
|
+
if (this.activePage) {
|
|
192
|
+
if (this.checkIgnore(this.activePage)) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
return this.activePage;
|
|
196
|
+
}
|
|
197
|
+
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
198
|
+
if (typeof URL === 'function') {
|
|
199
|
+
// That method of getting previous page works for websites with page reloads
|
|
200
|
+
var referrer = getReferrer();
|
|
201
|
+
if (!referrer) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
var host = location.host;
|
|
205
|
+
try {
|
|
206
|
+
var url = new URL(referrer);
|
|
207
|
+
var refHost = url.host, pathname = url.pathname;
|
|
208
|
+
if (host !== refHost) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
if (this.checkIgnore(pathname)) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
return pathname;
|
|
215
|
+
}
|
|
216
|
+
catch (_a) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
};
|
|
188
222
|
Lib.prototype.trackPage = function (pg, unique) {
|
|
223
|
+
var _a;
|
|
189
224
|
if (unique === void 0) { unique = false; }
|
|
190
225
|
if (!this.pageData)
|
|
191
226
|
return;
|
|
192
227
|
this.pageData.path = pg;
|
|
193
228
|
if (this.checkIgnore(pg))
|
|
194
229
|
return;
|
|
195
|
-
this.activePage = pg;
|
|
196
230
|
var perf = this.getPerformanceStats();
|
|
231
|
+
var prev;
|
|
232
|
+
if (!((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.noUserFlow)) {
|
|
233
|
+
prev = this.getPreviousPage();
|
|
234
|
+
}
|
|
197
235
|
var data = {
|
|
198
236
|
pid: this.projectID,
|
|
199
237
|
lc: getLocale(),
|
|
@@ -205,7 +243,9 @@
|
|
|
205
243
|
unique: unique,
|
|
206
244
|
pg: pg,
|
|
207
245
|
perf: perf,
|
|
246
|
+
prev: prev,
|
|
208
247
|
};
|
|
248
|
+
this.activePage = pg;
|
|
209
249
|
this.sendRequest('', data);
|
|
210
250
|
};
|
|
211
251
|
Lib.prototype.debug = function (message) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swetrix",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "The JavaScript analytics client for Swetrix Analytics",
|
|
5
5
|
"main": "dist/swetrix.cjs.js",
|
|
6
6
|
"module": "dist/swetrix.es5.js",
|
|
@@ -27,19 +27,19 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://swetrix.com/docs",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@types/node": "^18.
|
|
30
|
+
"@types/node": "^18.16.1",
|
|
31
31
|
"tslib": "^2.5.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@rollup/plugin-commonjs": "^24.0
|
|
35
|
-
"@rollup/plugin-node-resolve": "^15.0.
|
|
36
|
-
"rimraf": "^4.1
|
|
34
|
+
"@rollup/plugin-commonjs": "^24.1.0",
|
|
35
|
+
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
36
|
+
"rimraf": "^4.4.1",
|
|
37
37
|
"rollup": "^2.79.1",
|
|
38
38
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
39
39
|
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
40
40
|
"rollup-plugin-typescript2": "^0.34.1",
|
|
41
41
|
"rollup-plugin-uglify": "^6.0.4",
|
|
42
|
-
"typescript": "^
|
|
42
|
+
"typescript": "^5.0.4"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"prebuild": "rimraf dist",
|
package/src/Lib.ts
CHANGED
|
@@ -63,6 +63,9 @@ export interface PageViewsOptions {
|
|
|
63
63
|
|
|
64
64
|
/** Send Heartbeat requests when the website tab is not active in the browser. */
|
|
65
65
|
heartbeatOnBackground?: boolean
|
|
66
|
+
|
|
67
|
+
/** Disable user-flow */
|
|
68
|
+
noUserFlow?: boolean
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
export const defaultPageActions = {
|
|
@@ -212,15 +215,63 @@ export class Lib {
|
|
|
212
215
|
}
|
|
213
216
|
}
|
|
214
217
|
|
|
218
|
+
private getPreviousPage(): string | null {
|
|
219
|
+
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
220
|
+
// That method of getting previous page works for SPA websites
|
|
221
|
+
if (this.activePage) {
|
|
222
|
+
if (this.checkIgnore(this.activePage)) {
|
|
223
|
+
return null
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return this.activePage
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
230
|
+
if (typeof URL === 'function') {
|
|
231
|
+
// That method of getting previous page works for websites with page reloads
|
|
232
|
+
const referrer = getReferrer()
|
|
233
|
+
|
|
234
|
+
if (!referrer) {
|
|
235
|
+
return null
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const { host } = location
|
|
239
|
+
|
|
240
|
+
try {
|
|
241
|
+
const url = new URL(referrer)
|
|
242
|
+
const { host: refHost, pathname } = url
|
|
243
|
+
|
|
244
|
+
if (host !== refHost) {
|
|
245
|
+
return null
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (this.checkIgnore(pathname)) {
|
|
249
|
+
return null
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return pathname
|
|
253
|
+
} catch {
|
|
254
|
+
return null
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return null
|
|
259
|
+
}
|
|
260
|
+
|
|
215
261
|
private trackPage(pg: string, unique: boolean = false): void {
|
|
216
262
|
if (!this.pageData) return
|
|
217
263
|
this.pageData.path = pg
|
|
218
264
|
|
|
219
265
|
if (this.checkIgnore(pg)) return
|
|
220
266
|
|
|
221
|
-
this.activePage = pg
|
|
222
267
|
const perf = this.getPerformanceStats()
|
|
223
268
|
|
|
269
|
+
let prev
|
|
270
|
+
|
|
271
|
+
if (!this.pageViewsOptions?.noUserFlow) {
|
|
272
|
+
prev = this.getPreviousPage()
|
|
273
|
+
}
|
|
274
|
+
|
|
224
275
|
const data = {
|
|
225
276
|
pid: this.projectID,
|
|
226
277
|
lc: getLocale(),
|
|
@@ -232,8 +283,10 @@ export class Lib {
|
|
|
232
283
|
unique,
|
|
233
284
|
pg,
|
|
234
285
|
perf,
|
|
286
|
+
prev,
|
|
235
287
|
}
|
|
236
288
|
|
|
289
|
+
this.activePage = pg
|
|
237
290
|
this.sendRequest('', data)
|
|
238
291
|
}
|
|
239
292
|
|