@scoperat/tracker 0.1.1 → 0.2.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/dist/index.d.ts +163 -4
- package/dist/index.js +630 -2
- package/dist/index.js.map +1 -1
- package/dist/widget/index.d.ts +41 -0
- package/dist/widget/index.js +2633 -0
- package/dist/widget/index.js.map +1 -0
- package/dist/widget.global.js +970 -0
- package/dist/widget.global.js.map +1 -0
- package/package.json +15 -3
- package/dist/client.d.ts +0 -30
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -217
- package/dist/client.js.map +0 -1
- package/dist/context.d.ts +0 -5
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -24
- package/dist/context.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types.d.ts +0 -33
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scoperat/tracker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Browser analytics SDK",
|
|
5
|
+
"description": "Browser analytics SDK with embeddable support widget",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"engines": {
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
"events",
|
|
15
15
|
"telemetry",
|
|
16
16
|
"browser",
|
|
17
|
+
"support",
|
|
18
|
+
"widget",
|
|
17
19
|
"scoperat"
|
|
18
20
|
],
|
|
19
21
|
"main": "./dist/index.js",
|
|
@@ -22,17 +24,27 @@
|
|
|
22
24
|
".": {
|
|
23
25
|
"types": "./dist/index.d.ts",
|
|
24
26
|
"import": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./widget": {
|
|
29
|
+
"types": "./dist/widget/index.d.ts",
|
|
30
|
+
"import": "./dist/widget/index.js"
|
|
25
31
|
}
|
|
26
32
|
},
|
|
27
33
|
"files": [
|
|
28
34
|
"dist",
|
|
29
35
|
"README.md"
|
|
30
36
|
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"dompurify": "^3.4.0",
|
|
39
|
+
"marked": "^18.0.1",
|
|
40
|
+
"preact": "^10.29.1"
|
|
41
|
+
},
|
|
31
42
|
"devDependencies": {
|
|
43
|
+
"tsup": "^8.5.1",
|
|
32
44
|
"typescript": "^5"
|
|
33
45
|
},
|
|
34
46
|
"scripts": {
|
|
35
|
-
"build": "
|
|
47
|
+
"build": "tsup",
|
|
36
48
|
"clean": "rm -rf dist",
|
|
37
49
|
"type-check": "tsc --noEmit"
|
|
38
50
|
}
|
package/dist/client.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { FlushResult, IdentifyTraits, InitOptions, TrackEvent } from "./types.js";
|
|
2
|
-
declare class TrackerImpl {
|
|
3
|
-
private writeKey;
|
|
4
|
-
private endpoint;
|
|
5
|
-
private flushAt;
|
|
6
|
-
private flushInterval;
|
|
7
|
-
private timeout;
|
|
8
|
-
private onError?;
|
|
9
|
-
private buffer;
|
|
10
|
-
private timer;
|
|
11
|
-
private visibilityHandler;
|
|
12
|
-
private userId;
|
|
13
|
-
private orgId;
|
|
14
|
-
private traits;
|
|
15
|
-
private anonymousId;
|
|
16
|
-
private sessionTimeout;
|
|
17
|
-
init(writeKey: string, options?: InitOptions): void;
|
|
18
|
-
identify(userId: string, traits?: IdentifyTraits): void;
|
|
19
|
-
reset(): void;
|
|
20
|
-
private getOrCreateSessionId;
|
|
21
|
-
private clearSession;
|
|
22
|
-
track(event: string, properties?: Record<string, unknown>): void;
|
|
23
|
-
track(event: TrackEvent): void;
|
|
24
|
-
flush(): Promise<FlushResult>;
|
|
25
|
-
private flushSync;
|
|
26
|
-
shutdown(): Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
declare const scoperat: TrackerImpl;
|
|
29
|
-
export default scoperat;
|
|
30
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,WAAW,EACX,UAAU,EACX,MAAM,YAAY,CAAC;AAuCpB,cAAM,WAAW;IACf,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,aAAa,CAAkC;IACvD,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,OAAO,CAAC,CAA+C;IAE/D,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,KAAK,CAA+C;IAC5D,OAAO,CAAC,iBAAiB,CAA6B;IACtD,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,KAAK,CAAqB;IAClC,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,cAAc,CAAmC;IAEzD,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,IAAI;IAmCvD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI;IAQvD,KAAK,IAAI,IAAI;IAQb,OAAO,CAAC,oBAAoB;IAyB5B,OAAO,CAAC,YAAY;IAUpB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAChE,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAqCxB,KAAK,IAAI,OAAO,CAAC,WAAW,CAAC;IAiCnC,OAAO,CAAC,SAAS;IAiBX,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAehC;AAED,QAAA,MAAM,QAAQ,aAAoB,CAAC;AACnC,eAAe,QAAQ,CAAC"}
|
package/dist/client.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { getBrowserContext } from "./context.js";
|
|
2
|
-
const DEFAULT_FLUSH_AT = 10;
|
|
3
|
-
const DEFAULT_FLUSH_INTERVAL = 3_000;
|
|
4
|
-
const DEFAULT_TIMEOUT = 10_000;
|
|
5
|
-
const DEFAULT_SESSION_TIMEOUT = 30 * 60 * 1_000; // 30 minutes
|
|
6
|
-
const MAX_BATCH_SIZE = 100;
|
|
7
|
-
const ANON_ID_KEY = "__scoperat_anon_id";
|
|
8
|
-
const SESSION_ID_KEY = "__scoperat_session_id";
|
|
9
|
-
const LAST_ACTIVITY_KEY = "__scoperat_last_activity";
|
|
10
|
-
function generateAnonId() {
|
|
11
|
-
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
12
|
-
return crypto.randomUUID();
|
|
13
|
-
}
|
|
14
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
15
|
-
const r = (Math.random() * 16) | 0;
|
|
16
|
-
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
17
|
-
return v.toString(16);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
function getOrCreateAnonId() {
|
|
21
|
-
if (typeof window === "undefined" || typeof localStorage === "undefined") {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
let id = localStorage.getItem(ANON_ID_KEY);
|
|
26
|
-
if (!id) {
|
|
27
|
-
id = generateAnonId();
|
|
28
|
-
localStorage.setItem(ANON_ID_KEY, id);
|
|
29
|
-
}
|
|
30
|
-
return id;
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return generateAnonId();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
class TrackerImpl {
|
|
37
|
-
writeKey = null;
|
|
38
|
-
endpoint = "";
|
|
39
|
-
flushAt = DEFAULT_FLUSH_AT;
|
|
40
|
-
flushInterval = DEFAULT_FLUSH_INTERVAL;
|
|
41
|
-
timeout = DEFAULT_TIMEOUT;
|
|
42
|
-
onError;
|
|
43
|
-
buffer = [];
|
|
44
|
-
timer = null;
|
|
45
|
-
visibilityHandler = null;
|
|
46
|
-
userId;
|
|
47
|
-
orgId;
|
|
48
|
-
traits = {};
|
|
49
|
-
anonymousId;
|
|
50
|
-
sessionTimeout = DEFAULT_SESSION_TIMEOUT;
|
|
51
|
-
init(writeKey, options = {}) {
|
|
52
|
-
this.writeKey = writeKey;
|
|
53
|
-
this.endpoint = (options.endpoint ??
|
|
54
|
-
globalThis.location?.origin ??
|
|
55
|
-
"").replace(/\/+$/, "");
|
|
56
|
-
this.flushAt = options.flushAt ?? DEFAULT_FLUSH_AT;
|
|
57
|
-
this.flushInterval = options.flushInterval ?? DEFAULT_FLUSH_INTERVAL;
|
|
58
|
-
this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
59
|
-
this.onError = options.onError;
|
|
60
|
-
this.sessionTimeout = options.sessionTimeout ?? DEFAULT_SESSION_TIMEOUT;
|
|
61
|
-
this.anonymousId = getOrCreateAnonId();
|
|
62
|
-
if (this.timer)
|
|
63
|
-
clearInterval(this.timer);
|
|
64
|
-
this.timer = setInterval(() => {
|
|
65
|
-
if (this.buffer.length > 0) {
|
|
66
|
-
this.flush().catch(() => { });
|
|
67
|
-
}
|
|
68
|
-
}, this.flushInterval);
|
|
69
|
-
if (typeof window !== "undefined") {
|
|
70
|
-
if (this.visibilityHandler) {
|
|
71
|
-
window.removeEventListener("visibilitychange", this.visibilityHandler);
|
|
72
|
-
}
|
|
73
|
-
this.visibilityHandler = () => {
|
|
74
|
-
if (document.visibilityState === "hidden" && this.buffer.length > 0) {
|
|
75
|
-
this.flushSync();
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
window.addEventListener("visibilitychange", this.visibilityHandler);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
identify(userId, traits) {
|
|
82
|
-
this.userId = userId;
|
|
83
|
-
if (traits) {
|
|
84
|
-
this.traits = { ...traits };
|
|
85
|
-
if (traits.orgId)
|
|
86
|
-
this.orgId = traits.orgId;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
reset() {
|
|
90
|
-
this.userId = undefined;
|
|
91
|
-
this.orgId = undefined;
|
|
92
|
-
this.traits = {};
|
|
93
|
-
this.anonymousId = getOrCreateAnonId();
|
|
94
|
-
this.clearSession();
|
|
95
|
-
}
|
|
96
|
-
getOrCreateSessionId() {
|
|
97
|
-
if (typeof window === "undefined")
|
|
98
|
-
return undefined;
|
|
99
|
-
try {
|
|
100
|
-
const now = Date.now();
|
|
101
|
-
const lastActivity = localStorage.getItem(LAST_ACTIVITY_KEY);
|
|
102
|
-
const existingId = sessionStorage.getItem(SESSION_ID_KEY);
|
|
103
|
-
const expired = !lastActivity || now - Number(lastActivity) > this.sessionTimeout;
|
|
104
|
-
if (existingId && !expired) {
|
|
105
|
-
localStorage.setItem(LAST_ACTIVITY_KEY, String(now));
|
|
106
|
-
return existingId;
|
|
107
|
-
}
|
|
108
|
-
const newId = generateAnonId();
|
|
109
|
-
sessionStorage.setItem(SESSION_ID_KEY, newId);
|
|
110
|
-
localStorage.setItem(LAST_ACTIVITY_KEY, String(now));
|
|
111
|
-
return newId;
|
|
112
|
-
}
|
|
113
|
-
catch {
|
|
114
|
-
return generateAnonId();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
clearSession() {
|
|
118
|
-
if (typeof window === "undefined")
|
|
119
|
-
return;
|
|
120
|
-
try {
|
|
121
|
-
sessionStorage.removeItem(SESSION_ID_KEY);
|
|
122
|
-
localStorage.removeItem(LAST_ACTIVITY_KEY);
|
|
123
|
-
}
|
|
124
|
-
catch {
|
|
125
|
-
// Ignore storage errors
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
track(eventOrName, properties) {
|
|
129
|
-
if (!this.writeKey)
|
|
130
|
-
return;
|
|
131
|
-
const evt = typeof eventOrName === "string"
|
|
132
|
-
? { event: eventOrName, properties }
|
|
133
|
-
: eventOrName;
|
|
134
|
-
const traitsContext = Object.keys(this.traits).length > 0 ? { traits: this.traits } : {};
|
|
135
|
-
const enriched = {
|
|
136
|
-
...evt,
|
|
137
|
-
occurred_at: evt.occurred_at ?? new Date().toISOString(),
|
|
138
|
-
source: evt.source ?? "browser",
|
|
139
|
-
org_id: evt.org_id ?? this.orgId,
|
|
140
|
-
user_id: evt.user_id ?? this.userId,
|
|
141
|
-
anonymous_id: evt.anonymous_id ?? this.anonymousId,
|
|
142
|
-
session_id: evt.session_id ?? this.getOrCreateSessionId(),
|
|
143
|
-
context: {
|
|
144
|
-
...getBrowserContext(),
|
|
145
|
-
...traitsContext,
|
|
146
|
-
...evt.context,
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
this.buffer.push(enriched);
|
|
150
|
-
if (this.buffer.length >= this.flushAt) {
|
|
151
|
-
this.flush().catch(() => { });
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
async flush() {
|
|
155
|
-
if (!this.writeKey || this.buffer.length === 0) {
|
|
156
|
-
return { success: true, ingested: 0 };
|
|
157
|
-
}
|
|
158
|
-
const batch = this.buffer.splice(0, MAX_BATCH_SIZE);
|
|
159
|
-
try {
|
|
160
|
-
const res = await fetch(`${this.endpoint}/api/ingest/track`, {
|
|
161
|
-
method: "POST",
|
|
162
|
-
headers: {
|
|
163
|
-
"Content-Type": "application/json",
|
|
164
|
-
Authorization: `Bearer ${this.writeKey}`,
|
|
165
|
-
},
|
|
166
|
-
body: JSON.stringify({ events: batch }),
|
|
167
|
-
signal: AbortSignal.timeout(this.timeout),
|
|
168
|
-
});
|
|
169
|
-
if (!res.ok) {
|
|
170
|
-
const body = await res.text().catch(() => "");
|
|
171
|
-
throw new Error(`API returned ${res.status}: ${body}`);
|
|
172
|
-
}
|
|
173
|
-
const json = (await res.json());
|
|
174
|
-
return { success: true, ingested: json.ingested };
|
|
175
|
-
}
|
|
176
|
-
catch (error) {
|
|
177
|
-
this.buffer.unshift(...batch);
|
|
178
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
179
|
-
this.onError?.(err, batch);
|
|
180
|
-
return { success: false, ingested: 0 };
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
flushSync() {
|
|
184
|
-
if (!this.writeKey)
|
|
185
|
-
return;
|
|
186
|
-
if (typeof navigator === "undefined" || !navigator.sendBeacon)
|
|
187
|
-
return;
|
|
188
|
-
if (this.buffer.length === 0)
|
|
189
|
-
return;
|
|
190
|
-
const batch = this.buffer.splice(0, MAX_BATCH_SIZE);
|
|
191
|
-
const payload = JSON.stringify({ events: batch });
|
|
192
|
-
const url = `${this.endpoint}/api/ingest/track?key=${encodeURIComponent(this.writeKey)}`;
|
|
193
|
-
try {
|
|
194
|
-
const blob = new Blob([payload], { type: "application/json" });
|
|
195
|
-
navigator.sendBeacon(url, blob);
|
|
196
|
-
}
|
|
197
|
-
catch {
|
|
198
|
-
// Best effort on unload
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
async shutdown() {
|
|
202
|
-
if (this.timer) {
|
|
203
|
-
clearInterval(this.timer);
|
|
204
|
-
this.timer = null;
|
|
205
|
-
}
|
|
206
|
-
if (typeof window !== "undefined" && this.visibilityHandler) {
|
|
207
|
-
window.removeEventListener("visibilitychange", this.visibilityHandler);
|
|
208
|
-
this.visibilityHandler = null;
|
|
209
|
-
}
|
|
210
|
-
while (this.buffer.length > 0) {
|
|
211
|
-
await this.flush();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
const scoperat = new TrackerImpl();
|
|
216
|
-
export default scoperat;
|
|
217
|
-
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../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BAAiB,EAAE,CAAC;YAC5D,MAAM,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;YACvE,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAChC,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;CACF;AAED,MAAM,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC;AACnC,eAAe,QAAQ,CAAC"}
|
package/dist/context.d.ts
DELETED
package/dist/context.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoB3D"}
|
package/dist/context.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-capture browser context: page, referrer, screen, locale, user agent.
|
|
3
|
-
*/
|
|
4
|
-
export function getBrowserContext() {
|
|
5
|
-
if (typeof window === "undefined") {
|
|
6
|
-
return {};
|
|
7
|
-
}
|
|
8
|
-
return {
|
|
9
|
-
page: {
|
|
10
|
-
url: window.location.href,
|
|
11
|
-
path: window.location.pathname,
|
|
12
|
-
title: document.title,
|
|
13
|
-
referrer: document.referrer || undefined,
|
|
14
|
-
},
|
|
15
|
-
screen: {
|
|
16
|
-
width: window.screen.width,
|
|
17
|
-
height: window.screen.height,
|
|
18
|
-
},
|
|
19
|
-
locale: navigator.language,
|
|
20
|
-
userAgent: navigator.userAgent,
|
|
21
|
-
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO;QACL,IAAI,EAAE;YACJ,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;YACzB,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ;YAC9B,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,QAAQ,EAAE,QAAQ,CAAC,QAAQ,IAAI,SAAS;SACzC;QACD,MAAM,EAAE;YACN,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM;SAC7B;QACD,MAAM,EAAE,SAAS,CAAC,QAAQ;QAC1B,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,QAAQ,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,eAAe,EAAE,CAAC,QAAQ;KAC3D,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,aAAa,CAAC;AAEnC,eAAe,QAAQ,CAAC;AACxB,YAAY,EACV,WAAW,EACX,WAAW,EACX,cAAc,EACd,WAAW,EACX,UAAU,GACX,MAAM,YAAY,CAAC"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export type EventSource = "browser" | "server" | "worker";
|
|
2
|
-
export interface TrackEvent {
|
|
3
|
-
event: string;
|
|
4
|
-
properties?: Record<string, unknown>;
|
|
5
|
-
context?: Record<string, unknown>;
|
|
6
|
-
source?: EventSource;
|
|
7
|
-
occurred_at?: Date | string;
|
|
8
|
-
org_id?: string;
|
|
9
|
-
user_id?: string;
|
|
10
|
-
anonymous_id?: string;
|
|
11
|
-
session_id?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface IdentifyTraits {
|
|
14
|
-
orgId?: string;
|
|
15
|
-
orgName?: string;
|
|
16
|
-
email?: string;
|
|
17
|
-
name?: string;
|
|
18
|
-
[key: string]: unknown;
|
|
19
|
-
}
|
|
20
|
-
export interface InitOptions {
|
|
21
|
-
endpoint?: string;
|
|
22
|
-
flushAt?: number;
|
|
23
|
-
flushInterval?: number;
|
|
24
|
-
timeout?: number;
|
|
25
|
-
onError?: (error: Error, events: TrackEvent[]) => void;
|
|
26
|
-
/** Session inactivity timeout in ms. Defaults to 30 minutes. */
|
|
27
|
-
sessionTimeout?: number;
|
|
28
|
-
}
|
|
29
|
-
export interface FlushResult {
|
|
30
|
-
success: boolean;
|
|
31
|
-
ingested: number;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE1D,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,WAAW,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC;IACvD,gEAAgE;IAChE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|