@jitsu/js 1.5.1 → 1.6.1
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 +105 -95
- package/.turbo/turbo-clean.log +5 -5
- package/README.md +9 -0
- package/dist/analytics-plugin.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/jitsu.cjs.js +166 -56
- package/dist/jitsu.es.js +166 -57
- package/dist/web/p.js.txt +1 -1
- package/package.json +2 -2
- package/src/analytics-plugin.ts +52 -15
- package/src/destination-plugins/ga4.ts +123 -0
- package/src/destination-plugins/gtm.ts +39 -38
- package/src/destination-plugins/index.ts +3 -1
- package/src/index.ts +1 -0
- package/tsconfig.json +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,95 +1,105 @@
|
|
|
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
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
75
|
-
[
|
|
76
|
-
[
|
|
77
|
-
[
|
|
78
|
-
[
|
|
79
|
-
[
|
|
80
|
-
[
|
|
81
|
-
[
|
|
82
|
-
[
|
|
83
|
-
[
|
|
84
|
-
[
|
|
85
|
-
[
|
|
86
|
-
[
|
|
87
|
-
[
|
|
88
|
-
[
|
|
89
|
-
[
|
|
90
|
-
[
|
|
91
|
-
[
|
|
92
|
-
[
|
|
93
|
-
[
|
|
94
|
-
[
|
|
95
|
-
[
|
|
1
|
+
@jitsu/js:build: cache hit, replaying output [2mc3f20c137ae4b178[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/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/ga4.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[1mcompiled/src/destination-plugins/gtm.js[22m
|
|
36
|
+
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
[33m@jitsu/js:build: [0m ^
|
|
38
|
+
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
39
|
+
[33m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
40
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
41
|
+
[33m@jitsu/js:build: [0m[1m[33m(!) Circular dependencies[39m[22m
|
|
42
|
+
[33m@jitsu/js:build: [0mcompiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
|
|
43
|
+
[33m@jitsu/js:build: [0mcompiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/destination-plugins/index.js
|
|
44
|
+
[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
|
|
45
|
+
[33m@jitsu/js:build: [0m...and 3 more
|
|
46
|
+
[33m@jitsu/js:build: [0m[1m[33m(!) Use of eval is strongly discouraged[39m[22m
|
|
47
|
+
[33m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#avoiding-eval[39m
|
|
48
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/tag.js[22m
|
|
49
|
+
[33m@jitsu/js:build: [0m[90m68: })()`;
|
|
50
|
+
[33m@jitsu/js:build: [0m69: try {
|
|
51
|
+
[33m@jitsu/js:build: [0m70: eval(iif);
|
|
52
|
+
[33m@jitsu/js:build: [0m ^
|
|
53
|
+
[33m@jitsu/js:build: [0m71: }
|
|
54
|
+
[33m@jitsu/js:build: [0m72: catch (e) {[39m
|
|
55
|
+
[33m@jitsu/js:build: [0m[32mcreated [1mdist/web/p.js.txt[22m in [1m434ms[22m[39m
|
|
56
|
+
[33m@jitsu/js:build: [0m[36m
|
|
57
|
+
[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
|
|
58
|
+
[33m@jitsu/js:build: [0m[1m[33m(!) "this" has been rewritten to "undefined"[39m[22m
|
|
59
|
+
[33m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#error-this-is-undefined[39m
|
|
60
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/analytics-plugin.js[22m
|
|
61
|
+
[33m@jitsu/js:build: [0m[90m1: /* global analytics */
|
|
62
|
+
[33m@jitsu/js:build: [0m2: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
63
|
+
[33m@jitsu/js:build: [0m ^
|
|
64
|
+
[33m@jitsu/js:build: [0m3: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
65
|
+
[33m@jitsu/js:build: [0m4: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
66
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
67
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/gtm.js[22m
|
|
68
|
+
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
69
|
+
[33m@jitsu/js:build: [0m ^
|
|
70
|
+
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
71
|
+
[33m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
72
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
73
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/ga4.js[22m
|
|
74
|
+
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
75
|
+
[33m@jitsu/js:build: [0m ^
|
|
76
|
+
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
77
|
+
[33m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
78
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
79
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/tag.js[22m
|
|
80
|
+
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
81
|
+
[33m@jitsu/js:build: [0m ^
|
|
82
|
+
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
83
|
+
[33m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
84
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
85
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/logrocket.js[22m
|
|
86
|
+
[33m@jitsu/js:build: [0m[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
87
|
+
[33m@jitsu/js:build: [0m ^
|
|
88
|
+
[33m@jitsu/js:build: [0m2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
89
|
+
[33m@jitsu/js:build: [0m3: return new (P || (P = Promise))(function (resolve, reject) {[39m
|
|
90
|
+
[33m@jitsu/js:build: [0m...and 1 other occurrence
|
|
91
|
+
[33m@jitsu/js:build: [0m[1m[33m(!) Circular dependencies[39m[22m
|
|
92
|
+
[33m@jitsu/js:build: [0mcompiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
|
|
93
|
+
[33m@jitsu/js:build: [0mcompiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/destination-plugins/index.js
|
|
94
|
+
[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
|
|
95
|
+
[33m@jitsu/js:build: [0m...and 3 more
|
|
96
|
+
[33m@jitsu/js:build: [0m[1m[33m(!) Use of eval is strongly discouraged[39m[22m
|
|
97
|
+
[33m@jitsu/js:build: [0m[90mhttps://rollupjs.org/troubleshooting/#avoiding-eval[39m
|
|
98
|
+
[33m@jitsu/js:build: [0m[1mcompiled/src/destination-plugins/tag.js[22m
|
|
99
|
+
[33m@jitsu/js:build: [0m[90m68: })()`;
|
|
100
|
+
[33m@jitsu/js:build: [0m69: try {
|
|
101
|
+
[33m@jitsu/js:build: [0m70: eval(iif);
|
|
102
|
+
[33m@jitsu/js:build: [0m ^
|
|
103
|
+
[33m@jitsu/js:build: [0m71: }
|
|
104
|
+
[33m@jitsu/js:build: [0m72: catch (e) {[39m
|
|
105
|
+
[33m@jitsu/js:build: [0m[32mcreated [1mdist/jitsu.es.js, dist/jitsu.cjs.js[22m in [1m126ms[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 [2m01f8d33de867ec80[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/README.md
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export declare const emptyAnalytics: {
|
|
|
11
11
|
export declare function jitsuAnalytics(opts: JitsuOptions): AnalyticsInterface;
|
|
12
12
|
export * from "./jitsu";
|
|
13
13
|
export * from "./analytics-plugin";
|
|
14
|
+
export { applyFilters } from "./destination-plugins";
|
|
14
15
|
export { getTopLevelDomain } from "./tlds";
|
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$4 = (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); } }
|
|
@@ -122,7 +122,7 @@ var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
122
122
|
const tagPlugin = {
|
|
123
123
|
id: "tag",
|
|
124
124
|
handle(config, payload) {
|
|
125
|
-
return __awaiter$
|
|
125
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
126
126
|
if (!applyFilters(payload, config)) {
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
@@ -191,7 +191,7 @@ function replaceMacro(code, event) {
|
|
|
191
191
|
return code.replace(/{{\s*event\s*}}/g, JSON.stringify(event));
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
var __awaiter$
|
|
194
|
+
var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
195
195
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
196
196
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
197
197
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -203,7 +203,7 @@ var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
203
203
|
const logrocketPlugin = {
|
|
204
204
|
id: "logrocket",
|
|
205
205
|
handle(config, payload) {
|
|
206
|
-
return __awaiter$
|
|
206
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
207
207
|
if (!applyFilters(payload, config)) {
|
|
208
208
|
return;
|
|
209
209
|
}
|
|
@@ -245,7 +245,7 @@ function flushLogRocketQueue(lr) {
|
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
function initLogrocketIfNeeded(appId) {
|
|
248
|
-
return __awaiter$
|
|
248
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
249
249
|
if (getLogRocketState() !== "fresh") {
|
|
250
250
|
return;
|
|
251
251
|
}
|
|
@@ -271,7 +271,7 @@ function initLogrocketIfNeeded(appId) {
|
|
|
271
271
|
});
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
var __awaiter$
|
|
274
|
+
var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
275
275
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
276
276
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
277
277
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -280,60 +280,38 @@ var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
280
280
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
281
281
|
});
|
|
282
282
|
};
|
|
283
|
-
const defaultScriptSrc = "https://www.googletagmanager.com/gtag/js";
|
|
283
|
+
const defaultScriptSrc$1 = "https://www.googletagmanager.com/gtag/js";
|
|
284
284
|
const gtmPlugin = {
|
|
285
285
|
id: "gtm",
|
|
286
286
|
handle(config, payload) {
|
|
287
287
|
var _a, _b;
|
|
288
|
-
return __awaiter$
|
|
288
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
289
289
|
if (!applyFilters(payload, config)) {
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
292
|
-
yield initGtmIfNeeded(config);
|
|
292
|
+
yield initGtmIfNeeded(config, payload);
|
|
293
293
|
const dataLayer = window[config.dataLayerName || "dataLayer"];
|
|
294
|
+
const ids = Object.assign(Object.assign({}, (payload.userId ? { user_id: payload.userId, userId: payload.userId } : {})), (payload.anonymousId ? { anonymousId: payload.anonymousId } : {}));
|
|
294
295
|
switch (payload.type) {
|
|
295
296
|
case "page":
|
|
296
297
|
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
|
-
}
|
|
298
|
+
const pageEvent = Object.assign({ event: "page_view", page_location: pageProperties.url, page_title: pageProperties.title, page_path: pageProperties.path, page_hash: pageProperties.hash, page_search: pageProperties.search, page_referrer: (_b = (_a = context === null || context === void 0 ? void 0 : context.page) === null || _a === void 0 ? void 0 : _a.referrer) !== null && _b !== void 0 ? _b : "" }, ids);
|
|
306
299
|
dataLayer.push(pageEvent);
|
|
307
300
|
break;
|
|
308
301
|
case "track":
|
|
309
302
|
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
|
-
}
|
|
303
|
+
const trackEvent = Object.assign(Object.assign({ event: payload.event }, trackProperties), ids);
|
|
320
304
|
dataLayer.push(trackEvent);
|
|
321
305
|
break;
|
|
322
306
|
case "identify":
|
|
323
307
|
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
|
-
}
|
|
308
|
+
const identifyEvent = Object.assign(Object.assign({ event: "identify" }, traits), ids);
|
|
334
309
|
dataLayer.push(identifyEvent);
|
|
335
310
|
break;
|
|
336
311
|
}
|
|
312
|
+
dataLayer.push(function () {
|
|
313
|
+
this.reset();
|
|
314
|
+
});
|
|
337
315
|
});
|
|
338
316
|
},
|
|
339
317
|
};
|
|
@@ -343,8 +321,8 @@ function getGtmState() {
|
|
|
343
321
|
function setGtmState(s) {
|
|
344
322
|
window["__jitsuGtmState"] = s;
|
|
345
323
|
}
|
|
346
|
-
function initGtmIfNeeded(config) {
|
|
347
|
-
return __awaiter$
|
|
324
|
+
function initGtmIfNeeded(config, payload) {
|
|
325
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
348
326
|
if (getGtmState() !== "fresh") {
|
|
349
327
|
return;
|
|
350
328
|
}
|
|
@@ -354,26 +332,122 @@ function initGtmIfNeeded(config) {
|
|
|
354
332
|
const previewParams = config.preview
|
|
355
333
|
? `>m_preview=${config.preview}>m_auth=${config.auth}>m_cookies_win=x`
|
|
356
334
|
: "";
|
|
357
|
-
const
|
|
335
|
+
const tagId = config.containerId;
|
|
336
|
+
const scriptSrc = `${config.customScriptSrc || defaultScriptSrc$1}?id=${tagId}${dlParam}${previewParams}`;
|
|
358
337
|
window[dlName] = window[dlName] || [];
|
|
359
338
|
const gtag = function () {
|
|
360
339
|
window[dlName].push(arguments);
|
|
361
340
|
};
|
|
341
|
+
window[dlName].push({
|
|
342
|
+
user_id: payload.userId,
|
|
343
|
+
});
|
|
362
344
|
// @ts-ignore
|
|
363
345
|
gtag("js", new Date());
|
|
364
346
|
// @ts-ignore
|
|
365
|
-
gtag("config",
|
|
347
|
+
gtag("config", tagId);
|
|
366
348
|
loadScript(scriptSrc)
|
|
367
349
|
.then(() => {
|
|
368
350
|
setGtmState("loaded");
|
|
369
351
|
})
|
|
370
352
|
.catch(e => {
|
|
371
|
-
console.warn(`GTM (containerId=${
|
|
353
|
+
console.warn(`GTM (containerId=${tagId}) init failed: ${e.message}`, e);
|
|
372
354
|
setGtmState("failed");
|
|
373
355
|
});
|
|
374
356
|
});
|
|
375
357
|
}
|
|
376
358
|
|
|
359
|
+
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
360
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
361
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
362
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
363
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
364
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
365
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
366
|
+
});
|
|
367
|
+
};
|
|
368
|
+
const defaultScriptSrc = "https://www.googletagmanager.com/gtag/js";
|
|
369
|
+
const ga4Plugin = {
|
|
370
|
+
id: "ga4-tag",
|
|
371
|
+
handle(config, payload) {
|
|
372
|
+
var _a, _b;
|
|
373
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
374
|
+
if (!applyFilters(payload, config)) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
yield initGa4IfNeeded(config, payload);
|
|
378
|
+
const dataLayer = window[config.dataLayerName || "dataLayer"];
|
|
379
|
+
const gtag = function () {
|
|
380
|
+
dataLayer.push(arguments);
|
|
381
|
+
};
|
|
382
|
+
const ids = Object.assign(Object.assign({}, (payload.userId ? { user_id: payload.userId, userId: payload.userId } : {})), (payload.anonymousId ? { anonymousId: payload.anonymousId } : {}));
|
|
383
|
+
if (payload.userId) {
|
|
384
|
+
// @ts-ignore
|
|
385
|
+
gtag("set", { user_id: payload.userId });
|
|
386
|
+
}
|
|
387
|
+
switch (payload.type) {
|
|
388
|
+
case "page":
|
|
389
|
+
if (config.autoPageView) {
|
|
390
|
+
console.log("autoPageView");
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
const { properties: pageProperties, context } = payload;
|
|
394
|
+
const pageEvent = Object.assign({ page_location: pageProperties.url, page_title: pageProperties.title, page_path: pageProperties.path, page_hash: pageProperties.hash, page_search: pageProperties.search, page_referrer: (_b = (_a = context === null || context === void 0 ? void 0 : context.page) === null || _a === void 0 ? void 0 : _a.referrer) !== null && _b !== void 0 ? _b : "" }, ids);
|
|
395
|
+
// @ts-ignore
|
|
396
|
+
gtag("event", "page_view", pageEvent);
|
|
397
|
+
break;
|
|
398
|
+
case "track":
|
|
399
|
+
const { properties: trackProperties } = payload;
|
|
400
|
+
const trackEvent = Object.assign(Object.assign({}, trackProperties), ids);
|
|
401
|
+
// @ts-ignore
|
|
402
|
+
gtag("event", payload.event, trackEvent);
|
|
403
|
+
break;
|
|
404
|
+
case "identify":
|
|
405
|
+
const { traits } = payload;
|
|
406
|
+
const identifyEvent = Object.assign(Object.assign({}, traits), ids);
|
|
407
|
+
// @ts-ignore
|
|
408
|
+
gtag("event", "identify", identifyEvent);
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
},
|
|
413
|
+
};
|
|
414
|
+
function getGa4State() {
|
|
415
|
+
return window["__jitsuGa4State"] || "fresh";
|
|
416
|
+
}
|
|
417
|
+
function setGa4State(s) {
|
|
418
|
+
window["__jitsuGa4State"] = s;
|
|
419
|
+
}
|
|
420
|
+
function initGa4IfNeeded(config, payload) {
|
|
421
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
422
|
+
if (getGa4State() !== "fresh") {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
setGa4State("loading");
|
|
426
|
+
const dlName = config.dataLayerName || "dataLayer";
|
|
427
|
+
const dlParam = dlName !== "dataLayer" ? "&l=" + dlName : "";
|
|
428
|
+
// to work with both GA4 and GTM
|
|
429
|
+
const tagId = config.measurementIds;
|
|
430
|
+
const scriptSrc = `${defaultScriptSrc}?id=${tagId}${dlParam}`;
|
|
431
|
+
window[dlName] = window[dlName] || [];
|
|
432
|
+
const gtag = function () {
|
|
433
|
+
window[dlName].push(arguments);
|
|
434
|
+
};
|
|
435
|
+
// @ts-ignore
|
|
436
|
+
gtag("js", new Date());
|
|
437
|
+
gtag(
|
|
438
|
+
// @ts-ignore
|
|
439
|
+
"config", tagId, Object.assign(Object.assign({}, (payload.userId ? { user_id: payload.userId } : {})), (!config.autoPageView ? { send_page_view: false } : {})));
|
|
440
|
+
loadScript(scriptSrc)
|
|
441
|
+
.then(() => {
|
|
442
|
+
setGa4State("loaded");
|
|
443
|
+
})
|
|
444
|
+
.catch(e => {
|
|
445
|
+
console.warn(`GA4 (containerId=${config.measurementIds}) init failed: ${e.message}`, e);
|
|
446
|
+
setGa4State("failed");
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
|
|
377
451
|
function satisfyFilter(filter, subject) {
|
|
378
452
|
return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
|
|
379
453
|
}
|
|
@@ -394,7 +468,7 @@ function applyFilters(event, creds) {
|
|
|
394
468
|
try {
|
|
395
469
|
const eventsArray = Array.isArray(events) ? events : events.split("\n");
|
|
396
470
|
const hostsArray = Array.isArray(hosts) ? hosts : hosts.split("\n");
|
|
397
|
-
return (!!hostsArray.find(hostFilter => { var _a; return satisfyDomainFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
|
|
471
|
+
return (!!hostsArray.find(hostFilter => { var _a, _b; return satisfyDomainFilter(hostFilter, (_b = (_a = event.context) === null || _a === void 0 ? void 0 : _a.page) === null || _b === void 0 ? void 0 : _b.host); }) &&
|
|
398
472
|
(!!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.type)) ||
|
|
399
473
|
!!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.event))));
|
|
400
474
|
}
|
|
@@ -406,6 +480,7 @@ function applyFilters(event, creds) {
|
|
|
406
480
|
const internalDestinationPlugins = {
|
|
407
481
|
[tagPlugin.id]: tagPlugin,
|
|
408
482
|
[gtmPlugin.id]: gtmPlugin,
|
|
483
|
+
[ga4Plugin.id]: ga4Plugin,
|
|
409
484
|
[logrocketPlugin.id]: logrocketPlugin,
|
|
410
485
|
};
|
|
411
486
|
|
|
@@ -499,6 +574,24 @@ function getCookie(name) {
|
|
|
499
574
|
const parts = value.split(`; ${name}=`);
|
|
500
575
|
return parts.length === 2 ? parts.pop().split(";").shift() : undefined;
|
|
501
576
|
}
|
|
577
|
+
function getGa4Sessions() {
|
|
578
|
+
const value = `; ${document.cookie}`;
|
|
579
|
+
const matches = value.matchAll(/_ga_(\w+)=([^;]+)/g);
|
|
580
|
+
const sessions = {};
|
|
581
|
+
let matchesCount = 0;
|
|
582
|
+
for (const match of matches) {
|
|
583
|
+
const parts = match[2].split(".");
|
|
584
|
+
if (parts.length < 3) {
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
sessions[match[1]] = parts[2];
|
|
588
|
+
matchesCount++;
|
|
589
|
+
}
|
|
590
|
+
if (matchesCount === 0) {
|
|
591
|
+
return undefined;
|
|
592
|
+
}
|
|
593
|
+
return sessions;
|
|
594
|
+
}
|
|
502
595
|
function removeCookie(name) {
|
|
503
596
|
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;";
|
|
504
597
|
}
|
|
@@ -649,7 +742,7 @@ function isInBrowser() {
|
|
|
649
742
|
return typeof document !== "undefined" && typeof window !== "undefined";
|
|
650
743
|
}
|
|
651
744
|
function adjustPayload(payload, config, storage) {
|
|
652
|
-
var _a, _b;
|
|
745
|
+
var _a, _b, _c;
|
|
653
746
|
const runtime = config.runtime || (isInBrowser() ? windowRuntime(config) : emptyRuntime(config));
|
|
654
747
|
const url = runtime.pageUrl();
|
|
655
748
|
const parsedUrl = safeCall(() => new URL(url), undefined);
|
|
@@ -680,6 +773,10 @@ function adjustPayload(payload, config, storage) {
|
|
|
680
773
|
clientIds: {
|
|
681
774
|
fbc: getCookie("_fbc"),
|
|
682
775
|
fbp: getCookie("_fbp"),
|
|
776
|
+
ga4: {
|
|
777
|
+
clientId: (_c = getCookie("_ga")) === null || _c === void 0 ? void 0 : _c.split(".").slice(-2).join("."),
|
|
778
|
+
sessions: getGa4Sessions(),
|
|
779
|
+
},
|
|
683
780
|
},
|
|
684
781
|
campaign: parseUtms(query),
|
|
685
782
|
};
|
|
@@ -688,19 +785,25 @@ function adjustPayload(payload, config, storage) {
|
|
|
688
785
|
delete withContext.options;
|
|
689
786
|
return withContext;
|
|
690
787
|
}
|
|
691
|
-
function processDestinations(destinations, method,
|
|
788
|
+
function processDestinations(destinations, method, originalEvent, debug, analyticsInstance) {
|
|
692
789
|
return __awaiter(this, void 0, void 0, function* () {
|
|
693
790
|
const promises = [];
|
|
694
791
|
for (const destination of destinations) {
|
|
792
|
+
let newEvents = [originalEvent];
|
|
793
|
+
if (destination.newEvents) {
|
|
794
|
+
newEvents = destination.newEvents.map(e => (e === "same" ? originalEvent : e));
|
|
795
|
+
}
|
|
695
796
|
const credentials = Object.assign(Object.assign({}, destination.credentials), destination.options);
|
|
696
797
|
if (destination.deviceOptions.type === "internal-plugin") {
|
|
697
798
|
const plugin = internalDestinationPlugins[destination.deviceOptions.name];
|
|
698
799
|
if (plugin) {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
800
|
+
for (const event of newEvents) {
|
|
801
|
+
try {
|
|
802
|
+
promises.push(plugin.handle(credentials, event));
|
|
803
|
+
}
|
|
804
|
+
catch (e) {
|
|
805
|
+
console.warn(`[JITSU] Error processing event with internal plugin '${destination.deviceOptions.name}': ${e === null || e === void 0 ? void 0 : e.message}`, e);
|
|
806
|
+
}
|
|
704
807
|
}
|
|
705
808
|
}
|
|
706
809
|
else {
|
|
@@ -732,11 +835,17 @@ function processDestinations(destinations, method, event, debug, analyticsInstan
|
|
|
732
835
|
continue;
|
|
733
836
|
}
|
|
734
837
|
if (pluginInstance[method]) {
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
838
|
+
for (const event of newEvents) {
|
|
839
|
+
try {
|
|
840
|
+
pluginInstance[method]({
|
|
841
|
+
payload: event,
|
|
842
|
+
config: pluginInstance.config,
|
|
843
|
+
instance: analyticsInstance,
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
catch (e) {
|
|
847
|
+
console.warn(`[JITSU] Error processing ${method}() with plugin '${destination.deviceOptions.moduleVarName}@${destination.deviceOptions.packageCdn}' for destination '${destination.id}': ${e === null || e === void 0 ? void 0 : e.message}`, e);
|
|
848
|
+
}
|
|
740
849
|
}
|
|
741
850
|
}
|
|
742
851
|
}
|
|
@@ -989,6 +1098,7 @@ function jitsuAnalytics(opts) {
|
|
|
989
1098
|
// }
|
|
990
1099
|
}
|
|
991
1100
|
|
|
1101
|
+
exports.applyFilters = applyFilters;
|
|
992
1102
|
exports.emptyAnalytics = emptyAnalytics;
|
|
993
1103
|
exports.emptyRuntime = emptyRuntime;
|
|
994
1104
|
exports.getTopLevelDomain = getTopLevelDomain;
|