@levo-so/core 0.1.22 → 0.1.24
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
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
export type WorkspaceID = `W${string}`;
|
|
2
2
|
export declare const workspaceIdRegex: RegExp;
|
|
3
|
+
export interface IPageContext {
|
|
4
|
+
url: string;
|
|
5
|
+
referrer?: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
}
|
|
3
9
|
export interface ILevoConfig {
|
|
4
10
|
workspace: WorkspaceID | null;
|
|
5
11
|
apiUrl: string;
|
|
6
12
|
insightsUrl: string;
|
|
7
13
|
NODE_ENV: string;
|
|
8
14
|
APP_MODE?: "production" | "staging";
|
|
15
|
+
pageContext?: IPageContext | null;
|
|
9
16
|
}
|
|
10
17
|
/**
|
|
11
18
|
* @description LevoClient is class that provides a way to initialize the Levo SDK.
|
|
@@ -21,6 +28,7 @@ declare class LevoClient implements ILevoConfig {
|
|
|
21
28
|
get NODE_ENV(): string;
|
|
22
29
|
get APP_MODE(): "production" | "staging" | undefined;
|
|
23
30
|
updateWorkspace(workspace: WorkspaceID): void;
|
|
31
|
+
updatePageContext(pageContext: IPageContext | null): void;
|
|
24
32
|
get fetch(): import("wretch/addons/queryString").QueryStringAddon & import("wretch").Wretch<import("wretch/addons/queryString").QueryStringAddon, unknown, undefined>;
|
|
25
33
|
}
|
|
26
34
|
export { LevoClient, LevoClient as default };
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,11 @@ var LevoClient = class {
|
|
|
11
11
|
#insightsUrl;
|
|
12
12
|
#NODE_ENV;
|
|
13
13
|
#APP_MODE;
|
|
14
|
+
#pageContext = {
|
|
15
|
+
url: typeof window !== "undefined" ? window?.location?.href : "",
|
|
16
|
+
referrer: typeof document !== "undefined" ? document?.referrer : "",
|
|
17
|
+
title: typeof document !== "undefined" ? document?.title : ""
|
|
18
|
+
};
|
|
14
19
|
constructor(props) {
|
|
15
20
|
const defaultProps = {
|
|
16
21
|
workspace: null,
|
|
@@ -50,6 +55,9 @@ var LevoClient = class {
|
|
|
50
55
|
updateWorkspace(workspace) {
|
|
51
56
|
this.#workspace = workspace;
|
|
52
57
|
}
|
|
58
|
+
updatePageContext(pageContext) {
|
|
59
|
+
this.#pageContext = pageContext;
|
|
60
|
+
}
|
|
53
61
|
get fetch() {
|
|
54
62
|
const options = {
|
|
55
63
|
credentials: "include",
|
|
@@ -65,6 +73,12 @@ var LevoClient = class {
|
|
|
65
73
|
"Levo-Workspace": this.workspace
|
|
66
74
|
};
|
|
67
75
|
}
|
|
76
|
+
if (typeof this.#pageContext === "object" && this.#pageContext && Object.keys(this.#pageContext).length > 0) {
|
|
77
|
+
options.headers = {
|
|
78
|
+
...options?.headers || {},
|
|
79
|
+
"Levo-Page-Context": JSON.stringify(this.#pageContext)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
68
82
|
return wretch(this.apiUrl, options).addon(QueryStringAddon);
|
|
69
83
|
}
|
|
70
84
|
};
|
|
@@ -12,13 +12,15 @@ export declare class LevoAudience extends LevoPlugin {
|
|
|
12
12
|
type?: undefined;
|
|
13
13
|
referrer?: undefined;
|
|
14
14
|
data?: undefined;
|
|
15
|
+
raw?: undefined;
|
|
15
16
|
} | {
|
|
16
17
|
type: any;
|
|
17
18
|
referrer: any;
|
|
18
19
|
data: any;
|
|
20
|
+
raw: string;
|
|
19
21
|
};
|
|
20
22
|
startActivityListener(): any;
|
|
21
|
-
track(event: string, properties: ILevoAudience.Properties): Promise<
|
|
23
|
+
track(event: string, properties: ILevoAudience.Properties): Promise<any>;
|
|
22
24
|
bounce: (properties?: ILevoAudience.Properties) => void;
|
|
23
25
|
click: ({ properties, target, }: {
|
|
24
26
|
properties?: ILevoAudience.Properties;
|
|
@@ -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;;IAC3C,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAQ;IAK1C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IAkB9B,YAAY,UAAS;IACrB,YAAY,EAAE,GAAG,EAAE,CAAM;IAEnB,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,UAAU;IAmGnD,WAAW;;;;;;;;;;;IAmEX,qBAAqB;IAqBf,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,UAAU;IAuB/D,MAAM,gBAAiB,aAAa,CAAC,UAAU,UAsB7C;IAEF,KAAK,4BAGF;QACF,UAAU,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC;QACtC,MAAM,EAAE,WAAW,CAAC;KACpB,UAOC;CACF"}
|
|
@@ -253,9 +253,7 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
253
253
|
identifier: payloadProperties?.identifier || properties?.id,
|
|
254
254
|
workspace_id: this.client.workspace,
|
|
255
255
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
256
|
-
}).catch((e) =>
|
|
257
|
-
return getLevoError(e);
|
|
258
|
-
});
|
|
256
|
+
}).catch((e) => getLevoError(e));
|
|
259
257
|
},
|
|
260
258
|
page: ({ payload }) => {
|
|
261
259
|
if (!this?.client?.insightsUrl) {
|
|
@@ -268,9 +266,7 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
268
266
|
title: document.title,
|
|
269
267
|
identifier: properties.id,
|
|
270
268
|
resource: "page"
|
|
271
|
-
}).catch((e) =>
|
|
272
|
-
return getLevoError(e);
|
|
273
|
-
});
|
|
269
|
+
}).catch((e) => getLevoError(e));
|
|
274
270
|
},
|
|
275
271
|
identify: ({ payload }) => {
|
|
276
272
|
if (!this?.client?.insightsUrl) {
|
|
@@ -296,12 +292,8 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
296
292
|
this.request(
|
|
297
293
|
`${this?.client?.insightsUrl}/v1/insights/event/collect/bulk`,
|
|
298
294
|
this.requestBatch
|
|
299
|
-
).catch((e) =>
|
|
300
|
-
|
|
301
|
-
});
|
|
302
|
-
}).catch((e) => {
|
|
303
|
-
return getLevoError(e);
|
|
304
|
-
});
|
|
295
|
+
).catch((e) => getLevoError(e));
|
|
296
|
+
}).catch((e) => getLevoError(e));
|
|
305
297
|
}
|
|
306
298
|
};
|
|
307
299
|
this.instance = Analytics({
|
|
@@ -309,7 +301,6 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
309
301
|
plugins: [plugin]
|
|
310
302
|
});
|
|
311
303
|
const referrer = this.getReferrer();
|
|
312
|
-
console.log("Identifying", referrer);
|
|
313
304
|
await this.instance.identify("", {
|
|
314
305
|
...await getUserProperties(),
|
|
315
306
|
referrer
|
|
@@ -339,7 +330,7 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
339
330
|
data[key] = data[key]?.[0];
|
|
340
331
|
}
|
|
341
332
|
}
|
|
342
|
-
return { type, referrer, data };
|
|
333
|
+
return { type, referrer, data, raw: document.referrer };
|
|
343
334
|
}
|
|
344
335
|
startActivityListener() {
|
|
345
336
|
if (typeof document !== "undefined") {
|
|
@@ -361,11 +352,10 @@ var LevoAudience = class extends LevoPlugin {
|
|
|
361
352
|
return null;
|
|
362
353
|
}
|
|
363
354
|
async track(event, properties) {
|
|
364
|
-
console.log("Tracking", event, properties);
|
|
365
355
|
if (this.instance && this.isIdentified) {
|
|
366
|
-
this.instance.track(event, properties);
|
|
356
|
+
return this.instance.track(event, properties);
|
|
367
357
|
}
|
|
368
|
-
this.requestBatch.push({
|
|
358
|
+
return this.requestBatch.push({
|
|
369
359
|
event,
|
|
370
360
|
properties: {
|
|
371
361
|
...properties,
|