luzzi-analytics 0.1.0 → 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 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
- if (!apiKey) {
165
- console.error("[Luzzi] API key is required");
166
- return;
167
- }
168
- this.apiKey = apiKey;
169
- this.apiUrl = config.apiUrl || DEFAULT_API_URL;
170
- this.debug = config.debug || false;
171
- this.sessionId = this.generateSessionId();
172
- this.deviceInfo = this.collectDeviceInfo();
173
- this.queue.init(
174
- this.apiKey,
175
- this.apiUrl,
176
- config.batchSize || DEFAULT_BATCH_SIZE,
177
- config.flushInterval || DEFAULT_FLUSH_INTERVAL,
178
- this.debug
179
- );
180
- this.initialized = true;
181
- this.log("Initialized", { apiKey: apiKey.slice(0, 10) + "...", sessionId: this.sessionId });
182
- if (typeof window !== "undefined") {
183
- window.addEventListener("beforeunload", () => {
184
- this.flush();
185
- });
186
- window.addEventListener("visibilitychange", () => {
187
- if (document.visibilityState === "hidden") {
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
  /**
@@ -278,16 +287,18 @@ var LuzziCore = class {
278
287
  collectDeviceInfo() {
279
288
  const info = {};
280
289
  if (typeof window !== "undefined" && typeof navigator !== "undefined") {
281
- const ua = navigator.userAgent;
282
- if (ua.includes("Windows")) info.os = "windows";
283
- else if (ua.includes("Mac")) info.os = "macos";
284
- else if (ua.includes("Linux")) info.os = "linux";
285
- else if (ua.includes("Android")) info.os = "android";
286
- else if (ua.includes("iPhone") || ua.includes("iPad")) info.os = "ios";
287
- if (ua.includes("Chrome") && !ua.includes("Edg")) info.browser = "chrome";
288
- else if (ua.includes("Firefox")) info.browser = "firefox";
289
- else if (ua.includes("Safari") && !ua.includes("Chrome")) info.browser = "safari";
290
- else if (ua.includes("Edg")) info.browser = "edge";
290
+ const ua = navigator.userAgent || "";
291
+ if (ua && typeof ua === "string") {
292
+ if (ua.includes("Windows")) info.os = "windows";
293
+ else if (ua.includes("Mac")) info.os = "macos";
294
+ else if (ua.includes("Linux")) info.os = "linux";
295
+ else if (ua.includes("Android")) info.os = "android";
296
+ else if (ua.includes("iPhone") || ua.includes("iPad")) info.os = "ios";
297
+ if (ua.includes("Chrome") && !ua.includes("Edg")) info.browser = "chrome";
298
+ else if (ua.includes("Firefox")) info.browser = "firefox";
299
+ else if (ua.includes("Safari") && !ua.includes("Chrome")) info.browser = "safari";
300
+ else if (ua.includes("Edg")) info.browser = "edge";
301
+ }
291
302
  info.screen_width = window.screen?.width;
292
303
  info.screen_height = window.screen?.height;
293
304
  info.language = navigator.language;
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
- if (!apiKey) {
132
- console.error("[Luzzi] API key is required");
133
- return;
134
- }
135
- this.apiKey = apiKey;
136
- this.apiUrl = config.apiUrl || DEFAULT_API_URL;
137
- this.debug = config.debug || false;
138
- this.sessionId = this.generateSessionId();
139
- this.deviceInfo = this.collectDeviceInfo();
140
- this.queue.init(
141
- this.apiKey,
142
- this.apiUrl,
143
- config.batchSize || DEFAULT_BATCH_SIZE,
144
- config.flushInterval || DEFAULT_FLUSH_INTERVAL,
145
- this.debug
146
- );
147
- this.initialized = true;
148
- this.log("Initialized", { apiKey: apiKey.slice(0, 10) + "...", sessionId: this.sessionId });
149
- if (typeof window !== "undefined") {
150
- window.addEventListener("beforeunload", () => {
151
- this.flush();
152
- });
153
- window.addEventListener("visibilitychange", () => {
154
- if (document.visibilityState === "hidden") {
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
  /**
@@ -245,16 +254,18 @@ var LuzziCore = class {
245
254
  collectDeviceInfo() {
246
255
  const info = {};
247
256
  if (typeof window !== "undefined" && typeof navigator !== "undefined") {
248
- const ua = navigator.userAgent;
249
- if (ua.includes("Windows")) info.os = "windows";
250
- else if (ua.includes("Mac")) info.os = "macos";
251
- else if (ua.includes("Linux")) info.os = "linux";
252
- else if (ua.includes("Android")) info.os = "android";
253
- else if (ua.includes("iPhone") || ua.includes("iPad")) info.os = "ios";
254
- if (ua.includes("Chrome") && !ua.includes("Edg")) info.browser = "chrome";
255
- else if (ua.includes("Firefox")) info.browser = "firefox";
256
- else if (ua.includes("Safari") && !ua.includes("Chrome")) info.browser = "safari";
257
- else if (ua.includes("Edg")) info.browser = "edge";
257
+ const ua = navigator.userAgent || "";
258
+ if (ua && typeof ua === "string") {
259
+ if (ua.includes("Windows")) info.os = "windows";
260
+ else if (ua.includes("Mac")) info.os = "macos";
261
+ else if (ua.includes("Linux")) info.os = "linux";
262
+ else if (ua.includes("Android")) info.os = "android";
263
+ else if (ua.includes("iPhone") || ua.includes("iPad")) info.os = "ios";
264
+ if (ua.includes("Chrome") && !ua.includes("Edg")) info.browser = "chrome";
265
+ else if (ua.includes("Firefox")) info.browser = "firefox";
266
+ else if (ua.includes("Safari") && !ua.includes("Chrome")) info.browser = "safari";
267
+ else if (ua.includes("Edg")) info.browser = "edge";
268
+ }
258
269
  info.screen_width = window.screen?.width;
259
270
  info.screen_height = window.screen?.height;
260
271
  info.language = navigator.language;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "luzzi-analytics",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Simple, plug-and-play analytics SDK for solo builders",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",