@jitsu/js 1.1.0-canary.344.20230430234929 → 1.1.0-canary.388.20230519133920
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 +50 -20
- package/.turbo/turbo-clean.log +2 -2
- package/__tests__/node/nodejs.test.ts +14 -3
- package/__tests__/playwright/integration.test.ts +1 -2
- package/dist/index.d.ts +1 -0
- package/dist/jitsu.cjs.js +248 -52
- package/dist/jitsu.es.js +248 -52
- package/dist/web/p.js.txt +247 -52
- package/package.json +2 -2
- package/src/analytics-plugin.ts +29 -10
- package/src/destination-plugins/gtm.ts +102 -0
- package/src/destination-plugins/index.ts +32 -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
package/.pnpm-debug.log
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"0 debug pnpm:scope": {
|
|
3
|
+
"selected": 1,
|
|
4
|
+
"workspacePrefix": "/Users/ildarnurislamov/Projects/onetag"
|
|
5
|
+
},
|
|
6
|
+
"1 error pnpm": {
|
|
7
|
+
"code": "ELIFECYCLE",
|
|
8
|
+
"errno": "ENOENT",
|
|
9
|
+
"syscall": "spawn",
|
|
10
|
+
"file": "sh",
|
|
11
|
+
"pkgid": "@jitsu/js@0.0.0",
|
|
12
|
+
"stage": "build",
|
|
13
|
+
"script": "tsc -p . && rollup -c && cp src/jitsu.d.ts dist",
|
|
14
|
+
"pkgname": "@jitsu/js",
|
|
15
|
+
"err": {
|
|
16
|
+
"name": "pnpm",
|
|
17
|
+
"message": "@jitsu/js@0.0.0 build: `tsc -p . && rollup -c && cp src/jitsu.d.ts dist`\nspawn ENOENT",
|
|
18
|
+
"code": "ELIFECYCLE",
|
|
19
|
+
"stack": "pnpm: @jitsu/js@0.0.0 build: `tsc -p . && rollup -c && cp src/jitsu.d.ts dist`\nspawn ENOENT\n at ChildProcess.<anonymous> (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:93535:22)\n at ChildProcess.emit (node:events:527:28)\n at maybeClose (node:internal/child_process:1092:16)\n at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"2 warn pnpm:global": " Local package.json exists, but node_modules missing, did you mean to install?"
|
|
23
|
+
}
|
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
@jitsu/js:build: cache hit, replaying output [
|
|
1
|
+
@jitsu/js:build: cache hit, replaying output [2m9d604bcd7bdc50ac[0m
|
|
2
2
|
[33m@jitsu/js:build: [0m
|
|
3
|
-
[33m@jitsu/js:build: [0m> @jitsu/js@0.0.0 build /Users/
|
|
3
|
+
[33m@jitsu/js:build: [0m> @jitsu/js@0.0.0 build /Users/ildarnurislamov/Projects/onetag/libs/jitsu-js
|
|
4
4
|
[33m@jitsu/js:build: [0m> tsc -p . && rollup -c && cp compiled/src/*.d.ts dist
|
|
5
5
|
[33m@jitsu/js:build: [0m
|
|
6
6
|
[33m@jitsu/js:build: [0m[36m
|
|
@@ -14,7 +14,19 @@
|
|
|
14
14
|
[33m@jitsu/js:build: [0m3: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
15
|
[33m@jitsu/js:build: [0m4: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
16
16
|
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
17
|
-
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins.js[22m
|
|
17
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/logrocket.js[22m
|
|
18
|
+
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
|
+
[33m@jitsu/js:build: [0m ^
|
|
20
|
+
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
+
[33m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
22
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
23
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/tag.js[22m
|
|
24
|
+
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
25
|
+
[33m@jitsu/js:build: [0m ^
|
|
26
|
+
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
[33m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
28
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
29
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/gtm.js[22m
|
|
18
30
|
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
31
|
[33m@jitsu/js:build: [0m ^
|
|
20
32
|
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -22,17 +34,20 @@
|
|
|
22
34
|
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
23
35
|
[33m@jitsu/js:build: [0m[1m[33m(!) Circular dependencies[39m[22m
|
|
24
36
|
[33m@jitsu/js:build: [0mcompiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
|
|
25
|
-
[33m@jitsu/js:build: [0mcompiled/src/
|
|
37
|
+
[33m@jitsu/js:build: [0mcompiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/destination-plugins/index.js
|
|
38
|
+
[33m@jitsu/js:build: [0mcompiled/src/analytics-plugin.js -> compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/analytics-plugin.js
|
|
39
|
+
[33m@jitsu/js:build: [0mcompiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/logrocket.js -> compiled/src/destination-plugins/index.js
|
|
40
|
+
[33m@jitsu/js:build: [0mcompiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/gtm.js -> compiled/src/destination-plugins/index.js
|
|
26
41
|
[33m@jitsu/js:build: [0m[1m[33m(!) Use of eval is strongly discouraged[39m[22m
|
|
27
42
|
[33m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#avoiding-eval[39m
|
|
28
|
-
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins.js[22m
|
|
29
|
-
[33m@jitsu/js:build: [0m[
|
|
30
|
-
[33m@jitsu/js:build: [
|
|
31
|
-
[33m@jitsu/js:build: [
|
|
43
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/tag.js[22m
|
|
44
|
+
[33m@jitsu/js:build: [0m[90m68: })()`;
|
|
45
|
+
[33m@jitsu/js:build: [0m69: try {
|
|
46
|
+
[33m@jitsu/js:build: [0m70: eval(iif);
|
|
32
47
|
[33m@jitsu/js:build: [0m ^
|
|
33
|
-
[33m@jitsu/js:build: [
|
|
34
|
-
[33m@jitsu/js:build: [
|
|
35
|
-
[33m@jitsu/js:build: [0m[32mcreated [1mdist/web/p.js.txt[22m in [
|
|
48
|
+
[33m@jitsu/js:build: [0m71: }
|
|
49
|
+
[33m@jitsu/js:build: [0m72: catch (e) {[39m
|
|
50
|
+
[33m@jitsu/js:build: [0m[32mcreated [1mdist/web/p.js.txt[22m in [1m216ms[22m[39m
|
|
36
51
|
[33m@jitsu/js:build: [0m[36m
|
|
37
52
|
[33m@jitsu/js:build: [0m[1m./compiled/src/index.js, ./compiled/src/jitsu.js, ./compiled/src/analytics-plugin.js[22m → [1mdist/jitsu.es.js, dist/jitsu.cjs.js[22m...[39m
|
|
38
53
|
[33m@jitsu/js:build: [0m[1m[33m(!) "this" has been rewritten to "undefined"[39m[22m
|
|
@@ -44,7 +59,19 @@
|
|
|
44
59
|
[33m@jitsu/js:build: [0m3: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
45
60
|
[33m@jitsu/js:build: [0m4: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
46
61
|
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
47
|
-
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins.js[22m
|
|
62
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/gtm.js[22m
|
|
63
|
+
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
64
|
+
[33m@jitsu/js:build: [0m ^
|
|
65
|
+
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
66
|
+
[33m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
67
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
68
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/logrocket.js[22m
|
|
69
|
+
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
70
|
+
[33m@jitsu/js:build: [0m ^
|
|
71
|
+
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
72
|
+
[33m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
73
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
74
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/tag.js[22m
|
|
48
75
|
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
49
76
|
[33m@jitsu/js:build: [0m ^
|
|
50
77
|
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -52,14 +79,17 @@
|
|
|
52
79
|
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
53
80
|
[33m@jitsu/js:build: [0m[1m[33m(!) Circular dependencies[39m[22m
|
|
54
81
|
[33m@jitsu/js:build: [0mcompiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
|
|
55
|
-
[33m@jitsu/js:build: [0mcompiled/src/
|
|
82
|
+
[33m@jitsu/js:build: [0mcompiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/destination-plugins/index.js
|
|
83
|
+
[33m@jitsu/js:build: [0mcompiled/src/analytics-plugin.js -> compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/analytics-plugin.js
|
|
84
|
+
[33m@jitsu/js:build: [0mcompiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/logrocket.js -> compiled/src/destination-plugins/index.js
|
|
85
|
+
[33m@jitsu/js:build: [0mcompiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/gtm.js -> compiled/src/destination-plugins/index.js
|
|
56
86
|
[33m@jitsu/js:build: [0m[1m[33m(!) Use of eval is strongly discouraged[39m[22m
|
|
57
87
|
[33m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#avoiding-eval[39m
|
|
58
|
-
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins.js[22m
|
|
59
|
-
[33m@jitsu/js:build: [0m[
|
|
60
|
-
[33m@jitsu/js:build: [
|
|
61
|
-
[33m@jitsu/js:build: [
|
|
88
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/tag.js[22m
|
|
89
|
+
[33m@jitsu/js:build: [0m[90m68: })()`;
|
|
90
|
+
[33m@jitsu/js:build: [0m69: try {
|
|
91
|
+
[33m@jitsu/js:build: [0m70: eval(iif);
|
|
62
92
|
[33m@jitsu/js:build: [0m ^
|
|
63
|
-
[33m@jitsu/js:build: [
|
|
64
|
-
[33m@jitsu/js:build: [
|
|
65
|
-
[33m@jitsu/js:build: [0m[32mcreated [1mdist/jitsu.es.js, dist/jitsu.cjs.js[22m in [
|
|
93
|
+
[33m@jitsu/js:build: [0m71: }
|
|
94
|
+
[33m@jitsu/js:build: [0m72: catch (e) {[39m
|
|
95
|
+
[33m@jitsu/js:build: [0m[32mcreated [1mdist/jitsu.es.js, dist/jitsu.cjs.js[22m in [1m151ms[22m[39m
|
package/.turbo/turbo-clean.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
@jitsu/js:clean: cache hit, replaying output [
|
|
1
|
+
@jitsu/js:clean: cache hit, replaying output [2m6f082eb620c44280[0m
|
|
2
2
|
[33m@jitsu/js:clean: [0m
|
|
3
|
-
[33m@jitsu/js:clean: [0m> @jitsu/js@0.0.0 clean /Users/
|
|
3
|
+
[33m@jitsu/js:clean: [0m> @jitsu/js@0.0.0 clean /Users/ildarnurislamov/Projects/onetag/libs/jitsu-js
|
|
4
4
|
[33m@jitsu/js:clean: [0m> rm -rf ./dist
|
|
5
5
|
[33m@jitsu/js:clean: [0m
|
|
@@ -46,6 +46,10 @@ describe("Test Jitsu NodeJS client", () => {
|
|
|
46
46
|
email: "test@test.com",
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
+
await jitsu.group("testGroup", {
|
|
50
|
+
name: "Test Group",
|
|
51
|
+
});
|
|
52
|
+
|
|
49
53
|
await jitsu.page({
|
|
50
54
|
name: "test",
|
|
51
55
|
environment: "nodejs",
|
|
@@ -56,14 +60,16 @@ describe("Test Jitsu NodeJS client", () => {
|
|
|
56
60
|
},
|
|
57
61
|
});
|
|
58
62
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
59
|
-
expect(requestLog.length).toBe(
|
|
63
|
+
expect(requestLog.length).toBe(4);
|
|
60
64
|
expect(requestLog[0].type).toBe("track");
|
|
61
65
|
expect(requestLog[1].type).toBe("identify");
|
|
62
|
-
expect(requestLog[2].type).toBe("
|
|
66
|
+
expect(requestLog[2].type).toBe("group");
|
|
67
|
+
expect(requestLog[3].type).toBe("page");
|
|
63
68
|
|
|
64
69
|
const track = requestLog[0].body as AnalyticsClientEvent;
|
|
65
70
|
const identify = requestLog[1].body as AnalyticsClientEvent;
|
|
66
|
-
const
|
|
71
|
+
const group = requestLog[2].body as AnalyticsClientEvent;
|
|
72
|
+
const page = requestLog[3].body as AnalyticsClientEvent;
|
|
67
73
|
|
|
68
74
|
//expect(track.userId).toBe(undefined);
|
|
69
75
|
expect(page.properties.name).toBe("test");
|
|
@@ -72,6 +78,11 @@ describe("Test Jitsu NodeJS client", () => {
|
|
|
72
78
|
expect(page.userId).toBe("testUser");
|
|
73
79
|
expect(identify.traits.email).toBe("test@test.com");
|
|
74
80
|
expect(identify.anonymousId).toBe(page.anonymousId);
|
|
81
|
+
expect(group.traits.name).toBe("Test Group");
|
|
82
|
+
expect(group.anonymousId).toBe(page.anonymousId);
|
|
83
|
+
expect(group.userId).toBe("testUser");
|
|
84
|
+
expect(group.groupId).toBe("testGroup");
|
|
85
|
+
|
|
75
86
|
const pagePayload = requestLog[0].body;
|
|
76
87
|
console.log("pagePayload", pagePayload);
|
|
77
88
|
} finally {
|
|
@@ -7,8 +7,6 @@ import ejs from "ejs";
|
|
|
7
7
|
import * as process from "process";
|
|
8
8
|
import * as console from "console";
|
|
9
9
|
import { AnalyticsClientEvent, AnalyticsInterface } from "@jitsu/protocols/analytics.d";
|
|
10
|
-
import type { AnalyticsCore } from "@segment/analytics-next/src/core/analytics/interfaces";
|
|
11
|
-
import { response } from "express";
|
|
12
10
|
|
|
13
11
|
test.use({
|
|
14
12
|
ignoreHTTPSErrors: true,
|
|
@@ -116,6 +114,7 @@ const generateTestEvents = async () => {
|
|
|
116
114
|
await analytics.identify("userId2", { email: "john.doe2@gmail.com", caseName: "basic-identify" });
|
|
117
115
|
// jitsu must extract traits even from 'id' object
|
|
118
116
|
await analytics.identify({ email: "john.doe3@gmail.com", caseName: "identify-without-user-id" });
|
|
117
|
+
await analytics.group("group1", { name: "Group 1", caseName: "basic-group" });
|
|
119
118
|
await analytics.page({ caseName: "page-without-name", context: { page: { title: "Synthetic Title" } } });
|
|
120
119
|
await analytics.page("test-page", { caseName: "page-with-name" });
|
|
121
120
|
await analytics.track("testEvent", { caseName: "track-with-name" });
|
package/dist/index.d.ts
CHANGED
package/dist/jitsu.cjs.js
CHANGED
|
@@ -67,7 +67,50 @@ function analyticsLib() {
|
|
|
67
67
|
return ke(_objectSpread2(_objectSpread2({}, defaultSettings), opts));
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
function findScript(src) {
|
|
71
|
+
const scripts = Array.prototype.slice.call(window.document.querySelectorAll("script"));
|
|
72
|
+
return scripts.find(s => s.src === src);
|
|
73
|
+
}
|
|
74
|
+
function loadScript(src, attributes) {
|
|
75
|
+
const found = findScript(src);
|
|
76
|
+
if (found !== undefined) {
|
|
77
|
+
const status = found === null || found === void 0 ? void 0 : found.getAttribute("status");
|
|
78
|
+
if (status === "loaded") {
|
|
79
|
+
return Promise.resolve(found);
|
|
80
|
+
}
|
|
81
|
+
if (status === "loading") {
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
found.addEventListener("load", () => resolve(found));
|
|
84
|
+
found.addEventListener("error", err => reject(err));
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
var _a;
|
|
90
|
+
const script = window.document.createElement("script");
|
|
91
|
+
script.type = "text/javascript";
|
|
92
|
+
script.src = src;
|
|
93
|
+
script.async = true;
|
|
94
|
+
script.setAttribute("status", "loading");
|
|
95
|
+
for (const [k, v] of Object.entries(attributes !== null && attributes !== void 0 ? attributes : {})) {
|
|
96
|
+
script.setAttribute(k, v);
|
|
97
|
+
}
|
|
98
|
+
script.onload = () => {
|
|
99
|
+
script.onerror = script.onload = null;
|
|
100
|
+
script.setAttribute("status", "loaded");
|
|
101
|
+
resolve(script);
|
|
102
|
+
};
|
|
103
|
+
script.onerror = () => {
|
|
104
|
+
script.onerror = script.onload = null;
|
|
105
|
+
script.setAttribute("status", "error");
|
|
106
|
+
reject(new Error(`Failed to load ${src}`));
|
|
107
|
+
};
|
|
108
|
+
const tag = window.document.getElementsByTagName("script")[0];
|
|
109
|
+
(_a = tag.parentElement) === null || _a === void 0 ? void 0 : _a.insertBefore(script, tag);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
71
114
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
72
115
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
73
116
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -76,18 +119,10 @@ var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
76
119
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
77
120
|
});
|
|
78
121
|
};
|
|
79
|
-
function satisfyFilter(filter, subject) {
|
|
80
|
-
return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
|
|
81
|
-
}
|
|
82
|
-
function applyFilters(event, creds) {
|
|
83
|
-
const { hosts = ["*"], events = ["*"] } = creds;
|
|
84
|
-
return (!!hosts.find(hostFilter => { var _a; return satisfyFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
|
|
85
|
-
!!events.find(eventFilter => satisfyFilter(eventFilter, event.type)));
|
|
86
|
-
}
|
|
87
122
|
const tagPlugin = {
|
|
88
123
|
id: "tag",
|
|
89
124
|
handle(config, payload) {
|
|
90
|
-
return __awaiter$
|
|
125
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
91
126
|
if (!applyFilters(payload, config)) {
|
|
92
127
|
return;
|
|
93
128
|
}
|
|
@@ -155,53 +190,193 @@ function execJs(code, event) {
|
|
|
155
190
|
function replaceMacro(code, event) {
|
|
156
191
|
return code.replace(/{{\s*event\s*}}/g, JSON.stringify(event));
|
|
157
192
|
}
|
|
158
|
-
const internalDestinationPlugins = {
|
|
159
|
-
[tagPlugin.id]: tagPlugin,
|
|
160
|
-
};
|
|
161
193
|
|
|
162
|
-
function
|
|
163
|
-
|
|
164
|
-
return
|
|
194
|
+
var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
195
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
196
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
197
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
198
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
199
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
200
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
const logrocketPlugin = {
|
|
204
|
+
id: "logrocket",
|
|
205
|
+
handle(config, payload) {
|
|
206
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
207
|
+
if (!applyFilters(payload, config)) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
initLogrocketIfNeeded(config.appId);
|
|
211
|
+
const action = logRocket => {
|
|
212
|
+
if (payload.type === "identify" && payload.userId) {
|
|
213
|
+
logRocket.identify(payload.userId, payload.traits || {});
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
getLogRocketQueue().push(action);
|
|
217
|
+
if (getLogRocketState() === "loaded") {
|
|
218
|
+
flushLogRocketQueue(window["LogRocket"]);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
function getLogRocketState() {
|
|
224
|
+
return window["__jitsuLrState"] || "fresh";
|
|
165
225
|
}
|
|
166
|
-
function
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
226
|
+
function setLogRocketState(s) {
|
|
227
|
+
window["__jitsuLrState"] = s;
|
|
228
|
+
}
|
|
229
|
+
function getLogRocketQueue() {
|
|
230
|
+
return window["__jitsuLrQueue"] || (window["__jitsuLrQueue"] = []);
|
|
231
|
+
}
|
|
232
|
+
function flushLogRocketQueue(lr) {
|
|
233
|
+
const queue = getLogRocketQueue();
|
|
234
|
+
while (queue.length > 0) {
|
|
235
|
+
const method = queue.shift();
|
|
236
|
+
try {
|
|
237
|
+
const res = method(lr);
|
|
238
|
+
if (res) {
|
|
239
|
+
res.catch(e => console.warn(`Async LogRocket method failed: ${e.message}`, e));
|
|
240
|
+
}
|
|
172
241
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
found.addEventListener("load", () => resolve(found));
|
|
176
|
-
found.addEventListener("error", err => reject(err));
|
|
177
|
-
});
|
|
242
|
+
catch (e) {
|
|
243
|
+
console.warn(`LogRocket method failed: ${e.message}`, e);
|
|
178
244
|
}
|
|
179
245
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
script.async = true;
|
|
186
|
-
script.setAttribute("status", "loading");
|
|
187
|
-
for (const [k, v] of Object.entries(attributes !== null && attributes !== void 0 ? attributes : {})) {
|
|
188
|
-
script.setAttribute(k, v);
|
|
246
|
+
}
|
|
247
|
+
function initLogrocketIfNeeded(appId) {
|
|
248
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
249
|
+
if (getLogRocketState() !== "fresh") {
|
|
250
|
+
return;
|
|
189
251
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
252
|
+
setLogRocketState("loading");
|
|
253
|
+
loadScript(`https://cdn.lr-ingest.io/LogRocket.min.js`, { crossOrigin: "anonymous" })
|
|
254
|
+
.then(() => {
|
|
255
|
+
if (window["LogRocket"]) {
|
|
256
|
+
try {
|
|
257
|
+
window["LogRocket"].init(appId);
|
|
258
|
+
}
|
|
259
|
+
catch (e) {
|
|
260
|
+
console.warn(`LogRocket (id=${appId}) init failed: ${e.message}`, e);
|
|
261
|
+
setLogRocketState("failed");
|
|
262
|
+
}
|
|
263
|
+
setLogRocketState("loaded");
|
|
264
|
+
flushLogRocketQueue(window["LogRocket"]);
|
|
265
|
+
}
|
|
266
|
+
})
|
|
267
|
+
.catch(e => {
|
|
268
|
+
console.warn(`LogRocket (id=${appId}) init failed: ${e.message}`, e);
|
|
269
|
+
setLogRocketState("failed");
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
275
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
276
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
277
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
278
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
279
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
280
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
const defaultScriptSrc = "https://www.googletagmanager.com/gtag/js";
|
|
284
|
+
const gtmPlugin = {
|
|
285
|
+
id: "gtm",
|
|
286
|
+
handle(config, payload) {
|
|
287
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
288
|
+
if (!applyFilters(payload, config)) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
yield initGtmIfNeeded(config);
|
|
292
|
+
const dataLayer = window[config.dataLayerName || "dataLayer"];
|
|
293
|
+
switch (payload.type) {
|
|
294
|
+
case "page":
|
|
295
|
+
const { properties: pageProperties } = payload;
|
|
296
|
+
const pageEvent = Object.assign({ event: "page_view" }, pageProperties);
|
|
297
|
+
if (config.debug) {
|
|
298
|
+
console.log("gtag push", pageEvent);
|
|
299
|
+
}
|
|
300
|
+
dataLayer.push(pageEvent);
|
|
301
|
+
break;
|
|
302
|
+
case "track":
|
|
303
|
+
const { properties: trackProperties } = payload;
|
|
304
|
+
const trackEvent = Object.assign({ event: payload.event }, trackProperties);
|
|
305
|
+
if (config.debug) {
|
|
306
|
+
console.log("gtag push", trackEvent);
|
|
307
|
+
}
|
|
308
|
+
dataLayer.push(trackEvent);
|
|
309
|
+
break;
|
|
310
|
+
case "identify":
|
|
311
|
+
const { anonymousId, userId, traits } = payload;
|
|
312
|
+
const user = traits;
|
|
313
|
+
if (userId) {
|
|
314
|
+
user.userId = userId;
|
|
315
|
+
}
|
|
316
|
+
if (anonymousId) {
|
|
317
|
+
user.anonymousId = anonymousId;
|
|
318
|
+
}
|
|
319
|
+
const identifyEvent = { event: "identify", user: user };
|
|
320
|
+
if (config.debug) {
|
|
321
|
+
console.log("gtag push", identifyEvent);
|
|
322
|
+
}
|
|
323
|
+
dataLayer.push(identifyEvent);
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
function getGtmState() {
|
|
330
|
+
return window["__jitsuGtmState"] || "fresh";
|
|
331
|
+
}
|
|
332
|
+
function setGtmState(s) {
|
|
333
|
+
window["__jitsuGtmState"] = s;
|
|
334
|
+
}
|
|
335
|
+
function initGtmIfNeeded(config) {
|
|
336
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
337
|
+
if (getGtmState() !== "fresh") {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
setGtmState("loading");
|
|
341
|
+
const dlName = config.dataLayerName || "dataLayer";
|
|
342
|
+
const dlParam = dlName !== "dataLayer" ? "&l=" + dlName : "";
|
|
343
|
+
const previewParams = config.preview
|
|
344
|
+
? `>m_preview=${config.preview}>m_auth=${config.auth}>m_cookies_win=x`
|
|
345
|
+
: "";
|
|
346
|
+
const scriptSrc = `${config.customScriptSrc || defaultScriptSrc}?id=${config.containerId}${dlParam}${previewParams}`;
|
|
347
|
+
window[dlName] = window[dlName] || [];
|
|
348
|
+
const gtag = function () {
|
|
349
|
+
window[dlName].push(arguments);
|
|
199
350
|
};
|
|
200
|
-
|
|
201
|
-
(
|
|
351
|
+
// @ts-ignore
|
|
352
|
+
gtag("js", new Date());
|
|
353
|
+
// @ts-ignore
|
|
354
|
+
gtag("config", config.containerId);
|
|
355
|
+
loadScript(scriptSrc)
|
|
356
|
+
.then(() => {
|
|
357
|
+
setGtmState("loaded");
|
|
358
|
+
})
|
|
359
|
+
.catch(e => {
|
|
360
|
+
console.warn(`GTM (containerId=${config.containerId}) init failed: ${e.message}`, e);
|
|
361
|
+
setGtmState("failed");
|
|
362
|
+
});
|
|
202
363
|
});
|
|
203
364
|
}
|
|
204
365
|
|
|
366
|
+
function satisfyFilter(filter, subject) {
|
|
367
|
+
return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
|
|
368
|
+
}
|
|
369
|
+
function applyFilters(event, creds) {
|
|
370
|
+
const { hosts = ["*"], events = ["*"] } = creds;
|
|
371
|
+
return (!!hosts.find(hostFilter => { var _a; return satisfyFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
|
|
372
|
+
!!events.find(eventFilter => satisfyFilter(eventFilter, event.type)));
|
|
373
|
+
}
|
|
374
|
+
const internalDestinationPlugins = {
|
|
375
|
+
[tagPlugin.id]: tagPlugin,
|
|
376
|
+
[gtmPlugin.id]: gtmPlugin,
|
|
377
|
+
[logrocketPlugin.id]: logrocketPlugin,
|
|
378
|
+
};
|
|
379
|
+
|
|
205
380
|
/* global analytics */
|
|
206
381
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
207
382
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -220,6 +395,8 @@ const config = {
|
|
|
220
395
|
debug: false,
|
|
221
396
|
fetch: null,
|
|
222
397
|
echoEvents: false,
|
|
398
|
+
cookieDomain: undefined,
|
|
399
|
+
runtime: undefined,
|
|
223
400
|
};
|
|
224
401
|
const parseQuery = (qs) => {
|
|
225
402
|
if (!qs) {
|
|
@@ -443,7 +620,7 @@ function adjustPayload(payload, config, storage) {
|
|
|
443
620
|
userAgent: runtime.userAgent(),
|
|
444
621
|
locale: runtime.language(),
|
|
445
622
|
screen: runtime.screen(),
|
|
446
|
-
traits: payload.type != "identify" ? Object.assign({}, (restoreTraits(storage) || {})) : undefined,
|
|
623
|
+
traits: payload.type != "identify" && payload.type != "group" ? Object.assign({}, (restoreTraits(storage) || {})) : undefined,
|
|
447
624
|
page: {
|
|
448
625
|
path: properties.path || (parsedUrl && parsedUrl.pathname),
|
|
449
626
|
referrer: referrer,
|
|
@@ -452,7 +629,7 @@ function adjustPayload(payload, config, storage) {
|
|
|
452
629
|
search: properties.search || (parsedUrl && parsedUrl.search),
|
|
453
630
|
title: properties.title || runtime.pageTitle(),
|
|
454
631
|
url: properties.url || url,
|
|
455
|
-
|
|
632
|
+
encoding: properties.encoding || runtime.documentEncoding(),
|
|
456
633
|
},
|
|
457
634
|
campaign: parseUtms(query),
|
|
458
635
|
};
|
|
@@ -560,7 +737,7 @@ function send(method, payload, jitsuConfig, instance, store) {
|
|
|
560
737
|
}
|
|
561
738
|
if (response.destinations) {
|
|
562
739
|
if (jitsuConfig.debug) {
|
|
563
|
-
console.log(`[JITSU] Processing device
|
|
740
|
+
console.log(`[JITSU] Processing device destinations: `, JSON.stringify(response.destinations, null, 2));
|
|
564
741
|
}
|
|
565
742
|
return processDestinations(response.destinations, method, adjustedPayload, !!jitsuConfig.debug, instance);
|
|
566
743
|
}
|
|
@@ -589,9 +766,10 @@ const jitsuAnalyticsPlugin = (pluginConfig = {}) => {
|
|
|
589
766
|
persistentStorage.removeItem(key);
|
|
590
767
|
},
|
|
591
768
|
});
|
|
769
|
+
const instanceConfig = Object.assign(Object.assign({}, config), pluginConfig);
|
|
592
770
|
return {
|
|
593
771
|
name: "jitsu",
|
|
594
|
-
config:
|
|
772
|
+
config: instanceConfig,
|
|
595
773
|
initialize: args => {
|
|
596
774
|
const { config } = args;
|
|
597
775
|
if (config.debug) {
|
|
@@ -619,6 +797,16 @@ const jitsuAnalyticsPlugin = (pluginConfig = {}) => {
|
|
|
619
797
|
//clear storage cache
|
|
620
798
|
Object.keys(storageCache).forEach(key => delete storageCache[key]);
|
|
621
799
|
},
|
|
800
|
+
methods: {
|
|
801
|
+
//analytics doesn't support group as a base method, so we need to add it manually
|
|
802
|
+
group(groupId, traits, options, callback) {
|
|
803
|
+
const analyticsInstance = this.instance;
|
|
804
|
+
const user = analyticsInstance.user();
|
|
805
|
+
const userId = (options === null || options === void 0 ? void 0 : options.userId) || (user === null || user === void 0 ? void 0 : user.userId);
|
|
806
|
+
const anonymousId = (options === null || options === void 0 ? void 0 : options.anonymousId) || (user === null || user === void 0 ? void 0 : user.anonymousId);
|
|
807
|
+
return send("group", Object.assign(Object.assign({ type: "group", groupId, traits }, (anonymousId ? { anonymousId } : {})), (userId ? { userId } : {})), instanceConfig, analyticsInstance, cachingStorageWrapper(analyticsInstance.storage));
|
|
808
|
+
},
|
|
809
|
+
},
|
|
622
810
|
};
|
|
623
811
|
};
|
|
624
812
|
function getSeed() {
|
|
@@ -671,6 +859,7 @@ const emptyAnalytics = {
|
|
|
671
859
|
page: () => Promise.resolve(),
|
|
672
860
|
user: () => ({}),
|
|
673
861
|
identify: () => Promise.resolve({}),
|
|
862
|
+
group: () => Promise.resolve({}),
|
|
674
863
|
reset: () => Promise.resolve({}),
|
|
675
864
|
};
|
|
676
865
|
function createUnderlyingAnalyticsInstance(opts, rt, plugins = []) {
|
|
@@ -689,7 +878,14 @@ function createUnderlyingAnalyticsInstance(opts, rt, plugins = []) {
|
|
|
689
878
|
return originalPage(...args);
|
|
690
879
|
}
|
|
691
880
|
};
|
|
692
|
-
return analytics
|
|
881
|
+
return Object.assign(Object.assign({}, analytics), { group(groupId, traits, options, callback) {
|
|
882
|
+
for (const plugin of Object.values(analytics.plugins)) {
|
|
883
|
+
if (plugin["group"]) {
|
|
884
|
+
plugin["group"](groupId, traits, options, callback);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
return Promise.resolve({});
|
|
888
|
+
} });
|
|
693
889
|
}
|
|
694
890
|
function jitsuAnalytics(opts) {
|
|
695
891
|
const inBrowser = isInBrowser();
|