luzzi-analytics 0.1.1 → 0.1.2
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.js +35 -26
- package/dist/index.mjs +35 -26
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -161,33 +161,42 @@ var LuzziCore = class {
|
|
|
161
161
|
* Must be called before any other method
|
|
162
162
|
*/
|
|
163
163
|
init(apiKey, config = {}) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
this.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
164
|
+
try {
|
|
165
|
+
if (!apiKey) {
|
|
166
|
+
console.error("[Luzzi] API key is required");
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this.apiKey = apiKey;
|
|
170
|
+
this.apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
171
|
+
this.debug = config.debug || false;
|
|
172
|
+
this.sessionId = this.generateSessionId();
|
|
173
|
+
try {
|
|
174
|
+
this.deviceInfo = this.collectDeviceInfo();
|
|
175
|
+
} catch {
|
|
176
|
+
this.deviceInfo = {};
|
|
177
|
+
}
|
|
178
|
+
this.queue.init(
|
|
179
|
+
this.apiKey,
|
|
180
|
+
this.apiUrl,
|
|
181
|
+
config.batchSize || DEFAULT_BATCH_SIZE,
|
|
182
|
+
config.flushInterval || DEFAULT_FLUSH_INTERVAL,
|
|
183
|
+
this.debug
|
|
184
|
+
);
|
|
185
|
+
this.initialized = true;
|
|
186
|
+
this.log("Initialized", { apiKey: apiKey.slice(0, 10) + "...", sessionId: this.sessionId });
|
|
187
|
+
if (typeof window !== "undefined") {
|
|
188
|
+
window.addEventListener("beforeunload", () => {
|
|
188
189
|
this.flush();
|
|
189
|
-
}
|
|
190
|
-
|
|
190
|
+
});
|
|
191
|
+
window.addEventListener("visibilitychange", () => {
|
|
192
|
+
if (document.visibilityState === "hidden") {
|
|
193
|
+
this.flush();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.warn("[Luzzi] Failed to initialize:", error);
|
|
199
|
+
this.initialized = true;
|
|
191
200
|
}
|
|
192
201
|
}
|
|
193
202
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -128,33 +128,42 @@ var LuzziCore = class {
|
|
|
128
128
|
* Must be called before any other method
|
|
129
129
|
*/
|
|
130
130
|
init(apiKey, config = {}) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
131
|
+
try {
|
|
132
|
+
if (!apiKey) {
|
|
133
|
+
console.error("[Luzzi] API key is required");
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.apiKey = apiKey;
|
|
137
|
+
this.apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
138
|
+
this.debug = config.debug || false;
|
|
139
|
+
this.sessionId = this.generateSessionId();
|
|
140
|
+
try {
|
|
141
|
+
this.deviceInfo = this.collectDeviceInfo();
|
|
142
|
+
} catch {
|
|
143
|
+
this.deviceInfo = {};
|
|
144
|
+
}
|
|
145
|
+
this.queue.init(
|
|
146
|
+
this.apiKey,
|
|
147
|
+
this.apiUrl,
|
|
148
|
+
config.batchSize || DEFAULT_BATCH_SIZE,
|
|
149
|
+
config.flushInterval || DEFAULT_FLUSH_INTERVAL,
|
|
150
|
+
this.debug
|
|
151
|
+
);
|
|
152
|
+
this.initialized = true;
|
|
153
|
+
this.log("Initialized", { apiKey: apiKey.slice(0, 10) + "...", sessionId: this.sessionId });
|
|
154
|
+
if (typeof window !== "undefined") {
|
|
155
|
+
window.addEventListener("beforeunload", () => {
|
|
155
156
|
this.flush();
|
|
156
|
-
}
|
|
157
|
-
|
|
157
|
+
});
|
|
158
|
+
window.addEventListener("visibilitychange", () => {
|
|
159
|
+
if (document.visibilityState === "hidden") {
|
|
160
|
+
this.flush();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.warn("[Luzzi] Failed to initialize:", error);
|
|
166
|
+
this.initialized = true;
|
|
158
167
|
}
|
|
159
168
|
}
|
|
160
169
|
/**
|