swetrix 2.2.0 → 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.0",
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,7 +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
- return this.activePage
224
+ const shouldIgnore = this.checkIgnore(this.activePage)
225
+
226
+ if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise) {
227
+ return null
228
+ }
229
+
230
+ return shouldIgnore ? null : this.activePage
223
231
  }
224
232
 
225
233
  // Checking if URL is supported by the browser (for example, IE11 does not support it)
@@ -241,7 +249,13 @@ export class Lib {
241
249
  return null
242
250
  }
243
251
 
244
- return pathname
252
+ const shouldIgnore = this.checkIgnore(pathname)
253
+
254
+ if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise) {
255
+ return null
256
+ }
257
+
258
+ return shouldIgnore ? null : pathname
245
259
  } catch {
246
260
  return null
247
261
  }
@@ -254,7 +268,9 @@ export class Lib {
254
268
  if (!this.pageData) return
255
269
  this.pageData.path = pg
256
270
 
257
- if (this.checkIgnore(pg)) return
271
+ const shouldIgnore = this.checkIgnore(pg)
272
+
273
+ if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise) return
258
274
 
259
275
  const perf = this.getPerformanceStats()
260
276
 
@@ -273,7 +289,7 @@ export class Lib {
273
289
  me: getUTMMedium(),
274
290
  ca: getUTMCampaign(),
275
291
  unique,
276
- pg,
292
+ pg: shouldIgnore ? null : pg,
277
293
  perf,
278
294
  prev,
279
295
  }