@levo-so/core 0.1.27 → 0.1.28
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
|
@@ -77,7 +77,9 @@ var LevoClient = class {
|
|
|
77
77
|
if (this.#pageContext && typeof this.#pageContext === "object" && Object.keys(this.#pageContext).length > 0) {
|
|
78
78
|
options.headers = {
|
|
79
79
|
...options?.headers || {},
|
|
80
|
-
"Levo-Page-Context":
|
|
80
|
+
"Levo-Page-Context": encodeURIComponent(
|
|
81
|
+
JSON.stringify(this.#pageContext)
|
|
82
|
+
)
|
|
81
83
|
};
|
|
82
84
|
}
|
|
83
85
|
return wretch(this.apiUrl, options).addon(QueryStringAddon);
|
|
@@ -19,7 +19,7 @@ export declare class LevoAudience extends LevoPlugin {
|
|
|
19
19
|
};
|
|
20
20
|
startActivityListener(): any;
|
|
21
21
|
track(event: string, properties: ILevoAudience.Properties): Promise<any>;
|
|
22
|
-
getCurrentTabId(): string
|
|
23
|
-
getTabCount(): number
|
|
22
|
+
getCurrentTabId(): string;
|
|
23
|
+
getTabCount(): number;
|
|
24
24
|
}
|
|
25
25
|
//# sourceMappingURL=LevoAudience.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LevoAudience.d.ts","sourceRoot":"","sources":["../../src/plugins/LevoAudience.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAKvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,YAAa,SAAQ,UAAU;;IAC1C,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAQ;
|
|
1
|
+
{"version":3,"file":"LevoAudience.d.ts","sourceRoot":"","sources":["../../src/plugins/LevoAudience.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAKvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,YAAa,SAAQ,UAAU;;IAC1C,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAQ;IAmB1C,OAAO,CAAC,YAAY,GAAG,OAAO,EAAE,WAAW,GAAG,OAAO,EACnD,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW;IA8Bb,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,UAAU;IAkInD,WAAW;;;;;;;;;;;IAmEX,qBAAqB;IAqBf,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,UAAU;IAkC/D,eAAe;IAaf,WAAW;CAYZ"}
|
|
@@ -210,13 +210,14 @@ var getUserProperties = async () => {
|
|
|
210
210
|
var LevoAudience = class extends LevoPlugin {
|
|
211
211
|
instance = null;
|
|
212
212
|
#IDLE_THROTTLE = 1 * 1e3;
|
|
213
|
-
// every 1 second we check for
|
|
213
|
+
// every 1 second we check for idleness
|
|
214
214
|
#IDLE_TIMEOUT = 60 * 1e3;
|
|
215
215
|
// 60 seconds till we consider user idle
|
|
216
216
|
#session = "";
|
|
217
217
|
#device = "";
|
|
218
218
|
#is_identified = false;
|
|
219
219
|
#batch = [];
|
|
220
|
+
#events = [];
|
|
220
221
|
request(url, data) {
|
|
221
222
|
const headers = {
|
|
222
223
|
Accept: "application/json",
|
|
@@ -227,7 +228,9 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
227
228
|
}
|
|
228
229
|
const pageContext = this.client.getPageContext();
|
|
229
230
|
if (pageContext) {
|
|
230
|
-
headers["Levo-Page-Context"] =
|
|
231
|
+
headers["Levo-Page-Context"] = encodeURIComponent(
|
|
232
|
+
JSON.stringify(pageContext)
|
|
233
|
+
);
|
|
231
234
|
}
|
|
232
235
|
return wretch(url, {
|
|
233
236
|
credentials: "include"
|
|
@@ -250,27 +253,37 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
250
253
|
session_id: this.#session,
|
|
251
254
|
device_id: this.#device,
|
|
252
255
|
event: payload.event,
|
|
256
|
+
workspace_id: this.client.workspace,
|
|
253
257
|
properties: {
|
|
254
258
|
...properties,
|
|
255
259
|
...payloadProperties,
|
|
256
260
|
resource: void 0,
|
|
257
|
-
identifier: void 0
|
|
261
|
+
identifier: void 0,
|
|
262
|
+
hostname: void 0,
|
|
263
|
+
pathname: void 0,
|
|
264
|
+
url: void 0,
|
|
265
|
+
page_title: void 0,
|
|
266
|
+
created_at: void 0
|
|
258
267
|
},
|
|
259
|
-
hostname: window.location.hostname,
|
|
260
|
-
pathname: window.location.pathname,
|
|
261
|
-
url: window.location.href,
|
|
262
|
-
page_title: document.title,
|
|
268
|
+
hostname: payload?.hostname || window.location.hostname,
|
|
269
|
+
pathname: payload?.pathname || window.location.pathname,
|
|
270
|
+
url: payload?.url || window.location.href,
|
|
271
|
+
page_title: payload?.page_title || document.title,
|
|
263
272
|
resource: payloadProperties?.resource || "page",
|
|
264
273
|
identifier: payloadProperties?.identifier || properties?.id,
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
tab_count: this.getTabCount() || 0
|
|
274
|
+
created_at: payload?.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
275
|
+
tab_id: this.getCurrentTabId(),
|
|
276
|
+
tab_count: this.getTabCount()
|
|
269
277
|
};
|
|
270
|
-
navigator.sendBeacon(
|
|
278
|
+
const isQueued = navigator.sendBeacon(
|
|
271
279
|
`${this?.client?.insightsUrl}/v1/insights/event/collect`,
|
|
272
280
|
JSON.stringify(collectInput)
|
|
273
281
|
);
|
|
282
|
+
this.#events.push({
|
|
283
|
+
input: payload,
|
|
284
|
+
payload: collectInput,
|
|
285
|
+
queued: isQueued
|
|
286
|
+
});
|
|
274
287
|
},
|
|
275
288
|
page: ({ payload }) => {
|
|
276
289
|
if (!this?.client?.insightsUrl) {
|
|
@@ -283,7 +296,7 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
283
296
|
title: document.title,
|
|
284
297
|
identifier: properties.id,
|
|
285
298
|
resource: "page"
|
|
286
|
-
})
|
|
299
|
+
});
|
|
287
300
|
},
|
|
288
301
|
identify: ({ payload }) => {
|
|
289
302
|
if (!this?.client?.insightsUrl || !this.client.workspace) {
|
|
@@ -301,8 +314,8 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
301
314
|
page_title: document.title,
|
|
302
315
|
url: window.location.href,
|
|
303
316
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
304
|
-
tab_id: this.getCurrentTabId()
|
|
305
|
-
tab_count: this.getTabCount()
|
|
317
|
+
tab_id: this.getCurrentTabId(),
|
|
318
|
+
tab_count: this.getTabCount()
|
|
306
319
|
};
|
|
307
320
|
this.request(
|
|
308
321
|
`${this?.client?.insightsUrl}/v1/insights/event/welcome`,
|
|
@@ -311,10 +324,10 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
311
324
|
this.#is_identified = true;
|
|
312
325
|
this.#session = data.content.data.session;
|
|
313
326
|
this.#device = data.content.data.device;
|
|
314
|
-
|
|
315
|
-
`${this?.client?.insightsUrl}/v1/insights/event/
|
|
316
|
-
this.#batch
|
|
317
|
-
)
|
|
327
|
+
navigator.sendBeacon(
|
|
328
|
+
`${this?.client?.insightsUrl}/v1/insights/event/bulk?workspace=${this?.client?.workspace}`,
|
|
329
|
+
JSON.stringify(this.#batch)
|
|
330
|
+
);
|
|
318
331
|
}).catch((e) => getLevoError(e));
|
|
319
332
|
}
|
|
320
333
|
};
|
|
@@ -385,7 +398,12 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
385
398
|
properties: {
|
|
386
399
|
...properties,
|
|
387
400
|
resource: void 0,
|
|
388
|
-
identifier: void 0
|
|
401
|
+
identifier: void 0,
|
|
402
|
+
hostname: void 0,
|
|
403
|
+
pathname: void 0,
|
|
404
|
+
url: void 0,
|
|
405
|
+
page_title: void 0,
|
|
406
|
+
created_at: void 0
|
|
389
407
|
},
|
|
390
408
|
hostname: window.location.hostname,
|
|
391
409
|
pathname: window.location.pathname,
|
|
@@ -395,25 +413,25 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
395
413
|
identifier: properties?.identifier || properties?.id,
|
|
396
414
|
workspace_id: this.client.workspace,
|
|
397
415
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
398
|
-
tab_id: this.getCurrentTabId()
|
|
399
|
-
tab_count: this.getTabCount()
|
|
416
|
+
tab_id: this.getCurrentTabId(),
|
|
417
|
+
tab_count: this.getTabCount()
|
|
400
418
|
});
|
|
401
419
|
}
|
|
402
420
|
getCurrentTabId() {
|
|
403
421
|
try {
|
|
404
422
|
if (typeof window === "undefined" || !("sessionStorage" in window)) {
|
|
405
|
-
return
|
|
423
|
+
return "";
|
|
406
424
|
}
|
|
407
425
|
const CURRENT_TAB_LOCAL_STORAGE_KEY = "lv_insights_ct";
|
|
408
|
-
return window.sessionStorage.getItem(CURRENT_TAB_LOCAL_STORAGE_KEY) ||
|
|
426
|
+
return window.sessionStorage.getItem(CURRENT_TAB_LOCAL_STORAGE_KEY) || "";
|
|
409
427
|
} catch (_) {
|
|
410
|
-
return
|
|
428
|
+
return "";
|
|
411
429
|
}
|
|
412
430
|
}
|
|
413
431
|
getTabCount() {
|
|
414
432
|
try {
|
|
415
433
|
if (typeof window === "undefined" || !("localStorage" in window)) {
|
|
416
|
-
return
|
|
434
|
+
return 0;
|
|
417
435
|
}
|
|
418
436
|
const OT_LOCAL_STORAGE_KEY = "lv_insights_ot";
|
|
419
437
|
return Number(window.localStorage.getItem(OT_LOCAL_STORAGE_KEY)) || 0;
|
package/dist/types/audience.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare namespace ILevoAudience {
|
|
|
24
24
|
interface ScrollProperties {
|
|
25
25
|
percent: number;
|
|
26
26
|
}
|
|
27
|
-
type Properties = Partial<BaseProperties & BlockProperties & ActivityProperties & ScrollProperties> & Record<string, any>;
|
|
27
|
+
type Properties = Partial<BaseProperties & BlockProperties & ActivityProperties & ScrollProperties> & Partial<Omit<BaseInput, "workspace_id" | "tab_count" | "tab_id">> & Record<string, any>;
|
|
28
28
|
type EventProperties = {
|
|
29
29
|
properties: Properties;
|
|
30
30
|
traits: Traits;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audience.d.ts","sourceRoot":"","sources":["../../src/types/audience.ts"],"names":[],"mappings":"AACA,yBAAiB,aAAa,CAAC;IAC7B,UAAiB,MAAM;QACrB,YAAY,EAAE,OAAO,CAAC;QACtB,SAAS,EAAE,OAAO,CAAC;QACnB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE;YACR,IAAI,EAAE,MAAM,CAAC;YACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SAC9B,CAAC;KACH;IAED,KAAY,cAAc,GAAG,MAAM,GAAG;QACpC,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IAEF,UAAiB,eAAe;QAC9B,EAAE,EAAE,MAAM,CAAC;KACZ;IAED,UAAiB,kBAAkB;QACjC,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB;IAED,UAAiB,gBAAgB;QAC/B,OAAO,EAAE,MAAM,CAAC;KACjB;IAED,KAAY,UAAU,GAAG,OAAO,CAC9B,cAAc,GAAG,eAAe,GAAG,kBAAkB,GAAG,gBAAgB,CACzE,GACC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEtB,KAAY,eAAe,GAAG;QAC5B,UAAU,EAAE,UAAU,CAAC;QACvB,MAAM,EAAE,MAAM,CAAC;QACf,K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