@qurvo/sdk-browser 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/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/package.json +26 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface BrowserSdkConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
endpoint?: string;
|
|
4
|
+
autocapture?: boolean;
|
|
5
|
+
flushInterval?: number;
|
|
6
|
+
flushSize?: number;
|
|
7
|
+
}
|
|
8
|
+
declare class QurvoBrowser {
|
|
9
|
+
private queue;
|
|
10
|
+
private userId;
|
|
11
|
+
private initialized;
|
|
12
|
+
init(config: BrowserSdkConfig): void;
|
|
13
|
+
track(event: string, properties?: Record<string, unknown>): void;
|
|
14
|
+
identify(userId: string, userProperties?: Record<string, unknown>): void;
|
|
15
|
+
page(properties?: Record<string, unknown>): void;
|
|
16
|
+
set(properties: Record<string, unknown>): void;
|
|
17
|
+
setOnce(properties: Record<string, unknown>): void;
|
|
18
|
+
reset(): void;
|
|
19
|
+
private setupAutocapture;
|
|
20
|
+
private setupBeaconFlush;
|
|
21
|
+
}
|
|
22
|
+
export declare const qurvo: QurvoBrowser;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA8CA,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,cAAM,YAAY;IAChB,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,WAAW,CAAS;IAE5B,IAAI,CAAC,MAAM,EAAE,gBAAgB;IAwB7B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAczD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAejE,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIzC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAcvC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAc3C,KAAK;IAML,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,gBAAgB;CAczB;AAED,eAAO,MAAM,KAAK,cAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.qurvo = void 0;
|
|
4
|
+
const sdk_core_1 = require("@qurvo/sdk-core");
|
|
5
|
+
const SDK_NAME = '@qurvo/sdk-browser';
|
|
6
|
+
const SDK_VERSION = '0.0.1';
|
|
7
|
+
const ANON_ID_KEY = 'qurvo_anonymous_id';
|
|
8
|
+
const SESSION_ID_KEY = 'qurvo_session_id';
|
|
9
|
+
function generateId() {
|
|
10
|
+
return crypto.randomUUID?.() || Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
11
|
+
}
|
|
12
|
+
function getAnonymousId() {
|
|
13
|
+
let id = localStorage.getItem(ANON_ID_KEY);
|
|
14
|
+
if (!id) {
|
|
15
|
+
id = generateId();
|
|
16
|
+
localStorage.setItem(ANON_ID_KEY, id);
|
|
17
|
+
}
|
|
18
|
+
return id;
|
|
19
|
+
}
|
|
20
|
+
function getSessionId() {
|
|
21
|
+
let id = sessionStorage.getItem(SESSION_ID_KEY);
|
|
22
|
+
if (!id) {
|
|
23
|
+
id = generateId();
|
|
24
|
+
sessionStorage.setItem(SESSION_ID_KEY, id);
|
|
25
|
+
}
|
|
26
|
+
return id;
|
|
27
|
+
}
|
|
28
|
+
function getContext() {
|
|
29
|
+
return {
|
|
30
|
+
session_id: getSessionId(),
|
|
31
|
+
url: window.location.href,
|
|
32
|
+
referrer: document.referrer,
|
|
33
|
+
page_title: document.title,
|
|
34
|
+
page_path: window.location.pathname,
|
|
35
|
+
screen_width: window.screen.width,
|
|
36
|
+
screen_height: window.screen.height,
|
|
37
|
+
language: navigator.language,
|
|
38
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
39
|
+
sdk_name: SDK_NAME,
|
|
40
|
+
sdk_version: SDK_VERSION,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
class QurvoBrowser {
|
|
44
|
+
queue = null;
|
|
45
|
+
userId = null;
|
|
46
|
+
initialized = false;
|
|
47
|
+
init(config) {
|
|
48
|
+
if (this.initialized)
|
|
49
|
+
return;
|
|
50
|
+
const endpoint = config.endpoint || 'http://localhost:3001';
|
|
51
|
+
const transport = new sdk_core_1.FetchTransport();
|
|
52
|
+
this.queue = new sdk_core_1.EventQueue(transport, `${endpoint}/v1/batch`, config.apiKey, config.flushInterval || 10000, config.flushSize || 10, 1000);
|
|
53
|
+
this.queue.start();
|
|
54
|
+
this.initialized = true;
|
|
55
|
+
if (config.autocapture !== false) {
|
|
56
|
+
this.setupAutocapture();
|
|
57
|
+
}
|
|
58
|
+
this.setupBeaconFlush();
|
|
59
|
+
this.page();
|
|
60
|
+
}
|
|
61
|
+
track(event, properties) {
|
|
62
|
+
if (!this.queue)
|
|
63
|
+
return;
|
|
64
|
+
const payload = {
|
|
65
|
+
event,
|
|
66
|
+
distinct_id: this.userId || getAnonymousId(),
|
|
67
|
+
anonymous_id: getAnonymousId(),
|
|
68
|
+
properties,
|
|
69
|
+
context: getContext(),
|
|
70
|
+
timestamp: new Date().toISOString(),
|
|
71
|
+
};
|
|
72
|
+
this.queue.enqueue(payload);
|
|
73
|
+
}
|
|
74
|
+
identify(userId, userProperties) {
|
|
75
|
+
if (!this.queue)
|
|
76
|
+
return;
|
|
77
|
+
this.userId = userId;
|
|
78
|
+
const payload = {
|
|
79
|
+
event: '$identify',
|
|
80
|
+
distinct_id: userId,
|
|
81
|
+
anonymous_id: getAnonymousId(),
|
|
82
|
+
user_properties: userProperties,
|
|
83
|
+
context: getContext(),
|
|
84
|
+
timestamp: new Date().toISOString(),
|
|
85
|
+
};
|
|
86
|
+
this.queue.enqueue(payload);
|
|
87
|
+
}
|
|
88
|
+
page(properties) {
|
|
89
|
+
this.track('$pageview', properties);
|
|
90
|
+
}
|
|
91
|
+
set(properties) {
|
|
92
|
+
if (!this.queue)
|
|
93
|
+
return;
|
|
94
|
+
const payload = {
|
|
95
|
+
event: '$set',
|
|
96
|
+
distinct_id: this.userId || getAnonymousId(),
|
|
97
|
+
anonymous_id: getAnonymousId(),
|
|
98
|
+
user_properties: { $set: properties },
|
|
99
|
+
context: getContext(),
|
|
100
|
+
timestamp: new Date().toISOString(),
|
|
101
|
+
};
|
|
102
|
+
this.queue.enqueue(payload);
|
|
103
|
+
}
|
|
104
|
+
setOnce(properties) {
|
|
105
|
+
if (!this.queue)
|
|
106
|
+
return;
|
|
107
|
+
const payload = {
|
|
108
|
+
event: '$set_once',
|
|
109
|
+
distinct_id: this.userId || getAnonymousId(),
|
|
110
|
+
anonymous_id: getAnonymousId(),
|
|
111
|
+
user_properties: { $set_once: properties },
|
|
112
|
+
context: getContext(),
|
|
113
|
+
timestamp: new Date().toISOString(),
|
|
114
|
+
};
|
|
115
|
+
this.queue.enqueue(payload);
|
|
116
|
+
}
|
|
117
|
+
reset() {
|
|
118
|
+
this.userId = null;
|
|
119
|
+
localStorage.removeItem(ANON_ID_KEY);
|
|
120
|
+
sessionStorage.removeItem(SESSION_ID_KEY);
|
|
121
|
+
}
|
|
122
|
+
setupAutocapture() {
|
|
123
|
+
const originalPushState = history.pushState;
|
|
124
|
+
history.pushState = (...args) => {
|
|
125
|
+
originalPushState.apply(history, args);
|
|
126
|
+
this.page();
|
|
127
|
+
};
|
|
128
|
+
window.addEventListener('popstate', () => {
|
|
129
|
+
this.page();
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
setupBeaconFlush() {
|
|
133
|
+
const flushForUnload = () => {
|
|
134
|
+
this.track('$pageleave');
|
|
135
|
+
if (this.queue && this.queue.size > 0) {
|
|
136
|
+
this.queue.flushForUnload();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
document.addEventListener('visibilitychange', () => {
|
|
140
|
+
if (document.visibilityState === 'hidden')
|
|
141
|
+
flushForUnload();
|
|
142
|
+
});
|
|
143
|
+
window.addEventListener('beforeunload', flushForUnload);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.qurvo = new QurvoBrowser();
|
|
147
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,8CAA6D;AAG7D,MAAM,QAAQ,GAAG,oBAAoB,CAAC;AACtC,MAAM,WAAW,GAAG,OAAO,CAAC;AAC5B,MAAM,WAAW,GAAG,oBAAoB,CAAC;AACzC,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAE1C,SAAS,UAAU;IACjB,OAAO,MAAM,CAAC,UAAU,EAAE,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACpG,CAAC;AAED,SAAS,cAAc;IACrB,IAAI,EAAE,GAAG,YAAY,C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AAC;IAEO,gBAAgB;QACtB,MAAM,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC;QAC5C,OAAO,CAAC,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;YAC9B,iBAAiB,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACvC,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,GAAG,EAAE;YACvC,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,gBAAgB;QACtB,MAAM,cAAc,GAAG,GAAG,EAAE;YAC1B,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YACzB,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;gBACtC,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;YAC9B,CAAC;QACH,CAAC,CAAC;QAEF,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,GAAG,EAAE;YACjD,IAAI,QAAQ,CAAC,eAAe,KAAK,QAAQ;gBAAE,cAAc,EAAE,CAAC;QAC9D,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IAC1D,CAAC;CACF;AAEY,QAAA,KAAK,GAAG,IAAI,YAAY,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qurvo/sdk-browser",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Browser SDK for Qurvo analytics — event tracking, user identification, auto-capture",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@qurvo/sdk-core": "0.0.1"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.7.0",
|
|
19
|
+
"@qurvo/tsconfig": "0.0.0"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"dev": "tsc --watch",
|
|
24
|
+
"clean": "rm -rf dist .turbo"
|
|
25
|
+
}
|
|
26
|
+
}
|