@brainfish-ai/web-tracker 0.0.4-alpha.21 → 0.0.4-alpha.23
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/dist/index.cjs.js +4 -0
- package/dist/index.cjs.js.gz +0 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.gz +0 -0
- package/dist/index.js.map +1 -0
- package/dist/src/index.d.ts +22 -0
- package/dist/src/redact/built-ins/NameRedactor.d.ts +6 -0
- package/dist/src/redact/built-ins/SimpleRegexpRedactor.d.ts +10 -0
- package/dist/src/redact/built-ins/simple-regexp-patterns.d.ts +12 -0
- package/dist/src/redact/built-ins/well-known-names.d.ts +2 -0
- package/dist/src/redact/composition.d.ts +2 -0
- package/dist/src/redact/index.d.ts +10 -0
- package/{src/redact/types.ts → dist/src/redact/types.d.ts} +15 -22
- package/dist/src/redact/utils.d.ts +4 -0
- package/dist/src/screenshot/capture.d.ts +2 -0
- package/dist/src/screenshot/redact.d.ts +3 -0
- package/dist/src/screenshot/snapshot.d.ts +2 -0
- package/dist/src/setupTests.d.ts +0 -0
- package/dist/src/tracker.d.ts +9 -0
- package/dist/tracker.cjs.js +2 -0
- package/dist/tracker.cjs.js.map +1 -0
- package/dist/tracker.d.ts +1 -0
- package/dist/tracker.js +13 -0
- package/dist/tracker.js.map +1 -0
- package/package.json +4 -1
- package/index.ts +0 -2
- package/postcss.config.cjs +0 -6
- package/set-version.js +0 -13
- package/src/index.ts +0 -192
- package/src/redact/built-ins/NameRedactor.ts +0 -41
- package/src/redact/built-ins/SimpleRegexpRedactor.ts +0 -22
- package/src/redact/built-ins/simple-regexp-patterns.ts +0 -20
- package/src/redact/built-ins/well-known-names.ts +0 -11543
- package/src/redact/composition.ts +0 -54
- package/src/redact/index.ts +0 -21
- package/src/redact/utils.ts +0 -15
- package/src/screenshot/capture.test.ts +0 -83
- package/src/screenshot/capture.ts +0 -51
- package/src/screenshot/redact.test.ts +0 -74
- package/src/screenshot/redact.ts +0 -57
- package/src/screenshot/snapshot.ts +0 -35
- package/src/setupTests.ts +0 -1
- package/src/tracker.ts +0 -31
- package/src/types.d.ts +0 -31
- package/src/vite-env.d.ts +0 -7
- package/tailwind.config.cjs +0 -9
- package/tsconfig.json +0 -16
- package/vite.config.ts +0 -56
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TrackerSdkOptions, TrackProperties, TrackerSdk } from '@brainfish-ai/tracker-sdk';
|
|
2
|
+
export type * from '@brainfish-ai/tracker-sdk';
|
|
3
|
+
export type TrackerOptions = TrackerSdkOptions & {
|
|
4
|
+
trackOutgoingLinks?: boolean;
|
|
5
|
+
trackScreenViews?: boolean;
|
|
6
|
+
trackAttributes?: boolean;
|
|
7
|
+
trackHashChanges?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const VERSION: string;
|
|
10
|
+
export declare class Tracker extends TrackerSdk {
|
|
11
|
+
options: TrackerOptions;
|
|
12
|
+
private lastPath;
|
|
13
|
+
private debounceTimer;
|
|
14
|
+
constructor(options: TrackerOptions);
|
|
15
|
+
private debounce;
|
|
16
|
+
private isServer;
|
|
17
|
+
trackOutgoingLinks(): void;
|
|
18
|
+
trackScreenViews(): void;
|
|
19
|
+
trackAttributes(): void;
|
|
20
|
+
screenView(properties?: TrackProperties): Promise<void>;
|
|
21
|
+
screenView(path: string, properties?: TrackProperties): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ISyncRedactor } from '../types';
|
|
2
|
+
export declare class SimpleRegexpRedactor implements ISyncRedactor {
|
|
3
|
+
regexpMatcher: RegExp;
|
|
4
|
+
replaceWith: string;
|
|
5
|
+
constructor({ replaceWith, regexpPattern: regexpMatcher, }: {
|
|
6
|
+
replaceWith: string;
|
|
7
|
+
regexpPattern: RegExp;
|
|
8
|
+
});
|
|
9
|
+
redact(textToRedact: string): string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const creditCardNumber: RegExp;
|
|
2
|
+
export declare const streetAddress: RegExp;
|
|
3
|
+
export declare const zipcode: RegExp;
|
|
4
|
+
export declare const phoneNumber: RegExp;
|
|
5
|
+
export declare const ipAddress: RegExp;
|
|
6
|
+
export declare const usSocialSecurityNumber: RegExp;
|
|
7
|
+
export declare const emailAddress: RegExp;
|
|
8
|
+
export declare const username: RegExp;
|
|
9
|
+
export declare const password: RegExp;
|
|
10
|
+
export declare const credentials: RegExp;
|
|
11
|
+
export declare const digits: RegExp;
|
|
12
|
+
export declare const url: RegExp;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AsyncCustomRedactorConfig, IAsyncRedactor, CompositeRedactorOptions, SyncCustomRedactorConfig, ISyncRedactor } from './types';
|
|
2
|
+
export declare function composeChildRedactors<T extends AsyncCustomRedactorConfig>(opts?: CompositeRedactorOptions<T>): T extends SyncCustomRedactorConfig ? ISyncRedactor[] : (ISyncRedactor | IAsyncRedactor)[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CompositeRedactorOptions, ISyncRedactor, SyncCustomRedactorConfig } from './types';
|
|
2
|
+
/** @public */
|
|
3
|
+
export interface SyncCompositeRedactorOptions extends CompositeRedactorOptions<SyncCustomRedactorConfig> {
|
|
4
|
+
}
|
|
5
|
+
/** @public */
|
|
6
|
+
export declare class SyncRedactor implements ISyncRedactor {
|
|
7
|
+
private childRedactors;
|
|
8
|
+
constructor(opts?: SyncCompositeRedactorOptions);
|
|
9
|
+
redact: (textToRedact: string) => string;
|
|
10
|
+
}
|
|
@@ -1,34 +1,27 @@
|
|
|
1
1
|
import * as simpleRegexpBuiltIns from './built-ins/simple-regexp-patterns';
|
|
2
|
-
|
|
3
2
|
export interface ISyncRedactor {
|
|
4
|
-
|
|
3
|
+
redact(textToRedact: string): string;
|
|
5
4
|
}
|
|
6
|
-
|
|
7
5
|
export interface IAsyncRedactor {
|
|
8
|
-
|
|
6
|
+
redactAsync(textToRedact: string): Promise<string>;
|
|
9
7
|
}
|
|
10
|
-
|
|
11
8
|
export type IRedactor = ISyncRedactor | IAsyncRedactor;
|
|
12
|
-
|
|
13
9
|
export interface SimpleRegexpCustomRedactorConfig {
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
regexpPattern: RegExp;
|
|
11
|
+
replaceWith: string;
|
|
16
12
|
}
|
|
17
|
-
|
|
18
13
|
export type SyncCustomRedactorConfig = SimpleRegexpCustomRedactorConfig | ISyncRedactor;
|
|
19
|
-
|
|
20
14
|
export type AsyncCustomRedactorConfig = SyncCustomRedactorConfig | IAsyncRedactor;
|
|
21
|
-
|
|
22
15
|
export interface CompositeRedactorOptions<T extends AsyncCustomRedactorConfig> {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
globalReplaceWith?: string;
|
|
17
|
+
builtInRedactors?: {
|
|
18
|
+
[RedactorName in keyof typeof simpleRegexpBuiltIns | 'names']?: {
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
replaceWith?: string;
|
|
21
|
+
};
|
|
28
22
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
23
|
+
customRedactors?: {
|
|
24
|
+
before?: Array<T>;
|
|
25
|
+
after?: Array<T>;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SimpleRegexpCustomRedactorConfig, AsyncCustomRedactorConfig, ISyncRedactor, IRedactor } from './types';
|
|
2
|
+
export declare function isSimpleRegexpCustomRedactorConfig(redactor: AsyncCustomRedactorConfig): redactor is SimpleRegexpCustomRedactorConfig;
|
|
3
|
+
export declare function isSyncRedactor(redactor: IRedactor): redactor is ISyncRedactor;
|
|
4
|
+
export declare function snakeCase(str: string): string;
|
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const a=require("./index.cjs.js");(n=>{if(n.BrainfishAnalytics&&"q"in n.BrainfishAnalytics){const t=n.BrainfishAnalytics.q||[],s=new a.Tracker(t.shift()[1]);t.forEach(i=>{i[0]in s&&s[i[0]](...i.slice(1))}),n.BrainfishAnalytics=(i,...o)=>{const c=s[i]?s[i].bind(s):void 0;typeof c=="function"?c(...o):console.warn(`Method ${i} does not exist on BrainfishAnalytics`)}}})(window);
|
|
2
|
+
//# sourceMappingURL=tracker.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracker.cjs.js","sources":["../src/tracker.ts"],"sourcesContent":["import { Tracker } from './index';\n\ndeclare global {\n interface Window {\n BrainfishAnalytics: {\n q?: [string, ...any[]];\n (method: string, ...args: any[]): void;\n };\n }\n}\n\n((window) => {\n if (window.BrainfishAnalytics && 'q' in window.BrainfishAnalytics) {\n const queue = window.BrainfishAnalytics.q || [];\n const tracker = new Tracker(queue.shift()[1]) as any;\n queue.forEach((item) => {\n if (item[0] in tracker) {\n tracker[item[0]](...item.slice(1));\n }\n });\n\n window.BrainfishAnalytics = (t, ...args) => {\n const fn = tracker[t] ? tracker[t].bind(tracker) : undefined;\n if (typeof fn === 'function') {\n fn(...args);\n } else {\n console.warn(`Method ${t} does not exist on BrainfishAnalytics`);\n }\n };\n }\n})(window);\n"],"names":["window","BrainfishAnalytics","queue","q","tracker","Tracker","shift","forEach","item","slice","t","args","fn","bind","console","warn"],"mappings":"gDAWEA,GAAAA,CACA,GAAIA,EAAOC,oBAAsB,MAAOD,EAAOC,mBAAoB,CACjE,MAAMC,EAAQF,EAAOC,mBAAmBE,GAAK,CAAA,EACvCC,EAAU,IAAIC,UAAQH,EAAMI,MAAAA,EAAQ,CACpCJ,CAAAA,EAAAA,EAAAK,QAASC,GAAAA,CACTA,EAAK,CAAMJ,IAAAA,GACLA,EAAAI,EAAK,CAAOA,CAAAA,EAAAA,GAAAA,EAAKC,MAAM,CAAA,CAAA,CACjC,CAGFT,EAAAA,EAAOC,mBAAqB,CAACS,KAAMC,IAAAA,CAC3B,MAAAC,EAAKR,EAAQM,CAAKN,EAAAA,EAAQM,CAAGG,EAAAA,KAAKT,CAAW,EAAA,OACxCQ,OAAAA,GAAO,WAChBA,EAAMD,GAAAA,CAAAA,EAEEG,QAAAC,KAAK,UAAUL,CAAAA,uCAAAA,CACzB,CAEJ,CACF,GAAGV,MAAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/tracker.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Tracker as c } from "./index.js";
|
|
2
|
+
((s) => {
|
|
3
|
+
if (s.BrainfishAnalytics && "q" in s.BrainfishAnalytics) {
|
|
4
|
+
const o = s.BrainfishAnalytics.q || [], n = new c(o.shift()[1]);
|
|
5
|
+
o.forEach((i) => {
|
|
6
|
+
i[0] in n && n[i[0]](...i.slice(1));
|
|
7
|
+
}), s.BrainfishAnalytics = (i, ...t) => {
|
|
8
|
+
const a = n[i] ? n[i].bind(n) : void 0;
|
|
9
|
+
typeof a == "function" ? a(...t) : console.warn(`Method ${i} does not exist on BrainfishAnalytics`);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
})(window);
|
|
13
|
+
//# sourceMappingURL=tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracker.js","sources":["../src/tracker.ts"],"sourcesContent":["import { Tracker } from './index';\n\ndeclare global {\n interface Window {\n BrainfishAnalytics: {\n q?: [string, ...any[]];\n (method: string, ...args: any[]): void;\n };\n }\n}\n\n((window) => {\n if (window.BrainfishAnalytics && 'q' in window.BrainfishAnalytics) {\n const queue = window.BrainfishAnalytics.q || [];\n const tracker = new Tracker(queue.shift()[1]) as any;\n queue.forEach((item) => {\n if (item[0] in tracker) {\n tracker[item[0]](...item.slice(1));\n }\n });\n\n window.BrainfishAnalytics = (t, ...args) => {\n const fn = tracker[t] ? tracker[t].bind(tracker) : undefined;\n if (typeof fn === 'function') {\n fn(...args);\n } else {\n console.warn(`Method ${t} does not exist on BrainfishAnalytics`);\n }\n };\n }\n})(window);\n"],"names":["window","BrainfishAnalytics","queue","q","tracker","Tracker","shift","forEach","item","slice","t","args","fn","bind","console","warn"],"mappings":";CAWEA,CAAAA,MACA;AAAA,MAAIA,EAAOC,sBAAsB,OAAOD,EAAOC,oBAAoB;AACjE,UAAMC,IAAQF,EAAOC,mBAAmBE,KAAK,CAAA,GACvCC,IAAU,IAAIC,EAAQH,EAAMI,MAAQ,EAAA,CAAA,CAAA;AACpCJ,IAAAA,EAAAK,QAASC,OACTA;AAAAA,QAAK,CAAMJ,KAAAA,KACLA,EAAAI,EAAK,CAAOA,CAAAA,EAAAA,GAAAA,EAAKC,MAAM,CAAA,CAAA;AAAA,IACjC,CAGFT,GAAAA,EAAOC,qBAAqB,CAACS,MAAMC,MAAAA;AAC3B,YAAAC,IAAKR,EAAQM,CAAAA,IAAKN,EAAQM,CAAAA,EAAGG,KAAKT,CAAAA,IAAAA;AACtB,MAAA,OAAPQ,KAAO,aAChBA,EAAAA,GAAMD,CAEEG,IAAAA,QAAAC,KAAK,UAAUL,CACzB,uCAAA;AAAA,IAAA;AAAA,EAEJ;AACF,GAAGV,MAAAA;"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brainfish-ai/web-tracker",
|
|
3
|
-
"version": "0.0.4-alpha.
|
|
3
|
+
"version": "0.0.4-alpha.23",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"description": "Brainfish Tracker for Web",
|
|
6
6
|
"private": false,
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
7
10
|
"scripts": {
|
|
8
11
|
"start": "vite",
|
|
9
12
|
"dev": "vite",
|
package/index.ts
DELETED
package/postcss.config.cjs
DELETED
package/set-version.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const packageJson = require('./package.json');
|
|
3
|
-
|
|
4
|
-
// Get the version from package.json
|
|
5
|
-
const version = packageJson.version;
|
|
6
|
-
|
|
7
|
-
// Prepare the .env content
|
|
8
|
-
const envContent = `PACKAGE_VERSION=${version}\n`;
|
|
9
|
-
|
|
10
|
-
// Write the version to .env file
|
|
11
|
-
fs.writeFileSync('.env', envContent);
|
|
12
|
-
|
|
13
|
-
console.log(`Set PACKAGE_VERSION to ${version} in .env file`);
|
package/src/index.ts
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/unbound-method */
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
TrackerSdkOptions,
|
|
5
|
-
TrackProperties,
|
|
6
|
-
} from '@brainfish-ai/tracker-sdk';
|
|
7
|
-
import { TrackerSdk } from '@brainfish-ai/tracker-sdk';
|
|
8
|
-
import { screenshot } from './screenshot/snapshot';
|
|
9
|
-
|
|
10
|
-
export type * from '@brainfish-ai/tracker-sdk';
|
|
11
|
-
|
|
12
|
-
export type TrackerOptions = TrackerSdkOptions & {
|
|
13
|
-
trackOutgoingLinks?: boolean;
|
|
14
|
-
trackScreenViews?: boolean;
|
|
15
|
-
trackAttributes?: boolean;
|
|
16
|
-
trackHashChanges?: boolean;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
function toCamelCase(str: string) {
|
|
20
|
-
return str.replace(/([-_][a-z])/gi, ($1) =>
|
|
21
|
-
$1.toUpperCase().replace('-', '').replace('_', '')
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const VERSION = import.meta.env.PACKAGE_VERSION as string;
|
|
26
|
-
|
|
27
|
-
export class Tracker extends TrackerSdk {
|
|
28
|
-
private lastPath = '';
|
|
29
|
-
private debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
30
|
-
|
|
31
|
-
constructor(public options: TrackerOptions) {
|
|
32
|
-
super({
|
|
33
|
-
sdk: 'web',
|
|
34
|
-
sdkVersion: VERSION,
|
|
35
|
-
...options,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
if (!this.isServer()) {
|
|
39
|
-
this.setGlobalProperties({
|
|
40
|
-
__referrer: document.referrer,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
if (this.options.trackOutgoingLinks) {
|
|
44
|
-
this.trackOutgoingLinks();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (this.options.trackScreenViews) {
|
|
48
|
-
this.trackScreenViews();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (this.options.trackAttributes) {
|
|
52
|
-
this.trackAttributes();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private debounce(func: () => void, delay: number) {
|
|
58
|
-
this.debounceTimer && clearTimeout(this.debounceTimer);
|
|
59
|
-
this.debounceTimer = setTimeout(func, delay);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private isServer() {
|
|
63
|
-
return typeof document === 'undefined';
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public trackOutgoingLinks() {
|
|
67
|
-
if (this.isServer()) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
document.addEventListener('click', (event) => {
|
|
72
|
-
const target = event.target as HTMLElement;
|
|
73
|
-
const link = target.closest('a');
|
|
74
|
-
if (link && target) {
|
|
75
|
-
const href = link.getAttribute('href');
|
|
76
|
-
if (href?.startsWith('http')) {
|
|
77
|
-
super.track('link_out', {
|
|
78
|
-
href,
|
|
79
|
-
text:
|
|
80
|
-
link.innerText ||
|
|
81
|
-
link.getAttribute('title') ||
|
|
82
|
-
target.getAttribute('alt') ||
|
|
83
|
-
target.getAttribute('title'),
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public trackScreenViews() {
|
|
91
|
-
if (this.isServer()) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
this.screenView();
|
|
96
|
-
|
|
97
|
-
const oldPushState = history.pushState;
|
|
98
|
-
history.pushState = function pushState(...args) {
|
|
99
|
-
const ret = oldPushState.apply(this, args);
|
|
100
|
-
window.dispatchEvent(new Event('pushstate'));
|
|
101
|
-
window.dispatchEvent(new Event('locationchange'));
|
|
102
|
-
return ret;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const oldReplaceState = history.replaceState;
|
|
106
|
-
history.replaceState = function replaceState(...args) {
|
|
107
|
-
const ret = oldReplaceState.apply(this, args);
|
|
108
|
-
window.dispatchEvent(new Event('replacestate'));
|
|
109
|
-
window.dispatchEvent(new Event('locationchange'));
|
|
110
|
-
return ret;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
window.addEventListener('popstate', function () {
|
|
114
|
-
window.dispatchEvent(new Event('locationchange'));
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const eventHandler = () => this.debounce(() => this.screenView(), 50);
|
|
118
|
-
|
|
119
|
-
if (this.options.trackHashChanges) {
|
|
120
|
-
window.addEventListener('hashchange', eventHandler);
|
|
121
|
-
} else {
|
|
122
|
-
window.addEventListener('locationchange', eventHandler);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
public trackAttributes() {
|
|
127
|
-
if (this.isServer()) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
document.addEventListener('click', (event) => {
|
|
132
|
-
const target = event.target as HTMLElement;
|
|
133
|
-
const btn = target.closest('button');
|
|
134
|
-
const anchor = target.closest('a');
|
|
135
|
-
const element = btn?.getAttribute('data-track')
|
|
136
|
-
? btn
|
|
137
|
-
: anchor?.getAttribute('data-track')
|
|
138
|
-
? anchor
|
|
139
|
-
: null;
|
|
140
|
-
if (element) {
|
|
141
|
-
const properties: Record<string, unknown> = {};
|
|
142
|
-
for (const attr of element.attributes) {
|
|
143
|
-
if (attr.name.startsWith('data-') && attr.name !== 'data-track') {
|
|
144
|
-
properties[toCamelCase(attr.name.replace(/^data-/, ''))] =
|
|
145
|
-
attr.value;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
const name = element.getAttribute('data-track');
|
|
149
|
-
if (name) {
|
|
150
|
-
super.track(name, properties);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
async screenView(properties?: TrackProperties): Promise<void>;
|
|
157
|
-
async screenView(path: string, properties?: TrackProperties): Promise<void>;
|
|
158
|
-
async screenView(
|
|
159
|
-
pathOrProperties?: string | TrackProperties,
|
|
160
|
-
propertiesOrUndefined?: TrackProperties
|
|
161
|
-
): Promise<void> {
|
|
162
|
-
if (this.isServer()) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
let path: string;
|
|
167
|
-
let properties: TrackProperties | undefined;
|
|
168
|
-
|
|
169
|
-
if (typeof pathOrProperties === 'string') {
|
|
170
|
-
path = pathOrProperties;
|
|
171
|
-
properties = propertiesOrUndefined;
|
|
172
|
-
} else {
|
|
173
|
-
path = window.location.href;
|
|
174
|
-
properties = pathOrProperties;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (this.lastPath === path) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// capture screenshot
|
|
182
|
-
const snapshot = await screenshot();
|
|
183
|
-
|
|
184
|
-
this.lastPath = path;
|
|
185
|
-
super.track('screen_view', {
|
|
186
|
-
...(properties ?? {}),
|
|
187
|
-
__screenshot: snapshot,
|
|
188
|
-
__path: path,
|
|
189
|
-
__title: document.title,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ISyncRedactor } from '../types';
|
|
2
|
-
import _wellKnownNames from './well-known-names';
|
|
3
|
-
|
|
4
|
-
const greetingRegex = /(^|\.\s+)(dear|hi|hello|greetings|hey|hey there)/gi;
|
|
5
|
-
const closingRegex =
|
|
6
|
-
/(thx|thanks|thank you|regards|best|[a-z]+ly|[a-z]+ regards|all the best|happy [a-z]+ing|take care|have a [a-z]+ (weekend|night|day))/gi;
|
|
7
|
-
|
|
8
|
-
const greetingOrClosing = new RegExp(
|
|
9
|
-
'(((' + greetingRegex.source + ')|(' + closingRegex.source + '\\s*[,.!]*))[\\s-]*)',
|
|
10
|
-
'gi'
|
|
11
|
-
);
|
|
12
|
-
const genericName = new RegExp('( ?(([A-Z][a-z]+)|([A-Z]\\.)))+([,.]|[,.]?$)', 'gm');
|
|
13
|
-
|
|
14
|
-
const wellKnownNames = new RegExp('\\b(\\s*)(\\s*(' + _wellKnownNames.join('|') + '))+\\b', 'gim');
|
|
15
|
-
|
|
16
|
-
export class NameRedactor implements ISyncRedactor {
|
|
17
|
-
constructor(private replaceWith = 'PERSON_NAME') {}
|
|
18
|
-
|
|
19
|
-
redact(textToRedact: string) {
|
|
20
|
-
greetingOrClosing.lastIndex = 0;
|
|
21
|
-
genericName.lastIndex = 0;
|
|
22
|
-
let greetingOrClosingMatch = greetingOrClosing.exec(textToRedact);
|
|
23
|
-
while (greetingOrClosingMatch !== null) {
|
|
24
|
-
genericName.lastIndex = greetingOrClosing.lastIndex;
|
|
25
|
-
let genericNameMatch = genericName.exec(textToRedact);
|
|
26
|
-
if (genericNameMatch !== null && genericNameMatch.index === greetingOrClosing.lastIndex) {
|
|
27
|
-
let suffix = genericNameMatch[5] === null ? '' : genericNameMatch[5];
|
|
28
|
-
textToRedact =
|
|
29
|
-
textToRedact.slice(0, genericNameMatch.index) +
|
|
30
|
-
this.replaceWith +
|
|
31
|
-
suffix +
|
|
32
|
-
textToRedact.slice(genericNameMatch.index + genericNameMatch[0].length);
|
|
33
|
-
}
|
|
34
|
-
greetingOrClosingMatch = greetingOrClosing.exec(textToRedact);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
textToRedact = textToRedact.replace(wellKnownNames, '$1' + this.replaceWith);
|
|
38
|
-
|
|
39
|
-
return textToRedact;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ISyncRedactor } from '../types';
|
|
2
|
-
import { snakeCase } from '../utils';
|
|
3
|
-
|
|
4
|
-
export class SimpleRegexpRedactor implements ISyncRedactor {
|
|
5
|
-
regexpMatcher: RegExp;
|
|
6
|
-
replaceWith: string;
|
|
7
|
-
|
|
8
|
-
constructor({
|
|
9
|
-
replaceWith = snakeCase('default').toUpperCase(),
|
|
10
|
-
regexpPattern: regexpMatcher,
|
|
11
|
-
}: {
|
|
12
|
-
replaceWith: string;
|
|
13
|
-
regexpPattern: RegExp;
|
|
14
|
-
}) {
|
|
15
|
-
this.replaceWith = replaceWith;
|
|
16
|
-
this.regexpMatcher = regexpMatcher;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
redact(textToRedact: string) {
|
|
20
|
-
return textToRedact.replace(this.regexpMatcher, this.replaceWith);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const aptRegex = /(apt|bldg|dept|fl|hngr|lot|pier|rm|ste|slip|trlr|unit|#)\.? *[a-z0-9-]+\b/gi;
|
|
2
|
-
const poBoxRegex = /P\.? ?O\.? *Box +\d+/gi;
|
|
3
|
-
const roadRegex = /(street|st|road|rd|avenue|ave|drive|dr|loop|court|ct|circle|cir|lane|ln|boulevard|blvd|way)\.?\b/gi;
|
|
4
|
-
|
|
5
|
-
export const creditCardNumber = /\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}|\d{4}[ -]?\d{6}[ -]?\d{4}\d?/g;
|
|
6
|
-
export const streetAddress = new RegExp(
|
|
7
|
-
'(\\d+\\s*(\\w+ ){1,2}' + roadRegex.source + '(\\s+' + aptRegex.source + ')?)|(' + poBoxRegex.source + ')',
|
|
8
|
-
'gi'
|
|
9
|
-
);
|
|
10
|
-
export const zipcode = /\b\d{5}\b(-\d{4})?\b/g;
|
|
11
|
-
export const phoneNumber =
|
|
12
|
-
/(\(?\+?[0-9]{1,2}\)?[-. ]?)?(\(?[0-9]{3}\)?|[0-9]{3})[-. ]?([0-9]{3}[-. ]?[0-9]{4}|\b[A-Z0-9]{7}\b)/g;
|
|
13
|
-
export const ipAddress = /(\d{1,3}(\.\d{1,3}){3}|[0-9A-F]{4}(:[0-9A-F]{4}){5}(::|(:0000)+))/gi;
|
|
14
|
-
export const usSocialSecurityNumber = /\b\d{3}[ -.]\d{2}[ -.]\d{4}\b/g;
|
|
15
|
-
export const emailAddress = /([a-z0-9_\-.+]+)@\w+(\.\w+)*/gi;
|
|
16
|
-
export const username = /(user( ?name)?|login): \S+/gi;
|
|
17
|
-
export const password = /(pass(word|phrase)?|secret): \S+/gi;
|
|
18
|
-
export const credentials = /(login( cred(ential)?s| info(rmation)?)?|cred(ential)?s) ?:\s*\S+\s+\/?\s*\S+/gi;
|
|
19
|
-
export const digits = /\b\d{4,}\b/g;
|
|
20
|
-
export const url = /([^\s:/?#]+):\/\/([^/?#\s]*)([^?#\s]*)(\?([^#\s]*))?(#([^\s]*))?/g;
|