@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.
@@ -1,95 +1,105 @@
1
- @jitsu/js:build: cache hit, replaying output adf32738a7660400
2
- @jitsu/js:build: 
3
- @jitsu/js:build: > @jitsu/js@0.0.0 build /Users/vklmn/dev2/newjitsu/libs/jitsu-js
4
- @jitsu/js:build: > tsc -p . && rollup -c && cp compiled/src/*.d.ts dist
5
- @jitsu/js:build: 
6
- @jitsu/js:build: 
7
- @jitsu/js:build: ./compiled/src/browser.js → dist/web/p.js.txt...
8
- @jitsu/js:build: (!) "this" has been rewritten to "undefined"
9
- @jitsu/js:build: https://rollupjs.org/troubleshooting/#error-this-is-undefined
10
- @jitsu/js:build: compiled/src/analytics-plugin.js
11
- @jitsu/js:build: 1: /* global analytics */
12
- @jitsu/js:build: 2: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- @jitsu/js:build:  ^
14
- @jitsu/js:build: 3: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- @jitsu/js:build: 4: return new (P || (P = Promise))(function (resolve, reject) {
16
- @jitsu/js:build: ...and 1 other occurrence
17
- @jitsu/js:build: compiled/src/destination-plugins/gtm.js
18
- @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
19
- @jitsu/js:build:  ^
20
- @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21
- @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
22
- @jitsu/js:build: ...and 1 other occurrence
23
- @jitsu/js:build: compiled/src/destination-plugins/logrocket.js
24
- @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
25
- @jitsu/js:build:  ^
26
- @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
28
- @jitsu/js:build: ...and 1 other occurrence
29
- @jitsu/js:build: compiled/src/destination-plugins/tag.js
30
- @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
31
- @jitsu/js:build:  ^
32
- @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33
- @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
34
- @jitsu/js:build: ...and 1 other occurrence
35
- @jitsu/js:build: (!) Circular dependencies
36
- @jitsu/js:build: compiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
37
- @jitsu/js:build: compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/destination-plugins/index.js
38
- @jitsu/js:build: compiled/src/analytics-plugin.js -> compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/analytics-plugin.js
39
- @jitsu/js:build: compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/logrocket.js -> compiled/src/destination-plugins/index.js
40
- @jitsu/js:build: compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/gtm.js -> compiled/src/destination-plugins/index.js
41
- @jitsu/js:build: (!) Use of eval is strongly discouraged
42
- @jitsu/js:build: https://rollupjs.org/troubleshooting/#avoiding-eval
43
- @jitsu/js:build: compiled/src/destination-plugins/tag.js
44
- @jitsu/js:build: 68: })()`;
45
- @jitsu/js:build: 69: try {
46
- @jitsu/js:build: 70: eval(iif);
47
- @jitsu/js:build:  ^
48
- @jitsu/js:build: 71: }
49
- @jitsu/js:build: 72: catch (e) {
50
- @jitsu/js:build: created dist/web/p.js.txt in 420ms
51
- @jitsu/js:build: 
52
- @jitsu/js:build: ./compiled/src/index.js, ./compiled/src/jitsu.js, ./compiled/src/analytics-plugin.js → dist/jitsu.es.js, dist/jitsu.cjs.js...
53
- @jitsu/js:build: (!) "this" has been rewritten to "undefined"
54
- @jitsu/js:build: https://rollupjs.org/troubleshooting/#error-this-is-undefined
55
- @jitsu/js:build: compiled/src/analytics-plugin.js
56
- @jitsu/js:build: 1: /* global analytics */
57
- @jitsu/js:build: 2: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
58
- @jitsu/js:build:  ^
59
- @jitsu/js:build: 3: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
60
- @jitsu/js:build: 4: return new (P || (P = Promise))(function (resolve, reject) {
61
- @jitsu/js:build: ...and 1 other occurrence
62
- @jitsu/js:build: compiled/src/destination-plugins/tag.js
63
- @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
64
- @jitsu/js:build:  ^
65
- @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
66
- @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
67
- @jitsu/js:build: ...and 1 other occurrence
68
- @jitsu/js:build: compiled/src/destination-plugins/logrocket.js
69
- @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
70
- @jitsu/js:build:  ^
71
- @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
72
- @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
73
- @jitsu/js:build: ...and 1 other occurrence
74
- @jitsu/js:build: compiled/src/destination-plugins/gtm.js
75
- @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
76
- @jitsu/js:build:  ^
77
- @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
78
- @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
79
- @jitsu/js:build: ...and 1 other occurrence
80
- @jitsu/js:build: (!) Circular dependencies
81
- @jitsu/js:build: compiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
82
- @jitsu/js:build: compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/destination-plugins/index.js
83
- @jitsu/js:build: compiled/src/analytics-plugin.js -> compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/analytics-plugin.js
84
- @jitsu/js:build: compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/logrocket.js -> compiled/src/destination-plugins/index.js
85
- @jitsu/js:build: compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/gtm.js -> compiled/src/destination-plugins/index.js
86
- @jitsu/js:build: (!) Use of eval is strongly discouraged
87
- @jitsu/js:build: https://rollupjs.org/troubleshooting/#avoiding-eval
88
- @jitsu/js:build: compiled/src/destination-plugins/tag.js
89
- @jitsu/js:build: 68: })()`;
90
- @jitsu/js:build: 69: try {
91
- @jitsu/js:build: 70: eval(iif);
92
- @jitsu/js:build:  ^
93
- @jitsu/js:build: 71: }
94
- @jitsu/js:build: 72: catch (e) {
95
- @jitsu/js:build: created dist/jitsu.es.js, dist/jitsu.cjs.js in 129ms
1
+ @jitsu/js:build: cache hit, replaying output c3f20c137ae4b178
2
+ @jitsu/js:build: 
3
+ @jitsu/js:build: > @jitsu/js@0.0.0 build /Users/vklmn/dev2/newjitsu/libs/jitsu-js
4
+ @jitsu/js:build: > tsc -p . && rollup -c && cp compiled/src/*.d.ts dist
5
+ @jitsu/js:build: 
6
+ @jitsu/js:build: 
7
+ @jitsu/js:build: ./compiled/src/browser.js → dist/web/p.js.txt...
8
+ @jitsu/js:build: (!) "this" has been rewritten to "undefined"
9
+ @jitsu/js:build: https://rollupjs.org/troubleshooting/#error-this-is-undefined
10
+ @jitsu/js:build: compiled/src/analytics-plugin.js
11
+ @jitsu/js:build: 1: /* global analytics */
12
+ @jitsu/js:build: 2: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ @jitsu/js:build:  ^
14
+ @jitsu/js:build: 3: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ @jitsu/js:build: 4: return new (P || (P = Promise))(function (resolve, reject) {
16
+ @jitsu/js:build: ...and 1 other occurrence
17
+ @jitsu/js:build: compiled/src/destination-plugins/logrocket.js
18
+ @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
19
+ @jitsu/js:build:  ^
20
+ @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21
+ @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
22
+ @jitsu/js:build: ...and 1 other occurrence
23
+ @jitsu/js:build: compiled/src/destination-plugins/tag.js
24
+ @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
25
+ @jitsu/js:build:  ^
26
+ @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
28
+ @jitsu/js:build: ...and 1 other occurrence
29
+ @jitsu/js:build: compiled/src/destination-plugins/ga4.js
30
+ @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
31
+ @jitsu/js:build:  ^
32
+ @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33
+ @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
34
+ @jitsu/js:build: ...and 1 other occurrence
35
+ @jitsu/js:build: compiled/src/destination-plugins/gtm.js
36
+ @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ @jitsu/js:build:  ^
38
+ @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
39
+ @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
40
+ @jitsu/js:build: ...and 1 other occurrence
41
+ @jitsu/js:build: (!) Circular dependencies
42
+ @jitsu/js:build: compiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
43
+ @jitsu/js:build: compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/destination-plugins/index.js
44
+ @jitsu/js:build: compiled/src/analytics-plugin.js -> compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/analytics-plugin.js
45
+ @jitsu/js:build: ...and 3 more
46
+ @jitsu/js:build: (!) Use of eval is strongly discouraged
47
+ @jitsu/js:build: https://rollupjs.org/troubleshooting/#avoiding-eval
48
+ @jitsu/js:build: compiled/src/destination-plugins/tag.js
49
+ @jitsu/js:build: 68: })()`;
50
+ @jitsu/js:build: 69: try {
51
+ @jitsu/js:build: 70: eval(iif);
52
+ @jitsu/js:build:  ^
53
+ @jitsu/js:build: 71: }
54
+ @jitsu/js:build: 72: catch (e) {
55
+ @jitsu/js:build: created dist/web/p.js.txt in 434ms
56
+ @jitsu/js:build: 
57
+ @jitsu/js:build: ./compiled/src/index.js, ./compiled/src/jitsu.js, ./compiled/src/analytics-plugin.js dist/jitsu.es.js, dist/jitsu.cjs.js...
58
+ @jitsu/js:build: (!) "this" has been rewritten to "undefined"
59
+ @jitsu/js:build: https://rollupjs.org/troubleshooting/#error-this-is-undefined
60
+ @jitsu/js:build: compiled/src/analytics-plugin.js
61
+ @jitsu/js:build: 1: /* global analytics */
62
+ @jitsu/js:build: 2: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
63
+ @jitsu/js:build:  ^
64
+ @jitsu/js:build: 3: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
65
+ @jitsu/js:build: 4: return new (P || (P = Promise))(function (resolve, reject) {
66
+ @jitsu/js:build: ...and 1 other occurrence
67
+ @jitsu/js:build: compiled/src/destination-plugins/gtm.js
68
+ @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
69
+ @jitsu/js:build:  ^
70
+ @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
71
+ @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
72
+ @jitsu/js:build: ...and 1 other occurrence
73
+ @jitsu/js:build: compiled/src/destination-plugins/ga4.js
74
+ @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
75
+ @jitsu/js:build:  ^
76
+ @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
77
+ @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
78
+ @jitsu/js:build: ...and 1 other occurrence
79
+ @jitsu/js:build: compiled/src/destination-plugins/tag.js
80
+ @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
81
+ @jitsu/js:build:  ^
82
+ @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
83
+ @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
84
+ @jitsu/js:build: ...and 1 other occurrence
85
+ @jitsu/js:build: compiled/src/destination-plugins/logrocket.js
86
+ @jitsu/js:build: 1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
87
+ @jitsu/js:build:  ^
88
+ @jitsu/js:build: 2: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
89
+ @jitsu/js:build: 3: return new (P || (P = Promise))(function (resolve, reject) {
90
+ @jitsu/js:build: ...and 1 other occurrence
91
+ @jitsu/js:build: (!) Circular dependencies
92
+ @jitsu/js:build: compiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
93
+ @jitsu/js:build: compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/destination-plugins/index.js
94
+ @jitsu/js:build: compiled/src/analytics-plugin.js -> compiled/src/destination-plugins/index.js -> compiled/src/destination-plugins/tag.js -> compiled/src/analytics-plugin.js
95
+ @jitsu/js:build: ...and 3 more
96
+ @jitsu/js:build: (!) Use of eval is strongly discouraged
97
+ @jitsu/js:build: https://rollupjs.org/troubleshooting/#avoiding-eval
98
+ @jitsu/js:build: compiled/src/destination-plugins/tag.js
99
+ @jitsu/js:build: 68: })()`;
100
+ @jitsu/js:build: 69: try {
101
+ @jitsu/js:build: 70: eval(iif);
102
+ @jitsu/js:build:  ^
103
+ @jitsu/js:build: 71: }
104
+ @jitsu/js:build: 72: catch (e) {
105
+ @jitsu/js:build: created dist/jitsu.es.js, dist/jitsu.cjs.js in 126ms
@@ -1,5 +1,5 @@
1
- @jitsu/js:clean: cache hit, replaying output cfefea15f0f744c5
2
- @jitsu/js:clean: 
3
- @jitsu/js:clean: > @jitsu/js@0.0.0 clean /Users/vklmn/dev2/newjitsu/libs/jitsu-js
4
- @jitsu/js:clean: > rm -rf ./dist
5
- @jitsu/js:clean: 
1
+ @jitsu/js:clean: cache hit, replaying output 01f8d33de867ec80
2
+ @jitsu/js:clean: 
3
+ @jitsu/js:clean: > @jitsu/js@0.0.0 clean /Users/vklmn/dev2/newjitsu/libs/jitsu-js
4
+ @jitsu/js:clean: > rm -rf ./dist
5
+ @jitsu/js:clean: 
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ ## Install
2
+
3
+ ```bash
4
+ npm install --save @jitsu/jitsu-react
5
+ ```
6
+
7
+ ## Usage
8
+
9
+ **Please read a documentation on [Jitsu Docs](https://docs.jitsu.com/sending-data/npm)**
@@ -10,6 +10,7 @@ export type DestinationDescriptor = {
10
10
  destinationType: string;
11
11
  credentials: any;
12
12
  options: any;
13
+ newEvents?: any[];
13
14
  deviceOptions: DeviceOptions;
14
15
  };
15
16
  export type AnalyticsPluginDescriptor = {
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$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
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$3(this, void 0, void 0, function* () {
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$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
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$2(this, void 0, void 0, function* () {
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$2(this, void 0, void 0, function* () {
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$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
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$1(this, void 0, void 0, function* () {
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$1(this, void 0, void 0, function* () {
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
  ? `&gtm_preview=${config.preview}&gtm_auth=${config.auth}&gtm_cookies_win=x`
356
334
  : "";
357
- const scriptSrc = `${config.customScriptSrc || defaultScriptSrc}?id=${config.containerId}${dlParam}${previewParams}`;
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", config.containerId);
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=${config.containerId}) init failed: ${e.message}`, e);
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, event, debug, analyticsInstance) {
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
- try {
700
- promises.push(plugin.handle(credentials, event));
701
- }
702
- catch (e) {
703
- console.warn(`[JITSU] Error processing event with internal plugin '${destination.deviceOptions.name}': ${e === null || e === void 0 ? void 0 : e.message}`, e);
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
- try {
736
- pluginInstance[method]({ payload: event, config: pluginInstance.config, instance: analyticsInstance });
737
- }
738
- catch (e) {
739
- 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);
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;