@jitsu/js 1.1.1 → 1.1.2
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 +95 -65
- package/.turbo/turbo-clean.log +5 -5
- package/dist/jitsu.cjs.js +211 -79
- package/dist/jitsu.es.js +211 -79
- package/dist/web/p.js.txt +211 -79
- package/package.json +3 -3
- package/src/analytics-plugin.ts +10 -5
- package/dist/destination-plugins.d.ts +0 -17
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,65 +1,95 @@
|
|
|
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
|
-
[
|
|
1
|
+
@jitsu/js:build: cache hit, replaying output [2m528cebbe5d911d11[0m
|
|
2
|
+
[33m@jitsu/js:build: [0m
|
|
3
|
+
[33m@jitsu/js:build: [0m> @jitsu/js@0.0.0 build /Users/vklmn/dev2/newjitsu/libs/jitsu-js
|
|
4
|
+
[33m@jitsu/js:build: [0m> tsc -p . && rollup -c && cp compiled/src/*.d.ts dist
|
|
5
|
+
[33m@jitsu/js:build: [0m
|
|
6
|
+
[33m@jitsu/js:build: [0m[36m
|
|
7
|
+
[33m@jitsu/js:build: [0m[1m./compiled/src/browser.js[22m → [1mdist/web/p.js.txt[22m...[39m
|
|
8
|
+
[33m@jitsu/js:build: [0m[1m[33m(!) "this" has been rewritten to "undefined"[39m[22m
|
|
9
|
+
[33m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#error-this-is-undefined[39m
|
|
10
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/analytics-plugin.js[22m
|
|
11
|
+
[33m@jitsu/js:build: [0m[90m1: /* global analytics */
|
|
12
|
+
[33m@jitsu/js:build: [0m2: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
[33m@jitsu/js:build: [0m ^
|
|
14
|
+
[33m@jitsu/js:build: [0m3: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
[33m@jitsu/js:build: [0m4: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
16
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
17
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/tag.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/logrocket.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
|
|
30
|
+
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
31
|
+
[33m@jitsu/js:build: [0m ^
|
|
32
|
+
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
|
+
[33m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
34
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
35
|
+
[33m@jitsu/js:build: [0m[1m[33m(!) Circular dependencies[39m[22m
|
|
36
|
+
[33m@jitsu/js:build: [0mcompiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
|
|
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
|
|
41
|
+
[33m@jitsu/js:build: [0m[1m[33m(!) Use of eval is strongly discouraged[39m[22m
|
|
42
|
+
[33m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#avoiding-eval[39m
|
|
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);
|
|
47
|
+
[33m@jitsu/js:build: [0m ^
|
|
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 [1m212ms[22m[39m
|
|
51
|
+
[33m@jitsu/js:build: [0m[36m
|
|
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
|
|
53
|
+
[33m@jitsu/js:build: [0m[1m[33m(!) "this" has been rewritten to "undefined"[39m[22m
|
|
54
|
+
[33m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#error-this-is-undefined[39m
|
|
55
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/analytics-plugin.js[22m
|
|
56
|
+
[33m@jitsu/js:build: [0m[90m1: /* global analytics */
|
|
57
|
+
[33m@jitsu/js:build: [0m2: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
58
|
+
[33m@jitsu/js:build: [0m ^
|
|
59
|
+
[33m@jitsu/js:build: [0m3: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
60
|
+
[33m@jitsu/js:build: [0m4: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
61
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
62
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/tag.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/gtm.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/logrocket.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 [1m139ms[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 [2m87482d9c6faf899c[0m
|
|
2
|
+
[33m@jitsu/js:clean: [0m
|
|
3
|
+
[33m@jitsu/js:clean: [0m> @jitsu/js@0.0.0 clean /Users/vklmn/dev2/newjitsu/libs/jitsu-js
|
|
4
|
+
[33m@jitsu/js:clean: [0m> rm -rf ./dist
|
|
5
|
+
[33m@jitsu/js:clean: [0m
|
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$3 = (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,18 +119,10 @@ var __awaiter$1 = (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
|
-
}
|
|
130
122
|
const tagPlugin = {
|
|
131
123
|
id: "tag",
|
|
132
124
|
handle(config, payload) {
|
|
133
|
-
return __awaiter$
|
|
125
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
134
126
|
if (!applyFilters(payload, config)) {
|
|
135
127
|
return;
|
|
136
128
|
}
|
|
@@ -138,6 +130,96 @@ const tagPlugin = {
|
|
|
138
130
|
});
|
|
139
131
|
},
|
|
140
132
|
};
|
|
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
|
+
};
|
|
141
223
|
function getLogRocketState() {
|
|
142
224
|
return window["__jitsuLrState"] || "fresh";
|
|
143
225
|
}
|
|
@@ -163,7 +245,7 @@ function flushLogRocketQueue(lr) {
|
|
|
163
245
|
}
|
|
164
246
|
}
|
|
165
247
|
function initLogrocketIfNeeded(appId) {
|
|
166
|
-
return __awaiter$
|
|
248
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
167
249
|
if (getLogRocketState() !== "fresh") {
|
|
168
250
|
return;
|
|
169
251
|
}
|
|
@@ -188,88 +270,135 @@ function initLogrocketIfNeeded(appId) {
|
|
|
188
270
|
});
|
|
189
271
|
});
|
|
190
272
|
}
|
|
191
|
-
|
|
192
|
-
|
|
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",
|
|
193
286
|
handle(config, payload) {
|
|
287
|
+
var _a, _b;
|
|
194
288
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
195
289
|
if (!applyFilters(payload, config)) {
|
|
196
290
|
return;
|
|
197
291
|
}
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
292
|
+
yield initGtmIfNeeded(config);
|
|
293
|
+
const dataLayer = window[config.dataLayerName || "dataLayer"];
|
|
294
|
+
switch (payload.type) {
|
|
295
|
+
case "page":
|
|
296
|
+
const { properties: pageProperties, context } = payload;
|
|
297
|
+
const pageEvent = {
|
|
298
|
+
event: "page_view",
|
|
299
|
+
url: pageProperties.url,
|
|
300
|
+
title: pageProperties.title,
|
|
301
|
+
referer: (_b = (_a = context === null || context === void 0 ? void 0 : context.page) === null || _a === void 0 ? void 0 : _a.referrer) !== null && _b !== void 0 ? _b : "",
|
|
302
|
+
};
|
|
303
|
+
if (config.debug) {
|
|
304
|
+
console.log("gtag push", pageEvent);
|
|
305
|
+
}
|
|
306
|
+
dataLayer.push(pageEvent);
|
|
307
|
+
break;
|
|
308
|
+
case "track":
|
|
309
|
+
const { properties: trackProperties } = payload;
|
|
310
|
+
const trackEvent = Object.assign({ event: payload.event }, trackProperties);
|
|
311
|
+
if (payload.userId) {
|
|
312
|
+
trackEvent.userId = payload.userId;
|
|
313
|
+
}
|
|
314
|
+
if (payload.anonymousId) {
|
|
315
|
+
trackEvent.anonymousId = payload.anonymousId;
|
|
316
|
+
}
|
|
317
|
+
if (config.debug) {
|
|
318
|
+
console.log("gtag push", trackEvent);
|
|
319
|
+
}
|
|
320
|
+
dataLayer.push(trackEvent);
|
|
321
|
+
break;
|
|
322
|
+
case "identify":
|
|
323
|
+
const { traits } = payload;
|
|
324
|
+
const identifyEvent = Object.assign({ event: "identify" }, traits);
|
|
325
|
+
if (payload.userId) {
|
|
326
|
+
identifyEvent.userId = payload.userId;
|
|
327
|
+
}
|
|
328
|
+
if (payload.anonymousId) {
|
|
329
|
+
identifyEvent.anonymousId = payload.anonymousId;
|
|
330
|
+
}
|
|
331
|
+
if (config.debug) {
|
|
332
|
+
console.log("gtag push", identifyEvent);
|
|
333
|
+
}
|
|
334
|
+
dataLayer.push(identifyEvent);
|
|
335
|
+
break;
|
|
207
336
|
}
|
|
208
337
|
});
|
|
209
338
|
},
|
|
210
339
|
};
|
|
211
|
-
function
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (tag.lang === "javascript") {
|
|
222
|
-
execJs(tag.code, event);
|
|
223
|
-
}
|
|
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`);
|
|
340
|
+
function getGtmState() {
|
|
341
|
+
return window["__jitsuGtmState"] || "fresh";
|
|
342
|
+
}
|
|
343
|
+
function setGtmState(s) {
|
|
344
|
+
window["__jitsuGtmState"] = s;
|
|
345
|
+
}
|
|
346
|
+
function initGtmIfNeeded(config) {
|
|
347
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
348
|
+
if (getGtmState() !== "fresh") {
|
|
349
|
+
return;
|
|
247
350
|
}
|
|
248
|
-
|
|
351
|
+
setGtmState("loading");
|
|
352
|
+
const dlName = config.dataLayerName || "dataLayer";
|
|
353
|
+
const dlParam = dlName !== "dataLayer" ? "&l=" + dlName : "";
|
|
354
|
+
const previewParams = config.preview
|
|
355
|
+
? `>m_preview=${config.preview}>m_auth=${config.auth}>m_cookies_win=x`
|
|
356
|
+
: "";
|
|
357
|
+
const scriptSrc = `${config.customScriptSrc || defaultScriptSrc}?id=${config.containerId}${dlParam}${previewParams}`;
|
|
358
|
+
window[dlName] = window[dlName] || [];
|
|
359
|
+
const gtag = function () {
|
|
360
|
+
window[dlName].push(arguments);
|
|
361
|
+
};
|
|
362
|
+
// @ts-ignore
|
|
363
|
+
gtag("js", new Date());
|
|
364
|
+
// @ts-ignore
|
|
365
|
+
gtag("config", config.containerId);
|
|
366
|
+
loadScript(scriptSrc)
|
|
367
|
+
.then(() => {
|
|
368
|
+
setGtmState("loaded");
|
|
369
|
+
})
|
|
370
|
+
.catch(e => {
|
|
371
|
+
console.warn(`GTM (containerId=${config.containerId}) init failed: ${e.message}`, e);
|
|
372
|
+
setGtmState("failed");
|
|
373
|
+
});
|
|
374
|
+
});
|
|
249
375
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
try {
|
|
258
|
-
eval(iif);
|
|
376
|
+
|
|
377
|
+
function satisfyFilter(filter, subject) {
|
|
378
|
+
return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
|
|
379
|
+
}
|
|
380
|
+
function satisfyDomainFilter(filter, subject) {
|
|
381
|
+
if (filter === "*") {
|
|
382
|
+
return true;
|
|
259
383
|
}
|
|
260
|
-
|
|
261
|
-
|
|
384
|
+
subject = subject || "";
|
|
385
|
+
if (filter.startsWith("*.")) {
|
|
386
|
+
return subject.endsWith(filter.substring(1));
|
|
262
387
|
}
|
|
263
|
-
|
|
264
|
-
|
|
388
|
+
else {
|
|
389
|
+
return filter === subject;
|
|
265
390
|
}
|
|
266
|
-
return iif;
|
|
267
391
|
}
|
|
268
|
-
function
|
|
269
|
-
|
|
392
|
+
function applyFilters(event, creds) {
|
|
393
|
+
const { hosts = "*", events = "*" } = creds;
|
|
394
|
+
const eventsArray = events.split("\n");
|
|
395
|
+
return (!!hosts.split("\n").find(hostFilter => { var _a; return satisfyDomainFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
|
|
396
|
+
(!!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.type)) ||
|
|
397
|
+
!!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.event))));
|
|
270
398
|
}
|
|
271
399
|
const internalDestinationPlugins = {
|
|
272
400
|
[tagPlugin.id]: tagPlugin,
|
|
401
|
+
[gtmPlugin.id]: gtmPlugin,
|
|
273
402
|
[logrocketPlugin.id]: logrocketPlugin,
|
|
274
403
|
};
|
|
275
404
|
|
|
@@ -286,7 +415,7 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
|
|
|
286
415
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
287
416
|
});
|
|
288
417
|
};
|
|
289
|
-
const
|
|
418
|
+
const defaultConfig = {
|
|
290
419
|
/* Your segment writeKey */
|
|
291
420
|
writeKey: null,
|
|
292
421
|
/* Disable anonymous MTU */
|
|
@@ -593,10 +722,13 @@ function processDestinations(destinations, method, event, debug, analyticsInstan
|
|
|
593
722
|
}
|
|
594
723
|
});
|
|
595
724
|
}
|
|
725
|
+
function looksLikeCuid(id) {
|
|
726
|
+
return id.length === 25 && id.charAt(0) === "c";
|
|
727
|
+
}
|
|
596
728
|
function validateWriteKey(writeKey) {
|
|
597
729
|
if (writeKey) {
|
|
598
730
|
const [, secret] = writeKey.split(":", 2);
|
|
599
|
-
if (!secret) {
|
|
731
|
+
if (!secret && !looksLikeCuid(writeKey)) {
|
|
600
732
|
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
733
|
}
|
|
602
734
|
}
|
|
@@ -617,7 +749,7 @@ function send(method, payload, jitsuConfig, instance, store) {
|
|
|
617
749
|
// console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
|
|
618
750
|
// }
|
|
619
751
|
const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
|
|
620
|
-
const authHeader =
|
|
752
|
+
const authHeader = jitsuConfig.writeKey ? { "X-Write-Key": validateWriteKey(jitsuConfig.writeKey) } : {};
|
|
621
753
|
return fetch(url, {
|
|
622
754
|
method: "POST",
|
|
623
755
|
headers: Object.assign(Object.assign({ "Content-Type": "application/json" }, authHeader), debugHeader),
|
|
@@ -673,7 +805,7 @@ const jitsuAnalyticsPlugin = (pluginConfig = {}) => {
|
|
|
673
805
|
persistentStorage.removeItem(key);
|
|
674
806
|
},
|
|
675
807
|
});
|
|
676
|
-
const instanceConfig = Object.assign(Object.assign({},
|
|
808
|
+
const instanceConfig = Object.assign(Object.assign({}, defaultConfig), pluginConfig);
|
|
677
809
|
return {
|
|
678
810
|
name: "jitsu",
|
|
679
811
|
config: instanceConfig,
|