@levo-so/core 0.1.24 → 0.1.26
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/LevoClient.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export type WorkspaceID = `W${string}`;
|
|
|
2
2
|
export declare const workspaceIdRegex: RegExp;
|
|
3
3
|
export interface IPageContext {
|
|
4
4
|
url: string;
|
|
5
|
-
referrer?: string;
|
|
6
5
|
id?: string;
|
|
6
|
+
referrer?: string;
|
|
7
7
|
title?: string;
|
|
8
8
|
}
|
|
9
9
|
export interface ILevoConfig {
|
|
@@ -28,6 +28,7 @@ declare class LevoClient implements ILevoConfig {
|
|
|
28
28
|
get NODE_ENV(): string;
|
|
29
29
|
get APP_MODE(): "production" | "staging" | undefined;
|
|
30
30
|
updateWorkspace(workspace: WorkspaceID): void;
|
|
31
|
+
getPageContext(): IPageContext | null | undefined;
|
|
31
32
|
updatePageContext(pageContext: IPageContext | null): void;
|
|
32
33
|
get fetch(): import("wretch/addons/queryString").QueryStringAddon & import("wretch").Wretch<import("wretch/addons/queryString").QueryStringAddon, unknown, undefined>;
|
|
33
34
|
}
|
package/dist/index.js
CHANGED
|
@@ -55,6 +55,9 @@ var LevoClient = class {
|
|
|
55
55
|
updateWorkspace(workspace) {
|
|
56
56
|
this.#workspace = workspace;
|
|
57
57
|
}
|
|
58
|
+
getPageContext() {
|
|
59
|
+
return this.#pageContext;
|
|
60
|
+
}
|
|
58
61
|
updatePageContext(pageContext) {
|
|
59
62
|
this.#pageContext = pageContext;
|
|
60
63
|
}
|
|
@@ -63,17 +66,15 @@ var LevoClient = class {
|
|
|
63
66
|
credentials: "include",
|
|
64
67
|
signal: AbortSignal.timeout(3e4),
|
|
65
68
|
// 30 seconds timeout,
|
|
66
|
-
headers: {
|
|
67
|
-
Accept: "application/json",
|
|
68
|
-
"Content-Type": "application/json"
|
|
69
|
-
}
|
|
69
|
+
headers: {}
|
|
70
70
|
};
|
|
71
71
|
if (this.workspace) {
|
|
72
72
|
options.headers = {
|
|
73
|
+
...options?.headers || {},
|
|
73
74
|
"Levo-Workspace": this.workspace
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
|
-
if (typeof this.#pageContext === "object" &&
|
|
77
|
+
if (this.#pageContext && typeof this.#pageContext === "object" && Object.keys(this.#pageContext).length > 0) {
|
|
77
78
|
options.headers = {
|
|
78
79
|
...options?.headers || {},
|
|
79
80
|
"Levo-Page-Context": JSON.stringify(this.#pageContext)
|
|
@@ -22,9 +22,7 @@ export declare class LevoAudience extends LevoPlugin {
|
|
|
22
22
|
startActivityListener(): any;
|
|
23
23
|
track(event: string, properties: ILevoAudience.Properties): Promise<any>;
|
|
24
24
|
bounce: (properties?: ILevoAudience.Properties) => void;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
target: HTMLElement;
|
|
28
|
-
}) => void;
|
|
25
|
+
getCurrentTabId(): string | null;
|
|
26
|
+
getTabCount(): number | null;
|
|
29
27
|
}
|
|
30
28
|
//# 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;AAIvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,YAAa,SAAQ,UAAU;;
|
|
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;AAIvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,YAAa,SAAQ,UAAU;;IAC1C,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAQ;IAK1C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IA2B9B,YAAY,UAAS;IACrB,YAAY,EAAE,GAAG,EAAE,CAAM;IAEnB,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,UAAU;IAuGnD,WAAW;;;;;;;;;;;IAmEX,qBAAqB;IAqBf,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,UAAU;IAyB/D,MAAM,gBAAiB,aAAa,CAAC,UAAU,UAyB7C;IAEF,eAAe;IAef,WAAW;CAYZ"}
|
|
@@ -215,12 +215,19 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
215
215
|
// 60 seconds till we consider user idle
|
|
216
216
|
request(url, data) {
|
|
217
217
|
const headers = {
|
|
218
|
+
Accept: "application/json",
|
|
218
219
|
"Content-Type": "application/json"
|
|
219
220
|
};
|
|
220
221
|
if (this.client.workspace) {
|
|
221
222
|
headers["Levo-Workspace"] = this.client.workspace;
|
|
222
223
|
}
|
|
223
|
-
|
|
224
|
+
const pageContext = this.client.getPageContext();
|
|
225
|
+
if (pageContext) {
|
|
226
|
+
headers["Levo-Page-Context"] = JSON.stringify(pageContext);
|
|
227
|
+
}
|
|
228
|
+
return wretch(url, {
|
|
229
|
+
credentials: "include"
|
|
230
|
+
}).options({
|
|
224
231
|
keepAlive: true
|
|
225
232
|
}).headers(headers).post(data).json();
|
|
226
233
|
}
|
|
@@ -252,7 +259,9 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
252
259
|
resource: payloadProperties?.resource || "page",
|
|
253
260
|
identifier: payloadProperties?.identifier || properties?.id,
|
|
254
261
|
workspace_id: this.client.workspace,
|
|
255
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
262
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
263
|
+
tab_id: this.getCurrentTabId(),
|
|
264
|
+
tab_count: this.getTabCount()
|
|
256
265
|
}).catch((e) => getLevoError(e));
|
|
257
266
|
},
|
|
258
267
|
page: ({ payload }) => {
|
|
@@ -285,7 +294,9 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
285
294
|
pathname: window.location.pathname,
|
|
286
295
|
page_title: document.title,
|
|
287
296
|
url: window.location.href,
|
|
288
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
297
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
298
|
+
tab_id: this.getCurrentTabId(),
|
|
299
|
+
tab_count: this.getTabCount()
|
|
289
300
|
}
|
|
290
301
|
).then(() => {
|
|
291
302
|
this.isIdentified = true;
|
|
@@ -369,7 +380,9 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
369
380
|
resource: properties?.resource || "page",
|
|
370
381
|
identifier: properties?.identifier || properties?.id,
|
|
371
382
|
workspace_id: this.client.workspace,
|
|
372
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
383
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
384
|
+
tab_id: this.getCurrentTabId(),
|
|
385
|
+
tab_count: this.getTabCount()
|
|
373
386
|
});
|
|
374
387
|
}
|
|
375
388
|
bounce = (properties) => {
|
|
@@ -377,6 +390,7 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
377
390
|
event: "page.bounce",
|
|
378
391
|
properties: {
|
|
379
392
|
...properties,
|
|
393
|
+
tab_count: this.getTabCount,
|
|
380
394
|
resource: void 0,
|
|
381
395
|
identifier: void 0
|
|
382
396
|
},
|
|
@@ -387,23 +401,37 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
387
401
|
resource: properties?.resource || "page",
|
|
388
402
|
identifier: properties?.identifier || properties?.id,
|
|
389
403
|
workspace_id: this.client.workspace,
|
|
390
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
404
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
405
|
+
tab_id: this.getCurrentTabId(),
|
|
406
|
+
tab_count: this.getTabCount()
|
|
391
407
|
};
|
|
392
408
|
navigator.sendBeacon(
|
|
393
409
|
`${this?.client?.insightsUrl}/v1/insights/event/collect`,
|
|
394
410
|
JSON.stringify(payload)
|
|
395
411
|
);
|
|
396
412
|
};
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
413
|
+
getCurrentTabId() {
|
|
414
|
+
try {
|
|
415
|
+
if (typeof window === "undefined" || !("sessionStorage" in window)) {
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
const CURRENT_TAB_LOCAL_STORAGE_KEY = "lv_insights_ct";
|
|
419
|
+
return window.sessionStorage.getItem(CURRENT_TAB_LOCAL_STORAGE_KEY) || null;
|
|
420
|
+
} catch (_) {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
getTabCount() {
|
|
425
|
+
try {
|
|
426
|
+
if (typeof window === "undefined" || !("localStorage" in window)) {
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
const OT_LOCAL_STORAGE_KEY = "lv_insights_ot";
|
|
430
|
+
return Number(window.localStorage.getItem(OT_LOCAL_STORAGE_KEY)) || 0;
|
|
431
|
+
} catch (_) {
|
|
432
|
+
return 0;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
407
435
|
};
|
|
408
436
|
|
|
409
437
|
export { LevoAudience };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@levo-so/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.26",
|
|
4
4
|
"author": "Levo Engineering <devs@theinternetfolks.com>",
|
|
5
5
|
"description": "Levo common utilities",
|
|
6
6
|
"type": "module",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"tsup": "8.2.4",
|
|
26
26
|
"typescript": "5.5.4",
|
|
27
|
-
"@levo/
|
|
28
|
-
"@levo/
|
|
27
|
+
"@levo/ts-config": "0.0.0",
|
|
28
|
+
"@levo/eslint-config": "0.0.0"
|
|
29
29
|
},
|
|
30
30
|
"main": "./dist/index.js",
|
|
31
31
|
"module": "./dist/index.js",
|