@jitsu/js 1.1.0-canary.388.20230519133920 → 1.1.0-canary.404.20230526224724
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/.turbo/turbo-build.log +65 -95
- package/.turbo/turbo-clean.log +5 -5
- package/__tests__/node/nodejs.test.ts +1 -1
- package/dist/analytics-plugin.d.ts +1 -0
- package/dist/destination-plugins.d.ts +17 -0
- package/dist/jitsu.cjs.js +96 -189
- package/dist/jitsu.es.js +96 -189
- package/dist/version.d.ts +2 -0
- package/dist/web/p.js.txt +96 -189
- package/package.json +3 -3
- package/src/analytics-plugin.ts +21 -7
- package/src/destination-plugins/gtm.ts +20 -10
- package/src/destination-plugins/index.ts +20 -5
- package/src/version.ts +3 -0
- package/tsconfig.json +1 -0
- package/.pnpm-debug.log +0 -23
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,95 +1,65 @@
|
|
|
1
|
-
@jitsu/js:build: cache hit, replaying output [
|
|
2
|
-
[
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
[
|
|
36
|
-
[
|
|
37
|
-
[
|
|
38
|
-
[
|
|
39
|
-
[
|
|
40
|
-
[
|
|
41
|
-
[
|
|
42
|
-
[
|
|
43
|
-
[
|
|
44
|
-
[
|
|
45
|
-
[
|
|
46
|
-
[
|
|
47
|
-
[
|
|
48
|
-
[
|
|
49
|
-
[
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
[
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
56
|
-
[
|
|
57
|
-
[
|
|
58
|
-
[
|
|
59
|
-
[
|
|
60
|
-
[
|
|
61
|
-
[
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
[
|
|
65
|
-
[
|
|
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
|
|
75
|
-
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
76
|
-
[33m@jitsu/js:build: [0m ^
|
|
77
|
-
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
78
|
-
[33m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
79
|
-
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
80
|
-
[33m@jitsu/js:build: [0m[1m[33m(!) Circular dependencies[39m[22m
|
|
81
|
-
[33m@jitsu/js:build: [0mcompiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
|
|
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
|
|
86
|
-
[33m@jitsu/js:build: [0m[1m[33m(!) Use of eval is strongly discouraged[39m[22m
|
|
87
|
-
[33m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#avoiding-eval[39m
|
|
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);
|
|
92
|
-
[33m@jitsu/js:build: [0m ^
|
|
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
|
|
1
|
+
@jitsu/js:build: cache hit, replaying output [2m03414e3b139b4a1c[0m
|
|
2
|
+
[34m@jitsu/js:build: [0m
|
|
3
|
+
[34m@jitsu/js:build: [0m> @jitsu/js@0.0.0 build /Users/vklmn/dev2/onetag/libs/jitsu-js
|
|
4
|
+
[34m@jitsu/js:build: [0m> tsc -p . && rollup -c && cp compiled/src/*.d.ts dist
|
|
5
|
+
[34m@jitsu/js:build: [0m
|
|
6
|
+
[34m@jitsu/js:build: [0m[36m
|
|
7
|
+
[34m@jitsu/js:build: [0m[1m./compiled/src/browser.js[22m → [1mdist/web/p.js.txt[22m...[39m
|
|
8
|
+
[34m@jitsu/js:build: [0m[1m[33m(!) "this" has been rewritten to "undefined"[39m[22m
|
|
9
|
+
[34m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#error-this-is-undefined[39m
|
|
10
|
+
[34m@jitsu/js:build: [0m[1mcompiled/src/analytics-plugin.js[22m
|
|
11
|
+
[34m@jitsu/js:build: [0m[90m1: /* global analytics */
|
|
12
|
+
[34m@jitsu/js:build: [0m2: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
[34m@jitsu/js:build: [0m ^
|
|
14
|
+
[34m@jitsu/js:build: [0m3: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
[34m@jitsu/js:build: [0m4: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
16
|
+
[34m@jitsu/js:build: [0m...and 1 other occurrence
|
|
17
|
+
[34m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins.js[22m
|
|
18
|
+
[34m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
|
+
[34m@jitsu/js:build: [0m ^
|
|
20
|
+
[34m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
+
[34m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
22
|
+
[34m@jitsu/js:build: [0m...and 1 other occurrence
|
|
23
|
+
[34m@jitsu/js:build: [0m[1m[33m(!) Circular dependencies[39m[22m
|
|
24
|
+
[34m@jitsu/js:build: [0mcompiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
|
|
25
|
+
[34m@jitsu/js:build: [0mcompiled/src/analytics-plugin.js -> compiled/src/destination-plugins.js -> compiled/src/analytics-plugin.js
|
|
26
|
+
[34m@jitsu/js:build: [0m[1m[33m(!) Use of eval is strongly discouraged[39m[22m
|
|
27
|
+
[34m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#avoiding-eval[39m
|
|
28
|
+
[34m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins.js[22m
|
|
29
|
+
[34m@jitsu/js:build: [0m[90m146: })()`;
|
|
30
|
+
[34m@jitsu/js:build: [0m147: try {
|
|
31
|
+
[34m@jitsu/js:build: [0m148: eval(iif);
|
|
32
|
+
[34m@jitsu/js:build: [0m ^
|
|
33
|
+
[34m@jitsu/js:build: [0m149: }
|
|
34
|
+
[34m@jitsu/js:build: [0m150: catch (e) {[39m
|
|
35
|
+
[34m@jitsu/js:build: [0m[32mcreated [1mdist/web/p.js.txt[22m in [1m195ms[22m[39m
|
|
36
|
+
[34m@jitsu/js:build: [0m[36m
|
|
37
|
+
[34m@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
|
+
[34m@jitsu/js:build: [0m[1m[33m(!) "this" has been rewritten to "undefined"[39m[22m
|
|
39
|
+
[34m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#error-this-is-undefined[39m
|
|
40
|
+
[34m@jitsu/js:build: [0m[1mcompiled/src/analytics-plugin.js[22m
|
|
41
|
+
[34m@jitsu/js:build: [0m[90m1: /* global analytics */
|
|
42
|
+
[34m@jitsu/js:build: [0m2: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
43
|
+
[34m@jitsu/js:build: [0m ^
|
|
44
|
+
[34m@jitsu/js:build: [0m3: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
45
|
+
[34m@jitsu/js:build: [0m4: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
46
|
+
[34m@jitsu/js:build: [0m...and 1 other occurrence
|
|
47
|
+
[34m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins.js[22m
|
|
48
|
+
[34m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
49
|
+
[34m@jitsu/js:build: [0m ^
|
|
50
|
+
[34m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
51
|
+
[34m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
52
|
+
[34m@jitsu/js:build: [0m...and 1 other occurrence
|
|
53
|
+
[34m@jitsu/js:build: [0m[1m[33m(!) Circular dependencies[39m[22m
|
|
54
|
+
[34m@jitsu/js:build: [0mcompiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
|
|
55
|
+
[34m@jitsu/js:build: [0mcompiled/src/analytics-plugin.js -> compiled/src/destination-plugins.js -> compiled/src/analytics-plugin.js
|
|
56
|
+
[34m@jitsu/js:build: [0m[1m[33m(!) Use of eval is strongly discouraged[39m[22m
|
|
57
|
+
[34m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#avoiding-eval[39m
|
|
58
|
+
[34m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins.js[22m
|
|
59
|
+
[34m@jitsu/js:build: [0m[90m146: })()`;
|
|
60
|
+
[34m@jitsu/js:build: [0m147: try {
|
|
61
|
+
[34m@jitsu/js:build: [0m148: eval(iif);
|
|
62
|
+
[34m@jitsu/js:build: [0m ^
|
|
63
|
+
[34m@jitsu/js:build: [0m149: }
|
|
64
|
+
[34m@jitsu/js:build: [0m150: catch (e) {[39m
|
|
65
|
+
[34m@jitsu/js:build: [0m[32mcreated [1mdist/jitsu.es.js, dist/jitsu.cjs.js[22m in [1m133ms[22m[39m
|
package/.turbo/turbo-clean.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
@jitsu/js:clean: cache hit, replaying output [
|
|
2
|
-
[
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
1
|
+
@jitsu/js:clean: cache hit, replaying output [2m02a6b0bcaf2c7148[0m
|
|
2
|
+
[34m@jitsu/js:clean: [0m
|
|
3
|
+
[34m@jitsu/js:clean: [0m> @jitsu/js@0.0.0 clean /Users/vklmn/dev2/onetag/libs/jitsu-js
|
|
4
|
+
[34m@jitsu/js:clean: [0m> rm -rf ./dist
|
|
5
|
+
[34m@jitsu/js:clean: [0m
|
|
@@ -0,0 +1,17 @@
|
|
|
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 type LogRocketDestinationCredentials = {
|
|
14
|
+
appId: string;
|
|
15
|
+
} & CommonDestinationCredentials;
|
|
16
|
+
export type LogRocket = any;
|
|
17
|
+
export declare const internalDestinationPlugins: Record<string, InternalPlugin<any>>;
|
package/dist/jitsu.cjs.js
CHANGED
|
@@ -110,7 +110,7 @@ function loadScript(src, attributes) {
|
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
var __awaiter$
|
|
113
|
+
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
114
114
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
115
115
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
116
116
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -119,10 +119,18 @@ var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
119
119
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
120
120
|
});
|
|
121
121
|
};
|
|
122
|
+
function satisfyFilter(filter, subject) {
|
|
123
|
+
return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
|
|
124
|
+
}
|
|
125
|
+
function applyFilters(event, creds) {
|
|
126
|
+
const { hosts = ["*"], events = ["*"] } = creds;
|
|
127
|
+
return (!!hosts.find(hostFilter => { var _a; return satisfyFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
|
|
128
|
+
!!events.find(eventFilter => satisfyFilter(eventFilter, event.type)));
|
|
129
|
+
}
|
|
122
130
|
const tagPlugin = {
|
|
123
131
|
id: "tag",
|
|
124
132
|
handle(config, payload) {
|
|
125
|
-
return __awaiter$
|
|
133
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
126
134
|
if (!applyFilters(payload, config)) {
|
|
127
135
|
return;
|
|
128
136
|
}
|
|
@@ -130,96 +138,6 @@ const tagPlugin = {
|
|
|
130
138
|
});
|
|
131
139
|
},
|
|
132
140
|
};
|
|
133
|
-
function insertTags(code, event, opts = {}) {
|
|
134
|
-
let tag;
|
|
135
|
-
try {
|
|
136
|
-
tag = JSON.parse(code);
|
|
137
|
-
}
|
|
138
|
-
catch (e) {
|
|
139
|
-
tag = { code, lang: "javascript" };
|
|
140
|
-
}
|
|
141
|
-
const debug = opts.debug || false;
|
|
142
|
-
if (isInBrowser()) {
|
|
143
|
-
if (tag.lang === "javascript") {
|
|
144
|
-
execJs(tag.code, event);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
const codeHolder = document.createElement("span");
|
|
148
|
-
codeHolder.innerHTML = replaceMacro(tag.code, event);
|
|
149
|
-
document.body.insertAdjacentElement("beforeend", codeHolder);
|
|
150
|
-
const scripts = codeHolder.querySelectorAll("script");
|
|
151
|
-
scripts.forEach(script => {
|
|
152
|
-
const scriptClone = document.createElement("script");
|
|
153
|
-
scriptClone.type = scriptClone.type || "text/javascript";
|
|
154
|
-
if (script.hasAttribute("src")) {
|
|
155
|
-
scriptClone.src = script.src;
|
|
156
|
-
}
|
|
157
|
-
scriptClone.text = script.text;
|
|
158
|
-
if (debug) {
|
|
159
|
-
console.log(`[JITSU] Executing script${script.hasAttribute("src") ? ` ${script.src}` : ""}`, scriptClone.text);
|
|
160
|
-
}
|
|
161
|
-
document.head.appendChild(scriptClone);
|
|
162
|
-
document.head.removeChild(scriptClone);
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
if (debug) {
|
|
168
|
-
console.log(`[JITSU] insertTags(): cannot insert tags in non-browser environment`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
function execJs(code, event) {
|
|
173
|
-
const varName = `jitsu_event_${randomId()}`;
|
|
174
|
-
window[varName] = event;
|
|
175
|
-
const iif = `(function(){
|
|
176
|
-
const event = ${varName};
|
|
177
|
-
${code}
|
|
178
|
-
})()`;
|
|
179
|
-
try {
|
|
180
|
-
eval(iif);
|
|
181
|
-
}
|
|
182
|
-
catch (e) {
|
|
183
|
-
console.error(`[JITSU] Error executing JS code: ${e.message}. Code: `, iif);
|
|
184
|
-
}
|
|
185
|
-
finally {
|
|
186
|
-
delete window[varName];
|
|
187
|
-
}
|
|
188
|
-
return iif;
|
|
189
|
-
}
|
|
190
|
-
function replaceMacro(code, event) {
|
|
191
|
-
return code.replace(/{{\s*event\s*}}/g, JSON.stringify(event));
|
|
192
|
-
}
|
|
193
|
-
|
|
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
141
|
function getLogRocketState() {
|
|
224
142
|
return window["__jitsuLrState"] || "fresh";
|
|
225
143
|
}
|
|
@@ -245,7 +163,7 @@ function flushLogRocketQueue(lr) {
|
|
|
245
163
|
}
|
|
246
164
|
}
|
|
247
165
|
function initLogrocketIfNeeded(appId) {
|
|
248
|
-
return __awaiter$
|
|
166
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
249
167
|
if (getLogRocketState() !== "fresh") {
|
|
250
168
|
return;
|
|
251
169
|
}
|
|
@@ -270,113 +188,94 @@ function initLogrocketIfNeeded(appId) {
|
|
|
270
188
|
});
|
|
271
189
|
});
|
|
272
190
|
}
|
|
273
|
-
|
|
274
|
-
|
|
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",
|
|
191
|
+
const logrocketPlugin = {
|
|
192
|
+
id: "logrocket",
|
|
286
193
|
handle(config, payload) {
|
|
287
194
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
288
195
|
if (!applyFilters(payload, config)) {
|
|
289
196
|
return;
|
|
290
197
|
}
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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;
|
|
198
|
+
initLogrocketIfNeeded(config.appId);
|
|
199
|
+
const action = logRocket => {
|
|
200
|
+
if (payload.type === "identify" && payload.userId) {
|
|
201
|
+
logRocket.identify(payload.userId, payload.traits || {});
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
getLogRocketQueue().push(action);
|
|
205
|
+
if (getLogRocketState() === "loaded") {
|
|
206
|
+
flushLogRocketQueue(window["LogRocket"]);
|
|
325
207
|
}
|
|
326
208
|
});
|
|
327
209
|
},
|
|
328
210
|
};
|
|
329
|
-
function
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
211
|
+
function insertTags(code, event, opts = {}) {
|
|
212
|
+
let tag;
|
|
213
|
+
try {
|
|
214
|
+
tag = JSON.parse(code);
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
tag = { code, lang: "javascript" };
|
|
218
|
+
}
|
|
219
|
+
const debug = opts.debug || false;
|
|
220
|
+
if (isInBrowser()) {
|
|
221
|
+
if (tag.lang === "javascript") {
|
|
222
|
+
execJs(tag.code, event);
|
|
339
223
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
224
|
+
else {
|
|
225
|
+
const codeHolder = document.createElement("span");
|
|
226
|
+
codeHolder.innerHTML = replaceMacro(tag.code, event);
|
|
227
|
+
document.body.insertAdjacentElement("beforeend", codeHolder);
|
|
228
|
+
const scripts = codeHolder.querySelectorAll("script");
|
|
229
|
+
scripts.forEach(script => {
|
|
230
|
+
const scriptClone = document.createElement("script");
|
|
231
|
+
scriptClone.type = scriptClone.type || "text/javascript";
|
|
232
|
+
if (script.hasAttribute("src")) {
|
|
233
|
+
scriptClone.src = script.src;
|
|
234
|
+
}
|
|
235
|
+
scriptClone.text = script.text;
|
|
236
|
+
if (debug) {
|
|
237
|
+
console.log(`[JITSU] Executing script${script.hasAttribute("src") ? ` ${script.src}` : ""}`, scriptClone.text);
|
|
238
|
+
}
|
|
239
|
+
document.head.appendChild(scriptClone);
|
|
240
|
+
document.head.removeChild(scriptClone);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
if (debug) {
|
|
246
|
+
console.log(`[JITSU] insertTags(): cannot insert tags in non-browser environment`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
364
249
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
250
|
+
function execJs(code, event) {
|
|
251
|
+
const varName = `jitsu_event_${randomId()}`;
|
|
252
|
+
window[varName] = event;
|
|
253
|
+
const iif = `(function(){
|
|
254
|
+
const event = ${varName};
|
|
255
|
+
${code}
|
|
256
|
+
})()`;
|
|
257
|
+
try {
|
|
258
|
+
eval(iif);
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
console.error(`[JITSU] Error executing JS code: ${e.message}. Code: `, iif);
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
delete window[varName];
|
|
265
|
+
}
|
|
266
|
+
return iif;
|
|
368
267
|
}
|
|
369
|
-
function
|
|
370
|
-
|
|
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)));
|
|
268
|
+
function replaceMacro(code, event) {
|
|
269
|
+
return code.replace(/{{\s*event\s*}}/g, JSON.stringify(event));
|
|
373
270
|
}
|
|
374
271
|
const internalDestinationPlugins = {
|
|
375
272
|
[tagPlugin.id]: tagPlugin,
|
|
376
|
-
[gtmPlugin.id]: gtmPlugin,
|
|
377
273
|
[logrocketPlugin.id]: logrocketPlugin,
|
|
378
274
|
};
|
|
379
275
|
|
|
276
|
+
var name = "@jitsu/js";
|
|
277
|
+
var version = "0.0.0";
|
|
278
|
+
|
|
380
279
|
/* global analytics */
|
|
381
280
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
382
281
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -614,8 +513,8 @@ function adjustPayload(payload, config, storage) {
|
|
|
614
513
|
const referrer = runtime.referrer();
|
|
615
514
|
const context = {
|
|
616
515
|
library: {
|
|
617
|
-
name:
|
|
618
|
-
version:
|
|
516
|
+
name: name,
|
|
517
|
+
version: version,
|
|
619
518
|
},
|
|
620
519
|
userAgent: runtime.userAgent(),
|
|
621
520
|
locale: runtime.language(),
|
|
@@ -633,7 +532,7 @@ function adjustPayload(payload, config, storage) {
|
|
|
633
532
|
},
|
|
634
533
|
campaign: parseUtms(query),
|
|
635
534
|
};
|
|
636
|
-
const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), writeKey: config.writeKey, context: deepMerge(context, customContext) });
|
|
535
|
+
const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), writeKey: validateWriteKey(config.writeKey), context: deepMerge(context, customContext) });
|
|
637
536
|
delete withContext.meta;
|
|
638
537
|
delete withContext.options;
|
|
639
538
|
return withContext;
|
|
@@ -642,12 +541,11 @@ function processDestinations(destinations, method, event, debug, analyticsInstan
|
|
|
642
541
|
return __awaiter(this, void 0, void 0, function* () {
|
|
643
542
|
const promises = [];
|
|
644
543
|
for (const destination of destinations) {
|
|
544
|
+
const credentials = Object.assign(Object.assign({}, destination.credentials), destination.options);
|
|
645
545
|
if (destination.deviceOptions.type === "internal-plugin") {
|
|
646
546
|
const plugin = internalDestinationPlugins[destination.deviceOptions.name];
|
|
647
547
|
if (plugin) {
|
|
648
548
|
try {
|
|
649
|
-
//to support old versions, where credentials were stored in root
|
|
650
|
-
const credentials = destination.credentials || destination;
|
|
651
549
|
promises.push(plugin.handle(credentials, event));
|
|
652
550
|
}
|
|
653
551
|
catch (e) {
|
|
@@ -667,7 +565,7 @@ function processDestinations(destinations, method, event, debug, analyticsInstan
|
|
|
667
565
|
else {
|
|
668
566
|
let pluginInstance;
|
|
669
567
|
try {
|
|
670
|
-
pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(
|
|
568
|
+
pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(credentials);
|
|
671
569
|
}
|
|
672
570
|
catch (e) {
|
|
673
571
|
console.warn(`[JITSU] Error creating plugin '${destination.deviceOptions.moduleVarName}@${destination.deviceOptions.packageCdn}' for destination '${destination.id}': ${e === null || e === void 0 ? void 0 : e.message}`, e);
|
|
@@ -695,6 +593,15 @@ function processDestinations(destinations, method, event, debug, analyticsInstan
|
|
|
695
593
|
}
|
|
696
594
|
});
|
|
697
595
|
}
|
|
596
|
+
function validateWriteKey(writeKey) {
|
|
597
|
+
if (writeKey) {
|
|
598
|
+
const [, secret] = writeKey.split(":", 2);
|
|
599
|
+
if (!secret) {
|
|
600
|
+
throw new Error(`Legacy write key detected - ${writeKey}! This format doesn't work anymore, it should be 'key:secret'. Please download a new key from Jitsu UI`);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return writeKey;
|
|
604
|
+
}
|
|
698
605
|
function send(method, payload, jitsuConfig, instance, store) {
|
|
699
606
|
if (jitsuConfig.echoEvents) {
|
|
700
607
|
console.log(`[JITSU] sending '${method}' event:`, payload);
|
|
@@ -710,7 +617,7 @@ function send(method, payload, jitsuConfig, instance, store) {
|
|
|
710
617
|
// console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
|
|
711
618
|
// }
|
|
712
619
|
const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
|
|
713
|
-
const authHeader =
|
|
620
|
+
const authHeader = config.writeKey ? { "X-Write-Key": validateWriteKey(config.writeKey) } : {};
|
|
714
621
|
return fetch(url, {
|
|
715
622
|
method: "POST",
|
|
716
623
|
headers: Object.assign(Object.assign({ "Content-Type": "application/json" }, authHeader), debugHeader),
|