swetrix 2.2.1 → 2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swetrix",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "The JavaScript analytics client for Swetrix Analytics",
5
5
  "main": "dist/swetrix.cjs.js",
6
6
  "module": "dist/swetrix.es5.js",
@@ -8,6 +8,13 @@
8
8
  "origbrowser": "dist/swetrix.orig.js",
9
9
  "esnext": "dist/esnext/index.js",
10
10
  "typings": "dist/esnext/index.d.ts",
11
+ "scripts": {
12
+ "prebuild": "rimraf dist",
13
+ "prepublish": "npm run build",
14
+ "build": "rollup -c && tsc -p tsconfig.esnext.json",
15
+ "start": "rollup -c -w",
16
+ "tsc": "tsc -p tsconfig.esnext.json"
17
+ },
11
18
  "keywords": [
12
19
  "swetrix",
13
20
  "analytics",
@@ -27,25 +34,18 @@
27
34
  },
28
35
  "homepage": "https://swetrix.com/docs",
29
36
  "dependencies": {
30
- "@types/node": "^18.16.1",
31
- "tslib": "^2.5.0"
37
+ "@types/node": "^20.5.9",
38
+ "tslib": "^2.6.2"
32
39
  },
33
40
  "devDependencies": {
34
- "@rollup/plugin-commonjs": "^24.1.0",
35
- "@rollup/plugin-node-resolve": "^15.0.2",
41
+ "@rollup/plugin-commonjs": "^25.0.4",
42
+ "@rollup/plugin-node-resolve": "^15.2.1",
36
43
  "rimraf": "^4.4.1",
37
44
  "rollup": "^2.79.1",
38
45
  "rollup-plugin-node-resolve": "^5.2.0",
39
46
  "rollup-plugin-sourcemaps": "^0.6.3",
40
- "rollup-plugin-typescript2": "^0.34.1",
47
+ "rollup-plugin-typescript2": "^0.35.0",
41
48
  "rollup-plugin-uglify": "^6.0.4",
42
- "typescript": "^5.0.4"
43
- },
44
- "scripts": {
45
- "prebuild": "rimraf dist",
46
- "prepublish": "npm run build",
47
- "build": "rollup -c && tsc -p tsconfig.esnext.json",
48
- "start": "rollup -c -w",
49
- "tsc": "tsc -p tsconfig.esnext.json"
49
+ "typescript": "^5.2.2"
50
50
  }
51
- }
51
+ }
package/src/Lib.ts CHANGED
@@ -58,6 +58,9 @@ export interface PageViewsOptions {
58
58
  /** A list of Regular Expressions or string pathes to ignore. */
59
59
  ignore?: Array<string | RegExp>
60
60
 
61
+ /** 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. */
62
+ doNotAnonymise?: boolean
63
+
61
64
  /** Do not send Heartbeat requests to the server. */
62
65
  noHeartbeat?: boolean
63
66
 
@@ -178,7 +181,6 @@ export class Lib {
178
181
  }
179
182
  }
180
183
 
181
-
182
184
  private heartbeat(): void {
183
185
  if (!this.pageViewsOptions?.heartbeatOnBackground && document.visibilityState === 'hidden') {
184
186
  return
@@ -219,11 +221,13 @@ export class Lib {
219
221
  // Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
220
222
  // That method of getting previous page works for SPA websites
221
223
  if (this.activePage) {
222
- if (this.checkIgnore(this.activePage)) {
224
+ const shouldIgnore = this.checkIgnore(this.activePage)
225
+
226
+ if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise) {
223
227
  return null
224
228
  }
225
229
 
226
- return this.activePage
230
+ return shouldIgnore ? null : this.activePage
227
231
  }
228
232
 
229
233
  // Checking if URL is supported by the browser (for example, IE11 does not support it)
@@ -245,11 +249,13 @@ export class Lib {
245
249
  return null
246
250
  }
247
251
 
248
- if (this.checkIgnore(pathname)) {
252
+ const shouldIgnore = this.checkIgnore(pathname)
253
+
254
+ if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise) {
249
255
  return null
250
256
  }
251
257
 
252
- return pathname
258
+ return shouldIgnore ? null : pathname
253
259
  } catch {
254
260
  return null
255
261
  }
@@ -262,7 +268,9 @@ export class Lib {
262
268
  if (!this.pageData) return
263
269
  this.pageData.path = pg
264
270
 
265
- if (this.checkIgnore(pg)) return
271
+ const shouldIgnore = this.checkIgnore(pg)
272
+
273
+ if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise) return
266
274
 
267
275
  const perf = this.getPerformanceStats()
268
276
 
@@ -281,7 +289,7 @@ export class Lib {
281
289
  me: getUTMMedium(),
282
290
  ca: getUTMCampaign(),
283
291
  unique,
284
- pg,
292
+ pg: shouldIgnore ? null : pg,
285
293
  perf,
286
294
  prev,
287
295
  }