@faststats/web 0.0.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/README.md +4 -0
- package/dist/error.iife.js +3 -0
- package/dist/error.js +3 -0
- package/dist/module.d.ts +502 -0
- package/dist/module.js +403 -0
- package/dist/replay.iife.js +29 -0
- package/dist/replay.js +29 -0
- package/dist/script.iife.js +1 -0
- package/dist/script.js +1 -0
- package/dist/web-vitals.iife.js +1 -0
- package/dist/web-vitals.js +1 -0
- package/package.json +38 -0
- package/src/analytics.ts +544 -0
- package/src/error.ts +324 -0
- package/src/index.ts +95 -0
- package/src/module.ts +6 -0
- package/src/replay.ts +488 -0
- package/src/utils/identifiers.ts +70 -0
- package/src/utils/types.ts +13 -0
- package/src/web-vitals.ts +207 -0
- package/tsconfig.json +30 -0
- package/tsdown.config.ts +51 -0
- package/worker/index.ts +22 -0
- package/wrangler.toml +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var FA_Error=(function(){var e=class{endpoint;siteKey;debug;flushInterval;maxQueueSize;getCommonData;handledErrors=new WeakSet;errorCounts=new Map;flushTimer=null;started=!1;constructor(e){this.siteKey=e.siteKey,this.endpoint=e.endpoint??`https://metrics.faststats.dev/v1/web`,this.debug=e.debug??!1,this.flushInterval=e.flushInterval??5e3,this.maxQueueSize=e.maxQueueSize??50,this.getCommonData=e.getCommonData??(()=>({}))}start(){if(!(this.started||typeof window>`u`)){if(window.__FA_isTrackingDisabled?.()){this.debug&&console.log(`[ErrorTracker] Tracking disabled via localStorage`);return}this.started=!0,window.addEventListener(`error`,this.handleErrorEvent),window.addEventListener(`unhandledrejection`,this.handleRejection),this.flushTimer=setInterval(()=>this.flush(),this.flushInterval),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`hidden`&&this.flush()}),window.addEventListener(`pagehide`,()=>this.flush()),this.debug&&console.log(`[ErrorTracker] Started listening for errors`)}}stop(){!this.started||typeof window>`u`||(this.started=!1,window.removeEventListener(`error`,this.handleErrorEvent),window.removeEventListener(`unhandledrejection`,this.handleRejection),this.flushTimer&&=(clearInterval(this.flushTimer),null),this.flush(),this.debug&&console.log(`[ErrorTracker] Stopped listening for errors`))}handleErrorEvent=e=>{let t=e.error;if(t instanceof Error){if(this.handledErrors.has(t)){this.debug&&console.log(`[ErrorTracker] Skipping duplicate error:`,t.message);return}this.handledErrors.add(t)}this.queueError({message:e.message||(t?.message??`Unknown error`),filename:e.filename||void 0,lineno:e.lineno||void 0,colno:e.colno||void 0,stack:t?.stack||void 0,type:`error`})};handleRejection=e=>{let t=e.reason;if(t instanceof Error){if(this.handledErrors.has(t)){this.debug&&console.log(`[ErrorTracker] Skipping duplicate rejection:`,t.message);return}this.handledErrors.add(t)}this.queueError({message:t instanceof Error?t.message:typeof t==`string`?t:`Unhandled promise rejection`,stack:t instanceof Error?t.stack:void 0,type:`unhandledrejection`})};isExtensionError(e){return!!(e.filename?.startsWith(`chrome-extension://`)||e.stack&&e.stack.split(`
|
|
2
|
+
`).find(e=>e.trim().startsWith(`at `))?.includes(`chrome-extension://`))}parseStack(e){if(e)return e.split(`
|
|
3
|
+
`).map(e=>e.trim()).filter(e=>e.length>0)}async generateErrorHash(e){let t=[e.type,e.message,e.filename??``,e.lineno??``].join(`:`),n=new TextEncoder().encode(t),r=await crypto.subtle.digest(`SHA-256`,n);return`err_${Array.from(new Uint8Array(r)).map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}async queueError(e){if(this.isExtensionError(e))return;this.debug&&console.log(`[ErrorTracker] Captured error:`,e);let t=await this.generateErrorHash(e),n=this.errorCounts.get(t);if(n)n.count++,this.debug&&console.log(`[ErrorTracker] Incremented count for ${t} to ${n.count}`);else{let n={error:e.type===`unhandledrejection`?`UnhandledRejection`:`Error`,message:e.message,stack:this.parseStack(e.stack)};this.errorCounts.set(t,{entry:n,hash:t,count:1}),this.debug&&console.log(`[ErrorTracker] Queued new error: ${t}`)}this.errorCounts.size>=this.maxQueueSize&&this.flush()}captureError(e){if(this.handledErrors.has(e)){this.debug&&console.log(`[ErrorTracker] Skipping duplicate manual capture:`,e.message);return}this.handledErrors.add(e),this.queueError({message:e.message,stack:e.stack,type:`error`})}flush(){if(this.errorCounts.size===0)return;let e=[];for(let{entry:t,hash:n,count:r}of this.errorCounts.values())e.push({...t,hash:n,count:r});this.errorCounts.clear(),this.debug&&console.log(`[ErrorTracker] Flushing errors:`,e);let t=this.getCommonData(),n=window.__FA_getAnonymousId?.(),r=globalThis.__SOURCEMAPS_BUILD__,i=typeof r?.buildId==`string`&&r.buildId.trim().length>0?r.buildId:void 0,a={token:this.siteKey,...n?{userId:n}:{},sessionId:window.__FA_getSessionId?.(),...i?{buildId:i}:{},data:{url:t.url,page:t.page,referrer:t.referrer,title:typeof document<`u`?document.title:``},errors:e},o=JSON.stringify(a);this.debug&&console.log(`[ErrorTracker] Payload:`,o),window.__FA_sendData?.({url:this.endpoint,data:o,debug:this.debug,debugPrefix:`[ErrorTracker]`})}};return typeof window<`u`&&(window.__FA_ErrorTracker=e),e})();
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var FA_Error=(function(){var e=class{endpoint;siteKey;debug;flushInterval;maxQueueSize;getCommonData;handledErrors=new WeakSet;errorCounts=new Map;flushTimer=null;started=!1;constructor(e){this.siteKey=e.siteKey,this.endpoint=e.endpoint??`https://metrics.faststats.dev/v1/web`,this.debug=e.debug??!1,this.flushInterval=e.flushInterval??5e3,this.maxQueueSize=e.maxQueueSize??50,this.getCommonData=e.getCommonData??(()=>({}))}start(){if(!(this.started||typeof window>`u`)){if(window.__FA_isTrackingDisabled?.()){this.debug&&console.log(`[ErrorTracker] Tracking disabled via localStorage`);return}this.started=!0,window.addEventListener(`error`,this.handleErrorEvent),window.addEventListener(`unhandledrejection`,this.handleRejection),this.flushTimer=setInterval(()=>this.flush(),this.flushInterval),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`hidden`&&this.flush()}),window.addEventListener(`pagehide`,()=>this.flush()),this.debug&&console.log(`[ErrorTracker] Started listening for errors`)}}stop(){!this.started||typeof window>`u`||(this.started=!1,window.removeEventListener(`error`,this.handleErrorEvent),window.removeEventListener(`unhandledrejection`,this.handleRejection),this.flushTimer&&=(clearInterval(this.flushTimer),null),this.flush(),this.debug&&console.log(`[ErrorTracker] Stopped listening for errors`))}handleErrorEvent=e=>{let t=e.error;if(t instanceof Error){if(this.handledErrors.has(t)){this.debug&&console.log(`[ErrorTracker] Skipping duplicate error:`,t.message);return}this.handledErrors.add(t)}this.queueError({message:e.message||(t?.message??`Unknown error`),filename:e.filename||void 0,lineno:e.lineno||void 0,colno:e.colno||void 0,stack:t?.stack||void 0,type:`error`})};handleRejection=e=>{let t=e.reason;if(t instanceof Error){if(this.handledErrors.has(t)){this.debug&&console.log(`[ErrorTracker] Skipping duplicate rejection:`,t.message);return}this.handledErrors.add(t)}this.queueError({message:t instanceof Error?t.message:typeof t==`string`?t:`Unhandled promise rejection`,stack:t instanceof Error?t.stack:void 0,type:`unhandledrejection`})};isExtensionError(e){return!!(e.filename?.startsWith(`chrome-extension://`)||e.stack&&e.stack.split(`
|
|
2
|
+
`).find(e=>e.trim().startsWith(`at `))?.includes(`chrome-extension://`))}parseStack(e){if(e)return e.split(`
|
|
3
|
+
`).map(e=>e.trim()).filter(e=>e.length>0)}async generateErrorHash(e){let t=[e.type,e.message,e.filename??``,e.lineno??``].join(`:`),n=new TextEncoder().encode(t),r=await crypto.subtle.digest(`SHA-256`,n);return`err_${Array.from(new Uint8Array(r)).map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}async queueError(e){if(this.isExtensionError(e))return;this.debug&&console.log(`[ErrorTracker] Captured error:`,e);let t=await this.generateErrorHash(e),n=this.errorCounts.get(t);if(n)n.count++,this.debug&&console.log(`[ErrorTracker] Incremented count for ${t} to ${n.count}`);else{let n={error:e.type===`unhandledrejection`?`UnhandledRejection`:`Error`,message:e.message,stack:this.parseStack(e.stack)};this.errorCounts.set(t,{entry:n,hash:t,count:1}),this.debug&&console.log(`[ErrorTracker] Queued new error: ${t}`)}this.errorCounts.size>=this.maxQueueSize&&this.flush()}captureError(e){if(this.handledErrors.has(e)){this.debug&&console.log(`[ErrorTracker] Skipping duplicate manual capture:`,e.message);return}this.handledErrors.add(e),this.queueError({message:e.message,stack:e.stack,type:`error`})}flush(){if(this.errorCounts.size===0)return;let e=[];for(let{entry:t,hash:n,count:r}of this.errorCounts.values())e.push({...t,hash:n,count:r});this.errorCounts.clear(),this.debug&&console.log(`[ErrorTracker] Flushing errors:`,e);let t=this.getCommonData(),n=window.__FA_getAnonymousId?.(),r=globalThis.__SOURCEMAPS_BUILD__,i=typeof r?.buildId==`string`&&r.buildId.trim().length>0?r.buildId:void 0,a={token:this.siteKey,...n?{userId:n}:{},sessionId:window.__FA_getSessionId?.(),...i?{buildId:i}:{},data:{url:t.url,page:t.page,referrer:t.referrer,title:typeof document<`u`?document.title:``},errors:e},o=JSON.stringify(a);this.debug&&console.log(`[ErrorTracker] Payload:`,o),window.__FA_sendData?.({url:this.endpoint,data:o,debug:this.debug,debugPrefix:`[ErrorTracker]`})}};return typeof window<`u`&&(window.__FA_ErrorTracker=e),e})();
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import { recordOptions } from "rrweb/typings/types";
|
|
2
|
+
import { SlimDOMOptions } from "rrweb-snapshot";
|
|
3
|
+
|
|
4
|
+
//#region ../../node_modules/.bun/@rrweb+types@2.0.0-alpha.20/node_modules/@rrweb/types/dist/index.d.ts
|
|
5
|
+
declare type addedNodeMutation = {
|
|
6
|
+
parentId: number;
|
|
7
|
+
previousId?: number | null;
|
|
8
|
+
nextId: number | null;
|
|
9
|
+
node: serializedNodeWithId;
|
|
10
|
+
};
|
|
11
|
+
declare type adoptedStyleSheetData = {
|
|
12
|
+
source: IncrementalSource.AdoptedStyleSheet;
|
|
13
|
+
} & adoptedStyleSheetParam;
|
|
14
|
+
declare type adoptedStyleSheetParam = {
|
|
15
|
+
id: number;
|
|
16
|
+
styles?: {
|
|
17
|
+
styleId: number;
|
|
18
|
+
rules: styleSheetAddRule[];
|
|
19
|
+
}[];
|
|
20
|
+
styleIds: number[];
|
|
21
|
+
};
|
|
22
|
+
declare type attributeMutation = {
|
|
23
|
+
id: number;
|
|
24
|
+
attributes: {
|
|
25
|
+
[key: string]: string | styleOMValue | null;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
declare type attributes = cssTextKeyAttr & {
|
|
29
|
+
[key: string]: string | number | true | null;
|
|
30
|
+
};
|
|
31
|
+
declare enum CanvasContext {
|
|
32
|
+
'2D' = 0,
|
|
33
|
+
WebGL = 1,
|
|
34
|
+
WebGL2 = 2
|
|
35
|
+
}
|
|
36
|
+
declare type canvasMutationCommand = {
|
|
37
|
+
property: string;
|
|
38
|
+
args: Array<unknown>;
|
|
39
|
+
setter?: true;
|
|
40
|
+
};
|
|
41
|
+
declare type canvasMutationData = {
|
|
42
|
+
source: IncrementalSource.CanvasMutation;
|
|
43
|
+
} & canvasMutationParam;
|
|
44
|
+
declare type canvasMutationParam = {
|
|
45
|
+
id: number;
|
|
46
|
+
type: CanvasContext;
|
|
47
|
+
commands: canvasMutationCommand[];
|
|
48
|
+
} | ({
|
|
49
|
+
id: number;
|
|
50
|
+
type: CanvasContext;
|
|
51
|
+
} & canvasMutationCommand);
|
|
52
|
+
declare type cdataNode = {
|
|
53
|
+
type: NodeType.CDATA;
|
|
54
|
+
textContent: '';
|
|
55
|
+
};
|
|
56
|
+
declare type commentNode = {
|
|
57
|
+
type: NodeType.Comment;
|
|
58
|
+
textContent: string;
|
|
59
|
+
};
|
|
60
|
+
declare type cssTextKeyAttr = {
|
|
61
|
+
_cssText?: string;
|
|
62
|
+
};
|
|
63
|
+
declare type customElementData = {
|
|
64
|
+
source: IncrementalSource.CustomElement;
|
|
65
|
+
} & customElementParam;
|
|
66
|
+
declare type customElementParam = {
|
|
67
|
+
define?: {
|
|
68
|
+
name: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
declare type customEvent<T = unknown> = {
|
|
72
|
+
type: EventType.Custom;
|
|
73
|
+
data: {
|
|
74
|
+
tag: string;
|
|
75
|
+
payload: T;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
declare type documentNode = {
|
|
79
|
+
type: NodeType.Document;
|
|
80
|
+
childNodes: serializedNodeWithId[];
|
|
81
|
+
compatMode?: string;
|
|
82
|
+
};
|
|
83
|
+
declare type documentTypeNode = {
|
|
84
|
+
type: NodeType.DocumentType;
|
|
85
|
+
name: string;
|
|
86
|
+
publicId: string;
|
|
87
|
+
systemId: string;
|
|
88
|
+
};
|
|
89
|
+
declare type domContentLoadedEvent = {
|
|
90
|
+
type: EventType.DomContentLoaded;
|
|
91
|
+
data: unknown;
|
|
92
|
+
};
|
|
93
|
+
declare type elementNode = {
|
|
94
|
+
type: NodeType.Element;
|
|
95
|
+
tagName: string;
|
|
96
|
+
attributes: attributes;
|
|
97
|
+
childNodes: serializedNodeWithId[];
|
|
98
|
+
isSVG?: true;
|
|
99
|
+
needBlock?: boolean;
|
|
100
|
+
isCustom?: true;
|
|
101
|
+
};
|
|
102
|
+
declare enum EventType {
|
|
103
|
+
DomContentLoaded = 0,
|
|
104
|
+
Load = 1,
|
|
105
|
+
FullSnapshot = 2,
|
|
106
|
+
IncrementalSnapshot = 3,
|
|
107
|
+
Meta = 4,
|
|
108
|
+
Custom = 5,
|
|
109
|
+
Plugin = 6
|
|
110
|
+
}
|
|
111
|
+
declare type eventWithoutTime = domContentLoadedEvent | loadedEvent | fullSnapshotEvent | incrementalSnapshotEvent | metaEvent | customEvent | pluginEvent;
|
|
112
|
+
declare type eventWithTime = eventWithoutTime & {
|
|
113
|
+
timestamp: number;
|
|
114
|
+
delay?: number;
|
|
115
|
+
};
|
|
116
|
+
declare type fontData = {
|
|
117
|
+
source: IncrementalSource.Font;
|
|
118
|
+
} & fontParam;
|
|
119
|
+
declare type fontParam = {
|
|
120
|
+
family: string;
|
|
121
|
+
fontSource: string;
|
|
122
|
+
buffer: boolean;
|
|
123
|
+
descriptors?: FontFaceDescriptors;
|
|
124
|
+
};
|
|
125
|
+
declare type fullSnapshotEvent = {
|
|
126
|
+
type: EventType.FullSnapshot;
|
|
127
|
+
data: {
|
|
128
|
+
node: serializedNodeWithId;
|
|
129
|
+
initialOffset: {
|
|
130
|
+
top: number;
|
|
131
|
+
left: number;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
declare type incrementalData = mutationData | mousemoveData | mouseInteractionData | scrollData | viewportResizeData | inputData | mediaInteractionData | styleSheetRuleData | canvasMutationData | fontData | selectionData | styleDeclarationData | adoptedStyleSheetData | customElementData;
|
|
136
|
+
declare type incrementalSnapshotEvent = {
|
|
137
|
+
type: EventType.IncrementalSnapshot;
|
|
138
|
+
data: incrementalData;
|
|
139
|
+
};
|
|
140
|
+
declare enum IncrementalSource {
|
|
141
|
+
Mutation = 0,
|
|
142
|
+
MouseMove = 1,
|
|
143
|
+
MouseInteraction = 2,
|
|
144
|
+
Scroll = 3,
|
|
145
|
+
ViewportResize = 4,
|
|
146
|
+
Input = 5,
|
|
147
|
+
TouchMove = 6,
|
|
148
|
+
MediaInteraction = 7,
|
|
149
|
+
StyleSheetRule = 8,
|
|
150
|
+
CanvasMutation = 9,
|
|
151
|
+
Font = 10,
|
|
152
|
+
Log = 11,
|
|
153
|
+
Drag = 12,
|
|
154
|
+
StyleDeclaration = 13,
|
|
155
|
+
Selection = 14,
|
|
156
|
+
AdoptedStyleSheet = 15,
|
|
157
|
+
CustomElement = 16
|
|
158
|
+
}
|
|
159
|
+
declare type inputData = {
|
|
160
|
+
source: IncrementalSource.Input;
|
|
161
|
+
id: number;
|
|
162
|
+
} & inputValue;
|
|
163
|
+
declare type inputValue = {
|
|
164
|
+
text: string;
|
|
165
|
+
isChecked: boolean;
|
|
166
|
+
userTriggered?: boolean;
|
|
167
|
+
};
|
|
168
|
+
declare type loadedEvent = {
|
|
169
|
+
type: EventType.Load;
|
|
170
|
+
data: unknown;
|
|
171
|
+
};
|
|
172
|
+
declare type mediaInteractionData = {
|
|
173
|
+
source: IncrementalSource.MediaInteraction;
|
|
174
|
+
} & mediaInteractionParam;
|
|
175
|
+
declare type mediaInteractionParam = {
|
|
176
|
+
type: MediaInteractions;
|
|
177
|
+
id: number;
|
|
178
|
+
currentTime?: number;
|
|
179
|
+
volume?: number;
|
|
180
|
+
muted?: boolean;
|
|
181
|
+
loop?: boolean;
|
|
182
|
+
playbackRate?: number;
|
|
183
|
+
};
|
|
184
|
+
declare enum MediaInteractions {
|
|
185
|
+
Play = 0,
|
|
186
|
+
Pause = 1,
|
|
187
|
+
Seeked = 2,
|
|
188
|
+
VolumeChange = 3,
|
|
189
|
+
RateChange = 4
|
|
190
|
+
}
|
|
191
|
+
declare type metaEvent = {
|
|
192
|
+
type: EventType.Meta;
|
|
193
|
+
data: {
|
|
194
|
+
href: string;
|
|
195
|
+
width: number;
|
|
196
|
+
height: number;
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
declare type mouseInteractionData = {
|
|
200
|
+
source: IncrementalSource.MouseInteraction;
|
|
201
|
+
} & mouseInteractionParam;
|
|
202
|
+
declare type mouseInteractionParam = {
|
|
203
|
+
type: MouseInteractions;
|
|
204
|
+
id: number;
|
|
205
|
+
x?: number;
|
|
206
|
+
y?: number;
|
|
207
|
+
pointerType?: PointerTypes;
|
|
208
|
+
};
|
|
209
|
+
declare enum MouseInteractions {
|
|
210
|
+
MouseUp = 0,
|
|
211
|
+
MouseDown = 1,
|
|
212
|
+
Click = 2,
|
|
213
|
+
ContextMenu = 3,
|
|
214
|
+
DblClick = 4,
|
|
215
|
+
Focus = 5,
|
|
216
|
+
Blur = 6,
|
|
217
|
+
TouchStart = 7,
|
|
218
|
+
TouchMove_Departed = 8,
|
|
219
|
+
TouchEnd = 9,
|
|
220
|
+
TouchCancel = 10
|
|
221
|
+
}
|
|
222
|
+
declare type mousemoveData = {
|
|
223
|
+
source: IncrementalSource.MouseMove | IncrementalSource.TouchMove | IncrementalSource.Drag;
|
|
224
|
+
positions: mousePosition[];
|
|
225
|
+
};
|
|
226
|
+
declare type mousePosition = {
|
|
227
|
+
x: number;
|
|
228
|
+
y: number;
|
|
229
|
+
id: number;
|
|
230
|
+
timeOffset: number;
|
|
231
|
+
};
|
|
232
|
+
declare type mutationCallbackParam = {
|
|
233
|
+
texts: textMutation[];
|
|
234
|
+
attributes: attributeMutation[];
|
|
235
|
+
removes: removedNodeMutation[];
|
|
236
|
+
adds: addedNodeMutation[];
|
|
237
|
+
isAttachIframe?: true;
|
|
238
|
+
};
|
|
239
|
+
declare type mutationData = {
|
|
240
|
+
source: IncrementalSource.Mutation;
|
|
241
|
+
} & mutationCallbackParam;
|
|
242
|
+
declare enum NodeType {
|
|
243
|
+
Document = 0,
|
|
244
|
+
DocumentType = 1,
|
|
245
|
+
Element = 2,
|
|
246
|
+
Text = 3,
|
|
247
|
+
CDATA = 4,
|
|
248
|
+
Comment = 5
|
|
249
|
+
}
|
|
250
|
+
declare type pluginEvent<T = unknown> = {
|
|
251
|
+
type: EventType.Plugin;
|
|
252
|
+
data: {
|
|
253
|
+
plugin: string;
|
|
254
|
+
payload: T;
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
declare enum PointerTypes {
|
|
258
|
+
Mouse = 0,
|
|
259
|
+
Pen = 1,
|
|
260
|
+
Touch = 2
|
|
261
|
+
}
|
|
262
|
+
declare type removedNodeMutation = {
|
|
263
|
+
parentId: number;
|
|
264
|
+
id: number;
|
|
265
|
+
isShadow?: boolean;
|
|
266
|
+
};
|
|
267
|
+
declare type scrollData = {
|
|
268
|
+
source: IncrementalSource.Scroll;
|
|
269
|
+
} & scrollPosition;
|
|
270
|
+
declare type scrollPosition = {
|
|
271
|
+
id: number;
|
|
272
|
+
x: number;
|
|
273
|
+
y: number;
|
|
274
|
+
};
|
|
275
|
+
declare type selectionData = {
|
|
276
|
+
source: IncrementalSource.Selection;
|
|
277
|
+
} & selectionParam;
|
|
278
|
+
declare type selectionParam = {
|
|
279
|
+
ranges: Array<SelectionRange>;
|
|
280
|
+
};
|
|
281
|
+
declare type SelectionRange = {
|
|
282
|
+
start: number;
|
|
283
|
+
startOffset: number;
|
|
284
|
+
end: number;
|
|
285
|
+
endOffset: number;
|
|
286
|
+
};
|
|
287
|
+
declare type serializedNode = (documentNode | documentTypeNode | elementNode | textNode | cdataNode | commentNode) & {
|
|
288
|
+
rootId?: number;
|
|
289
|
+
isShadowHost?: boolean;
|
|
290
|
+
isShadow?: boolean;
|
|
291
|
+
};
|
|
292
|
+
declare type serializedNodeWithId = serializedNode & {
|
|
293
|
+
id: number;
|
|
294
|
+
};
|
|
295
|
+
declare type styleDeclarationData = {
|
|
296
|
+
source: IncrementalSource.StyleDeclaration;
|
|
297
|
+
} & styleDeclarationParam;
|
|
298
|
+
declare type styleDeclarationParam = {
|
|
299
|
+
id?: number;
|
|
300
|
+
styleId?: number;
|
|
301
|
+
index: number[];
|
|
302
|
+
set?: {
|
|
303
|
+
property: string;
|
|
304
|
+
value: string | null;
|
|
305
|
+
priority: string | undefined;
|
|
306
|
+
};
|
|
307
|
+
remove?: {
|
|
308
|
+
property: string;
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
declare type styleOMValue = {
|
|
312
|
+
[key: string]: styleValueWithPriority | string | false;
|
|
313
|
+
};
|
|
314
|
+
declare type styleSheetAddRule = {
|
|
315
|
+
rule: string;
|
|
316
|
+
index?: number | number[];
|
|
317
|
+
};
|
|
318
|
+
declare type styleSheetDeleteRule = {
|
|
319
|
+
index: number | number[];
|
|
320
|
+
};
|
|
321
|
+
declare type styleSheetRuleData = {
|
|
322
|
+
source: IncrementalSource.StyleSheetRule;
|
|
323
|
+
} & styleSheetRuleParam;
|
|
324
|
+
declare type styleSheetRuleParam = {
|
|
325
|
+
id?: number;
|
|
326
|
+
styleId?: number;
|
|
327
|
+
removes?: styleSheetDeleteRule[];
|
|
328
|
+
adds?: styleSheetAddRule[];
|
|
329
|
+
replace?: string;
|
|
330
|
+
replaceSync?: string;
|
|
331
|
+
};
|
|
332
|
+
declare type styleValueWithPriority = [string, string];
|
|
333
|
+
declare type textMutation = {
|
|
334
|
+
id: number;
|
|
335
|
+
value: string | null;
|
|
336
|
+
};
|
|
337
|
+
declare type textNode = {
|
|
338
|
+
type: NodeType.Text;
|
|
339
|
+
textContent: string;
|
|
340
|
+
isStyle?: true;
|
|
341
|
+
};
|
|
342
|
+
declare type viewportResizeData = {
|
|
343
|
+
source: IncrementalSource.ViewportResize;
|
|
344
|
+
} & viewportResizeDimension;
|
|
345
|
+
declare type viewportResizeDimension = {
|
|
346
|
+
width: number;
|
|
347
|
+
height: number;
|
|
348
|
+
};
|
|
349
|
+
declare global {
|
|
350
|
+
interface Window {
|
|
351
|
+
FontFace: typeof FontFace;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
//#endregion
|
|
355
|
+
//#region src/utils/types.d.ts
|
|
356
|
+
interface SendDataOptions {
|
|
357
|
+
url: string;
|
|
358
|
+
data: string | Blob;
|
|
359
|
+
contentType?: string;
|
|
360
|
+
headers?: Record<string, string>;
|
|
361
|
+
debug?: boolean;
|
|
362
|
+
debugPrefix?: string;
|
|
363
|
+
}
|
|
364
|
+
//#endregion
|
|
365
|
+
//#region src/replay.d.ts
|
|
366
|
+
interface ReplayTrackerOptions {
|
|
367
|
+
siteKey: string;
|
|
368
|
+
endpoint?: string;
|
|
369
|
+
debug?: boolean;
|
|
370
|
+
samplingPercentage?: number;
|
|
371
|
+
flushInterval?: number;
|
|
372
|
+
maxEvents?: number;
|
|
373
|
+
sampling?: recordOptions<eventWithTime>["sampling"];
|
|
374
|
+
slimDOMOptions?: SlimDOMOptions;
|
|
375
|
+
maskAllInputs?: boolean;
|
|
376
|
+
maskInputOptions?: recordOptions<eventWithTime>["maskInputOptions"];
|
|
377
|
+
blockClass?: string;
|
|
378
|
+
blockSelector?: string;
|
|
379
|
+
maskTextClass?: string;
|
|
380
|
+
maskTextSelector?: string;
|
|
381
|
+
checkoutEveryNms?: number;
|
|
382
|
+
checkoutEveryNth?: number;
|
|
383
|
+
recordConsole?: boolean;
|
|
384
|
+
}
|
|
385
|
+
type ReplayTrackerPublicInstance = {
|
|
386
|
+
start(): void;
|
|
387
|
+
stop(): void;
|
|
388
|
+
getSessionId(): string | undefined;
|
|
389
|
+
};
|
|
390
|
+
type ReplayTrackerConstructor = new (options: ReplayTrackerOptions) => ReplayTrackerPublicInstance;
|
|
391
|
+
declare global {
|
|
392
|
+
interface Window {
|
|
393
|
+
__FA_ReplayTracker?: ReplayTrackerConstructor;
|
|
394
|
+
__FA_getAnonymousId?: () => string;
|
|
395
|
+
__FA_getSessionId?: () => string;
|
|
396
|
+
__FA_sendData?: (options: SendDataOptions) => Promise<boolean>;
|
|
397
|
+
__FA_isTrackingDisabled?: () => boolean;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/analytics.d.ts
|
|
402
|
+
type Dict = Record<string, unknown>;
|
|
403
|
+
interface SamplingOptions {
|
|
404
|
+
percentage?: number;
|
|
405
|
+
}
|
|
406
|
+
interface ErrorTrackingConfig {
|
|
407
|
+
enabled?: boolean;
|
|
408
|
+
}
|
|
409
|
+
interface WebVitalsConfig {
|
|
410
|
+
enabled?: boolean;
|
|
411
|
+
sampling?: SamplingOptions;
|
|
412
|
+
}
|
|
413
|
+
interface SessionReplayConfig {
|
|
414
|
+
enabled?: boolean;
|
|
415
|
+
sampling?: SamplingOptions;
|
|
416
|
+
}
|
|
417
|
+
type ConsentMode = "pending" | "granted" | "denied";
|
|
418
|
+
interface ConsentConfig {
|
|
419
|
+
mode?: ConsentMode;
|
|
420
|
+
cookielessWhilePending?: boolean;
|
|
421
|
+
}
|
|
422
|
+
interface IdentifyOptions {
|
|
423
|
+
name?: string;
|
|
424
|
+
phone?: string;
|
|
425
|
+
avatarUrl?: string;
|
|
426
|
+
traits?: Record<string, unknown>;
|
|
427
|
+
}
|
|
428
|
+
interface WebAnalyticsOptions {
|
|
429
|
+
siteKey: string;
|
|
430
|
+
endpoint?: string;
|
|
431
|
+
baseUrl?: string;
|
|
432
|
+
debug?: boolean;
|
|
433
|
+
autoTrack?: boolean;
|
|
434
|
+
trackHash?: boolean;
|
|
435
|
+
trackErrors?: boolean;
|
|
436
|
+
trackWebVitals?: boolean;
|
|
437
|
+
trackReplay?: boolean;
|
|
438
|
+
cookieless?: boolean;
|
|
439
|
+
consent?: ConsentConfig;
|
|
440
|
+
errorTracking?: ErrorTrackingConfig;
|
|
441
|
+
webVitals?: WebVitalsConfig;
|
|
442
|
+
sessionReplays?: SessionReplayConfig;
|
|
443
|
+
replayOptions?: Partial<ReplayTrackerOptions>;
|
|
444
|
+
}
|
|
445
|
+
declare global {
|
|
446
|
+
interface Window {
|
|
447
|
+
WebAnalytics: typeof WebAnalytics;
|
|
448
|
+
__FA_getAnonymousId?: () => string;
|
|
449
|
+
__FA_getSessionId?: () => string;
|
|
450
|
+
__FA_sendData?: (options: SendDataOptions) => Promise<boolean>;
|
|
451
|
+
__FA_identify?: (externalId: string, email: string, options?: IdentifyOptions) => void;
|
|
452
|
+
__FA_logout?: (resetAnonymousIdentity?: boolean) => void;
|
|
453
|
+
__FA_setConsentMode?: (mode: ConsentMode) => void;
|
|
454
|
+
__FA_optIn?: () => void;
|
|
455
|
+
__FA_optOut?: () => void;
|
|
456
|
+
__FA_isTrackingDisabled?: () => boolean;
|
|
457
|
+
__FA_webAnalyticsInstance?: WebAnalytics;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
declare class WebAnalytics {
|
|
461
|
+
private readonly options;
|
|
462
|
+
private readonly endpoint;
|
|
463
|
+
private readonly debug;
|
|
464
|
+
private readonly baseUrl;
|
|
465
|
+
private started;
|
|
466
|
+
private pageKey;
|
|
467
|
+
private navTimer;
|
|
468
|
+
private heartbeatTimer;
|
|
469
|
+
private scrollDepth;
|
|
470
|
+
private pageEntryTime;
|
|
471
|
+
private pagePath;
|
|
472
|
+
private pageUrl;
|
|
473
|
+
private pageHash;
|
|
474
|
+
private hasLeftCurrentPage;
|
|
475
|
+
private scrollHandler;
|
|
476
|
+
private consentMode;
|
|
477
|
+
private readonly cookielessWhilePending;
|
|
478
|
+
constructor(options: WebAnalyticsOptions);
|
|
479
|
+
private log;
|
|
480
|
+
private init;
|
|
481
|
+
start(): void;
|
|
482
|
+
private load;
|
|
483
|
+
pageview(extra?: Dict): void;
|
|
484
|
+
track(name: string, extra?: Dict): void;
|
|
485
|
+
identify(externalId: string, email: string, options?: IdentifyOptions): void;
|
|
486
|
+
logout(resetAnonymousIdentity?: boolean): void;
|
|
487
|
+
setConsentMode(mode: ConsentMode): void;
|
|
488
|
+
optIn(): void;
|
|
489
|
+
optOut(): void;
|
|
490
|
+
getConsentMode(): ConsentMode;
|
|
491
|
+
private isCookielessMode;
|
|
492
|
+
private send;
|
|
493
|
+
private enterPage;
|
|
494
|
+
private leavePage;
|
|
495
|
+
private trackScroll;
|
|
496
|
+
private startHeartbeat;
|
|
497
|
+
private navigate;
|
|
498
|
+
private patch;
|
|
499
|
+
private links;
|
|
500
|
+
}
|
|
501
|
+
//#endregion
|
|
502
|
+
export { type ConsentMode, type IdentifyOptions, WebAnalytics, type WebAnalyticsOptions };
|