@jitsu/js 1.1.0-canary.344.20230430234929 → 1.1.0-canary.391.20230523080206
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/.pnpm-debug.log +23 -0
- package/.turbo/turbo-build.log +95 -65
- package/.turbo/turbo-clean.log +5 -5
- package/__tests__/node/nodejs.test.ts +14 -3
- package/__tests__/playwright/integration.test.ts +1 -2
- package/dist/analytics-plugin.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/jitsu.cjs.js +263 -54
- package/dist/jitsu.es.js +263 -54
- package/dist/web/p.js.txt +262 -54
- package/package.json +2 -2
- package/src/analytics-plugin.ts +33 -13
- package/src/destination-plugins/gtm.ts +112 -0
- package/src/destination-plugins/index.ts +34 -0
- package/src/destination-plugins/logrocket.ts +83 -0
- package/src/{destination-plugins.ts → destination-plugins/tag.ts} +3 -28
- package/src/index.ts +13 -3
- package/dist/destination-plugins.d.ts +0 -13
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AnalyticsClientEvent } from "@jitsu/protocols/analytics";
|
|
2
|
+
import { tagPlugin } from "./tag";
|
|
3
|
+
import { logrocketPlugin } from "./logrocket";
|
|
4
|
+
import { gtmPlugin } from "./gtm";
|
|
5
|
+
|
|
6
|
+
export type InternalPlugin<T> = {
|
|
7
|
+
id: string;
|
|
8
|
+
handle(config: T, payload: AnalyticsClientEvent): Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type CommonDestinationCredentials = {
|
|
12
|
+
hosts?: string;
|
|
13
|
+
events?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function satisfyFilter(filter: string, subject: string | undefined): boolean {
|
|
17
|
+
return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function applyFilters(event: AnalyticsClientEvent, creds: CommonDestinationCredentials): boolean {
|
|
21
|
+
const { hosts = "*", events = "*" } = creds;
|
|
22
|
+
const eventsArray = events.split("\n");
|
|
23
|
+
return (
|
|
24
|
+
!!hosts.split("\n").find(hostFilter => satisfyFilter(hostFilter, event.context?.host)) &&
|
|
25
|
+
(!!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.type)) ||
|
|
26
|
+
!!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.event)))
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const internalDestinationPlugins: Record<string, InternalPlugin<any>> = {
|
|
31
|
+
[tagPlugin.id]: tagPlugin,
|
|
32
|
+
[gtmPlugin.id]: gtmPlugin,
|
|
33
|
+
[logrocketPlugin.id]: logrocketPlugin,
|
|
34
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { loadScript } from "../script-loader";
|
|
2
|
+
import { AnalyticsClientEvent } from "@jitsu/protocols/analytics";
|
|
3
|
+
import { applyFilters, CommonDestinationCredentials, InternalPlugin } from "./index";
|
|
4
|
+
|
|
5
|
+
export type LogRocketDestinationCredentials = {
|
|
6
|
+
appId: string;
|
|
7
|
+
} & CommonDestinationCredentials;
|
|
8
|
+
|
|
9
|
+
export const logrocketPlugin: InternalPlugin<LogRocketDestinationCredentials> = {
|
|
10
|
+
id: "logrocket",
|
|
11
|
+
async handle(config, payload: AnalyticsClientEvent) {
|
|
12
|
+
if (!applyFilters(payload, config)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
initLogrocketIfNeeded(config.appId);
|
|
16
|
+
|
|
17
|
+
const action = logRocket => {
|
|
18
|
+
if (payload.type === "identify" && payload.userId) {
|
|
19
|
+
logRocket.identify(payload.userId, payload.traits || {});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
getLogRocketQueue().push(action);
|
|
23
|
+
if (getLogRocketState() === "loaded") {
|
|
24
|
+
flushLogRocketQueue(window["LogRocket"]);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type LogRocketState = "fresh" | "loading" | "loaded" | "failed";
|
|
30
|
+
|
|
31
|
+
function getLogRocketState(): LogRocketState {
|
|
32
|
+
return window["__jitsuLrState"] || "fresh";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function setLogRocketState(s: LogRocketState) {
|
|
36
|
+
window["__jitsuLrState"] = s;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getLogRocketQueue(): ((lr: LogRocket) => void | Promise<void>)[] {
|
|
40
|
+
return window["__jitsuLrQueue"] || (window["__jitsuLrQueue"] = []);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type LogRocket = any;
|
|
44
|
+
|
|
45
|
+
function flushLogRocketQueue(lr: LogRocket) {
|
|
46
|
+
const queue = getLogRocketQueue();
|
|
47
|
+
|
|
48
|
+
while (queue.length > 0) {
|
|
49
|
+
const method = queue.shift();
|
|
50
|
+
try {
|
|
51
|
+
const res = method(lr);
|
|
52
|
+
if (res) {
|
|
53
|
+
res.catch(e => console.warn(`Async LogRocket method failed: ${e.message}`, e));
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.warn(`LogRocket method failed: ${e.message}`, e);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function initLogrocketIfNeeded(appId: string) {
|
|
62
|
+
if (getLogRocketState() !== "fresh") {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
setLogRocketState("loading");
|
|
66
|
+
loadScript(`https://cdn.lr-ingest.io/LogRocket.min.js`, { crossOrigin: "anonymous" })
|
|
67
|
+
.then(() => {
|
|
68
|
+
if (window["LogRocket"]) {
|
|
69
|
+
try {
|
|
70
|
+
window["LogRocket"].init(appId);
|
|
71
|
+
} catch (e) {
|
|
72
|
+
console.warn(`LogRocket (id=${appId}) init failed: ${e.message}`, e);
|
|
73
|
+
setLogRocketState("failed");
|
|
74
|
+
}
|
|
75
|
+
setLogRocketState("loaded");
|
|
76
|
+
flushLogRocketQueue(window["LogRocket"]);
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
.catch(e => {
|
|
80
|
+
console.warn(`LogRocket (id=${appId}) init failed: ${e.message}`, e);
|
|
81
|
+
setLogRocketState("failed");
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -1,33 +1,12 @@
|
|
|
1
1
|
import { AnalyticsClientEvent } from "@jitsu/protocols/analytics";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export type InternalPlugin<T> = {
|
|
5
|
-
id: string;
|
|
6
|
-
handle(config: T, payload: AnalyticsClientEvent): Promise<void>;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export type CommonDestinationCredentials = {
|
|
10
|
-
hosts?: string[];
|
|
11
|
-
events?: string[];
|
|
12
|
-
};
|
|
2
|
+
import { applyFilters, CommonDestinationCredentials, InternalPlugin } from "./index";
|
|
3
|
+
import { isInBrowser, randomId } from "../analytics-plugin";
|
|
13
4
|
|
|
14
5
|
export type TagDestinationCredentials = {
|
|
15
6
|
code: string;
|
|
16
7
|
} & CommonDestinationCredentials;
|
|
17
8
|
|
|
18
|
-
|
|
19
|
-
return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function applyFilters(event: AnalyticsClientEvent, creds: CommonDestinationCredentials): boolean {
|
|
23
|
-
const { hosts = ["*"], events = ["*"] } = creds;
|
|
24
|
-
return (
|
|
25
|
-
!!hosts.find(hostFilter => satisfyFilter(hostFilter, event.context?.host)) &&
|
|
26
|
-
!!events.find(eventFilter => satisfyFilter(eventFilter, event.type))
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const tagPlugin: InternalPlugin<TagDestinationCredentials> = {
|
|
9
|
+
export const tagPlugin: InternalPlugin<TagDestinationCredentials> = {
|
|
31
10
|
id: "tag",
|
|
32
11
|
async handle(config, payload: AnalyticsClientEvent) {
|
|
33
12
|
if (!applyFilters(payload, config)) {
|
|
@@ -97,7 +76,3 @@ function execJs(code: string, event: any) {
|
|
|
97
76
|
function replaceMacro(code, event) {
|
|
98
77
|
return code.replace(/{{\s*event\s*}}/g, JSON.stringify(event));
|
|
99
78
|
}
|
|
100
|
-
|
|
101
|
-
export const internalDestinationPlugins: Record<string, InternalPlugin<any>> = {
|
|
102
|
-
[tagPlugin.id]: tagPlugin,
|
|
103
|
-
};
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import Analytics from "analytics";
|
|
2
2
|
import { AnalyticsInterface, JitsuOptions, RuntimeFacade } from "./jitsu";
|
|
3
3
|
import jitsuAnalyticsPlugin, { emptyRuntime, isInBrowser, windowRuntime } from "./analytics-plugin";
|
|
4
|
-
import {
|
|
5
|
-
import e from "express";
|
|
4
|
+
import { Callback, DispatchedEvent, ID, JSONObject, Options } from "@jitsu/protocols/analytics";
|
|
6
5
|
|
|
7
6
|
export default function parse(input) {
|
|
8
7
|
let value = input;
|
|
@@ -29,6 +28,7 @@ export const emptyAnalytics = {
|
|
|
29
28
|
page: () => Promise.resolve(),
|
|
30
29
|
user: () => ({}),
|
|
31
30
|
identify: () => Promise.resolve({}),
|
|
31
|
+
group: () => Promise.resolve({}),
|
|
32
32
|
reset: () => Promise.resolve({}),
|
|
33
33
|
};
|
|
34
34
|
|
|
@@ -54,7 +54,17 @@ function createUnderlyingAnalyticsInstance(
|
|
|
54
54
|
return originalPage(...args);
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
return
|
|
57
|
+
return {
|
|
58
|
+
...analytics,
|
|
59
|
+
group(groupId?: ID, traits?: JSONObject | null, options?: Options, callback?: Callback): Promise<DispatchedEvent> {
|
|
60
|
+
for (const plugin of Object.values(analytics.plugins)) {
|
|
61
|
+
if (plugin["group"]) {
|
|
62
|
+
plugin["group"](groupId, traits, options, callback);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return Promise.resolve({});
|
|
66
|
+
},
|
|
67
|
+
} as AnalyticsInterface;
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
export function jitsuAnalytics(opts: JitsuOptions): AnalyticsInterface {
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AnalyticsClientEvent } from "@jitsu/protocols/analytics";
|
|
2
|
-
export type InternalPlugin<T> = {
|
|
3
|
-
id: string;
|
|
4
|
-
handle(config: T, payload: AnalyticsClientEvent): Promise<void>;
|
|
5
|
-
};
|
|
6
|
-
export type CommonDestinationCredentials = {
|
|
7
|
-
hosts?: string[];
|
|
8
|
-
events?: string[];
|
|
9
|
-
};
|
|
10
|
-
export type TagDestinationCredentials = {
|
|
11
|
-
code: string;
|
|
12
|
-
} & CommonDestinationCredentials;
|
|
13
|
-
export declare const internalDestinationPlugins: Record<string, InternalPlugin<any>>;
|