@jitsu/js 1.1.0-canary.388.20230519133920 → 1.1.0-canary.391.20230523080206

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,95 @@
1
- @jitsu/js:build: cache hit, replaying output 9d604bcd7bdc50ac
2
- @jitsu/js:build: 
3
- @jitsu/js:build: > @jitsu/js@0.0.0 build /Users/ildarnurislamov/Projects/onetag/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/gtm.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 216ms
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/gtm.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/tag.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 151ms
1
+ @jitsu/js:build: cache hit, replaying output 70799201810b0c5a
2
+ @jitsu/js:build: 
3
+ @jitsu/js:build: > @jitsu/js@0.0.0 build /Users/ildarnurislamov/Projects/onetag/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/tag.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/gtm.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/logrocket.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 512ms
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 353ms
@@ -1,5 +1,5 @@
1
- @jitsu/js:clean: cache hit, replaying output 6f082eb620c44280
2
- @jitsu/js:clean: 
3
- @jitsu/js:clean: > @jitsu/js@0.0.0 clean /Users/ildarnurislamov/Projects/onetag/libs/jitsu-js
4
- @jitsu/js:clean: > rm -rf ./dist
5
- @jitsu/js:clean: 
1
+ @jitsu/js:clean: cache hit, replaying output 96c25c4b05e1319b
2
+ @jitsu/js:clean: 
3
+ @jitsu/js:clean: > @jitsu/js@0.0.0 clean /Users/ildarnurislamov/Projects/onetag/libs/jitsu-js
4
+ @jitsu/js:clean: > rm -rf ./dist
5
+ @jitsu/js:clean: 
@@ -10,6 +10,7 @@ export type DestinationDescriptor = {
10
10
  id: string;
11
11
  destinationType: string;
12
12
  credentials: any;
13
+ options: any;
13
14
  deviceOptions: DeviceOptions;
14
15
  };
15
16
  export type AnalyticsPluginDescriptor = {
package/dist/jitsu.cjs.js CHANGED
@@ -284,6 +284,7 @@ const defaultScriptSrc = "https://www.googletagmanager.com/gtag/js";
284
284
  const gtmPlugin = {
285
285
  id: "gtm",
286
286
  handle(config, payload) {
287
+ var _a, _b;
287
288
  return __awaiter$1(this, void 0, void 0, function* () {
288
289
  if (!applyFilters(payload, config)) {
289
290
  return;
@@ -292,8 +293,13 @@ const gtmPlugin = {
292
293
  const dataLayer = window[config.dataLayerName || "dataLayer"];
293
294
  switch (payload.type) {
294
295
  case "page":
295
- const { properties: pageProperties } = payload;
296
- const pageEvent = Object.assign({ event: "page_view" }, pageProperties);
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
+ };
297
303
  if (config.debug) {
298
304
  console.log("gtag push", pageEvent);
299
305
  }
@@ -302,21 +308,26 @@ const gtmPlugin = {
302
308
  case "track":
303
309
  const { properties: trackProperties } = payload;
304
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
+ }
305
317
  if (config.debug) {
306
318
  console.log("gtag push", trackEvent);
307
319
  }
308
320
  dataLayer.push(trackEvent);
309
321
  break;
310
322
  case "identify":
311
- const { anonymousId, userId, traits } = payload;
312
- const user = traits;
313
- if (userId) {
314
- user.userId = userId;
323
+ const { traits } = payload;
324
+ const identifyEvent = Object.assign({ event: "identify" }, traits);
325
+ if (payload.userId) {
326
+ identifyEvent.userId = payload.userId;
315
327
  }
316
- if (anonymousId) {
317
- user.anonymousId = anonymousId;
328
+ if (payload.anonymousId) {
329
+ identifyEvent.anonymousId = payload.anonymousId;
318
330
  }
319
- const identifyEvent = { event: "identify", user: user };
320
331
  if (config.debug) {
321
332
  console.log("gtag push", identifyEvent);
322
333
  }
@@ -367,9 +378,11 @@ function satisfyFilter(filter, subject) {
367
378
  return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
368
379
  }
369
380
  function applyFilters(event, creds) {
370
- const { hosts = ["*"], events = ["*"] } = creds;
371
- return (!!hosts.find(hostFilter => { var _a; return satisfyFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
372
- !!events.find(eventFilter => satisfyFilter(eventFilter, event.type)));
381
+ const { hosts = "*", events = "*" } = creds;
382
+ const eventsArray = events.split("\n");
383
+ return (!!hosts.split("\n").find(hostFilter => { var _a; return satisfyFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
384
+ (!!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.type)) ||
385
+ !!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.event))));
373
386
  }
374
387
  const internalDestinationPlugins = {
375
388
  [tagPlugin.id]: tagPlugin,
@@ -642,12 +655,12 @@ function processDestinations(destinations, method, event, debug, analyticsInstan
642
655
  return __awaiter(this, void 0, void 0, function* () {
643
656
  const promises = [];
644
657
  for (const destination of destinations) {
658
+ const credentials = Object.assign(Object.assign({}, destination.credentials), destination.options);
645
659
  if (destination.deviceOptions.type === "internal-plugin") {
646
660
  const plugin = internalDestinationPlugins[destination.deviceOptions.name];
647
661
  if (plugin) {
648
662
  try {
649
663
  //to support old versions, where credentials were stored in root
650
- const credentials = destination.credentials || destination;
651
664
  promises.push(plugin.handle(credentials, event));
652
665
  }
653
666
  catch (e) {
@@ -667,7 +680,7 @@ function processDestinations(destinations, method, event, debug, analyticsInstan
667
680
  else {
668
681
  let pluginInstance;
669
682
  try {
670
- pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(destination.credentials);
683
+ pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(credentials);
671
684
  }
672
685
  catch (e) {
673
686
  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);
package/dist/jitsu.es.js CHANGED
@@ -282,6 +282,7 @@ const defaultScriptSrc = "https://www.googletagmanager.com/gtag/js";
282
282
  const gtmPlugin = {
283
283
  id: "gtm",
284
284
  handle(config, payload) {
285
+ var _a, _b;
285
286
  return __awaiter$1(this, void 0, void 0, function* () {
286
287
  if (!applyFilters(payload, config)) {
287
288
  return;
@@ -290,8 +291,13 @@ const gtmPlugin = {
290
291
  const dataLayer = window[config.dataLayerName || "dataLayer"];
291
292
  switch (payload.type) {
292
293
  case "page":
293
- const { properties: pageProperties } = payload;
294
- const pageEvent = Object.assign({ event: "page_view" }, pageProperties);
294
+ const { properties: pageProperties, context } = payload;
295
+ const pageEvent = {
296
+ event: "page_view",
297
+ url: pageProperties.url,
298
+ title: pageProperties.title,
299
+ 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 : "",
300
+ };
295
301
  if (config.debug) {
296
302
  console.log("gtag push", pageEvent);
297
303
  }
@@ -300,21 +306,26 @@ const gtmPlugin = {
300
306
  case "track":
301
307
  const { properties: trackProperties } = payload;
302
308
  const trackEvent = Object.assign({ event: payload.event }, trackProperties);
309
+ if (payload.userId) {
310
+ trackEvent.userId = payload.userId;
311
+ }
312
+ if (payload.anonymousId) {
313
+ trackEvent.anonymousId = payload.anonymousId;
314
+ }
303
315
  if (config.debug) {
304
316
  console.log("gtag push", trackEvent);
305
317
  }
306
318
  dataLayer.push(trackEvent);
307
319
  break;
308
320
  case "identify":
309
- const { anonymousId, userId, traits } = payload;
310
- const user = traits;
311
- if (userId) {
312
- user.userId = userId;
321
+ const { traits } = payload;
322
+ const identifyEvent = Object.assign({ event: "identify" }, traits);
323
+ if (payload.userId) {
324
+ identifyEvent.userId = payload.userId;
313
325
  }
314
- if (anonymousId) {
315
- user.anonymousId = anonymousId;
326
+ if (payload.anonymousId) {
327
+ identifyEvent.anonymousId = payload.anonymousId;
316
328
  }
317
- const identifyEvent = { event: "identify", user: user };
318
329
  if (config.debug) {
319
330
  console.log("gtag push", identifyEvent);
320
331
  }
@@ -365,9 +376,11 @@ function satisfyFilter(filter, subject) {
365
376
  return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
366
377
  }
367
378
  function applyFilters(event, creds) {
368
- const { hosts = ["*"], events = ["*"] } = creds;
369
- return (!!hosts.find(hostFilter => { var _a; return satisfyFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
370
- !!events.find(eventFilter => satisfyFilter(eventFilter, event.type)));
379
+ const { hosts = "*", events = "*" } = creds;
380
+ const eventsArray = events.split("\n");
381
+ return (!!hosts.split("\n").find(hostFilter => { var _a; return satisfyFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
382
+ (!!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.type)) ||
383
+ !!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.event))));
371
384
  }
372
385
  const internalDestinationPlugins = {
373
386
  [tagPlugin.id]: tagPlugin,
@@ -640,12 +653,12 @@ function processDestinations(destinations, method, event, debug, analyticsInstan
640
653
  return __awaiter(this, void 0, void 0, function* () {
641
654
  const promises = [];
642
655
  for (const destination of destinations) {
656
+ const credentials = Object.assign(Object.assign({}, destination.credentials), destination.options);
643
657
  if (destination.deviceOptions.type === "internal-plugin") {
644
658
  const plugin = internalDestinationPlugins[destination.deviceOptions.name];
645
659
  if (plugin) {
646
660
  try {
647
661
  //to support old versions, where credentials were stored in root
648
- const credentials = destination.credentials || destination;
649
662
  promises.push(plugin.handle(credentials, event));
650
663
  }
651
664
  catch (e) {
@@ -665,7 +678,7 @@ function processDestinations(destinations, method, event, debug, analyticsInstan
665
678
  else {
666
679
  let pluginInstance;
667
680
  try {
668
- pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(destination.credentials);
681
+ pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(credentials);
669
682
  }
670
683
  catch (e) {
671
684
  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);
package/dist/web/p.js.txt CHANGED
@@ -285,6 +285,7 @@
285
285
  const gtmPlugin = {
286
286
  id: "gtm",
287
287
  handle(config, payload) {
288
+ var _a, _b;
288
289
  return __awaiter$1(this, void 0, void 0, function* () {
289
290
  if (!applyFilters(payload, config)) {
290
291
  return;
@@ -293,8 +294,13 @@
293
294
  const dataLayer = window[config.dataLayerName || "dataLayer"];
294
295
  switch (payload.type) {
295
296
  case "page":
296
- const { properties: pageProperties } = payload;
297
- const pageEvent = Object.assign({ event: "page_view" }, pageProperties);
297
+ const { properties: pageProperties, context } = payload;
298
+ const pageEvent = {
299
+ event: "page_view",
300
+ url: pageProperties.url,
301
+ title: pageProperties.title,
302
+ 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 : "",
303
+ };
298
304
  if (config.debug) {
299
305
  console.log("gtag push", pageEvent);
300
306
  }
@@ -303,21 +309,26 @@
303
309
  case "track":
304
310
  const { properties: trackProperties } = payload;
305
311
  const trackEvent = Object.assign({ event: payload.event }, trackProperties);
312
+ if (payload.userId) {
313
+ trackEvent.userId = payload.userId;
314
+ }
315
+ if (payload.anonymousId) {
316
+ trackEvent.anonymousId = payload.anonymousId;
317
+ }
306
318
  if (config.debug) {
307
319
  console.log("gtag push", trackEvent);
308
320
  }
309
321
  dataLayer.push(trackEvent);
310
322
  break;
311
323
  case "identify":
312
- const { anonymousId, userId, traits } = payload;
313
- const user = traits;
314
- if (userId) {
315
- user.userId = userId;
324
+ const { traits } = payload;
325
+ const identifyEvent = Object.assign({ event: "identify" }, traits);
326
+ if (payload.userId) {
327
+ identifyEvent.userId = payload.userId;
316
328
  }
317
- if (anonymousId) {
318
- user.anonymousId = anonymousId;
329
+ if (payload.anonymousId) {
330
+ identifyEvent.anonymousId = payload.anonymousId;
319
331
  }
320
- const identifyEvent = { event: "identify", user: user };
321
332
  if (config.debug) {
322
333
  console.log("gtag push", identifyEvent);
323
334
  }
@@ -368,9 +379,11 @@
368
379
  return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
369
380
  }
370
381
  function applyFilters(event, creds) {
371
- const { hosts = ["*"], events = ["*"] } = creds;
372
- return (!!hosts.find(hostFilter => { var _a; return satisfyFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
373
- !!events.find(eventFilter => satisfyFilter(eventFilter, event.type)));
382
+ const { hosts = "*", events = "*" } = creds;
383
+ const eventsArray = events.split("\n");
384
+ return (!!hosts.split("\n").find(hostFilter => { var _a; return satisfyFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
385
+ (!!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.type)) ||
386
+ !!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.event))));
374
387
  }
375
388
  const internalDestinationPlugins = {
376
389
  [tagPlugin.id]: tagPlugin,
@@ -643,12 +656,12 @@
643
656
  return __awaiter(this, void 0, void 0, function* () {
644
657
  const promises = [];
645
658
  for (const destination of destinations) {
659
+ const credentials = Object.assign(Object.assign({}, destination.credentials), destination.options);
646
660
  if (destination.deviceOptions.type === "internal-plugin") {
647
661
  const plugin = internalDestinationPlugins[destination.deviceOptions.name];
648
662
  if (plugin) {
649
663
  try {
650
664
  //to support old versions, where credentials were stored in root
651
- const credentials = destination.credentials || destination;
652
665
  promises.push(plugin.handle(credentials, event));
653
666
  }
654
667
  catch (e) {
@@ -668,7 +681,7 @@
668
681
  else {
669
682
  let pluginInstance;
670
683
  try {
671
- pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(destination.credentials);
684
+ pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(credentials);
672
685
  }
673
686
  catch (e) {
674
687
  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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsu/js",
3
- "version": "1.1.0-canary.388.20230519133920",
3
+ "version": "1.1.0-canary.391.20230523080206",
4
4
  "description": "",
5
5
  "author": "Jitsu Dev Team <dev@jitsu.com>",
6
6
  "main": "dist/jitsu.cjs.js",
@@ -34,7 +34,7 @@
34
34
  "rollup": "^3.2.5",
35
35
  "ts-jest": "29.0.5",
36
36
  "typescript": "^4.9.5",
37
- "@jitsu/protocols": "1.1.0-canary.388.20230519133920"
37
+ "@jitsu/protocols": "1.1.0-canary.391.20230523080206"
38
38
  },
39
39
  "dependencies": {
40
40
  "analytics": "^0.8.1"
@@ -293,6 +293,7 @@ export type DestinationDescriptor = {
293
293
  id: string;
294
294
  destinationType: string;
295
295
  credentials: any;
296
+ options: any;
296
297
  deviceOptions: DeviceOptions;
297
298
  };
298
299
  export type AnalyticsPluginDescriptor = {
@@ -317,12 +318,12 @@ async function processDestinations(
317
318
  ) {
318
319
  const promises: Promise<any>[] = [];
319
320
  for (const destination of destinations) {
321
+ const credentials = { ...destination.credentials, ...destination.options };
322
+
320
323
  if (destination.deviceOptions.type === "internal-plugin") {
321
324
  const plugin = internalDestinationPlugins[destination.deviceOptions.name];
322
325
  if (plugin) {
323
326
  try {
324
- //to support old versions, where credentials were stored in root
325
- const credentials = destination.credentials || destination;
326
327
  promises.push(plugin.handle(credentials, event));
327
328
  } catch (e) {
328
329
  console.warn(
@@ -345,7 +346,7 @@ async function processDestinations(
345
346
  } else {
346
347
  let pluginInstance: any;
347
348
  try {
348
- pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(destination.credentials);
349
+ pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(credentials);
349
350
  } catch (e) {
350
351
  console.warn(
351
352
  `[JITSU] Error creating plugin '${destination.deviceOptions.moduleVarName}@${destination.deviceOptions.packageCdn}' for destination '${destination.id}': ${e?.message}`,
@@ -25,8 +25,13 @@ export const gtmPlugin: InternalPlugin<GtmDestinationCredentials> = {
25
25
 
26
26
  switch (payload.type) {
27
27
  case "page":
28
- const { properties: pageProperties } = payload;
29
- const pageEvent = { event: "page_view", ...pageProperties };
28
+ const { properties: pageProperties, context } = payload;
29
+ const pageEvent = {
30
+ event: "page_view",
31
+ url: pageProperties.url,
32
+ title: pageProperties.title,
33
+ referer: context?.page?.referrer ?? "",
34
+ };
30
35
  if (config.debug) {
31
36
  console.log("gtag push", pageEvent);
32
37
  }
@@ -34,22 +39,27 @@ export const gtmPlugin: InternalPlugin<GtmDestinationCredentials> = {
34
39
  break;
35
40
  case "track":
36
41
  const { properties: trackProperties } = payload;
37
- const trackEvent = { event: payload.event, ...trackProperties };
42
+ const trackEvent: any = { event: payload.event, ...trackProperties };
43
+ if (payload.userId) {
44
+ trackEvent.userId = payload.userId;
45
+ }
46
+ if (payload.anonymousId) {
47
+ trackEvent.anonymousId = payload.anonymousId;
48
+ }
38
49
  if (config.debug) {
39
50
  console.log("gtag push", trackEvent);
40
51
  }
41
52
  dataLayer.push(trackEvent);
42
53
  break;
43
54
  case "identify":
44
- const { anonymousId, userId, traits } = payload;
45
- const user = traits;
46
- if (userId) {
47
- user.userId = userId;
55
+ const { traits } = payload;
56
+ const identifyEvent: any = { event: "identify", ...traits };
57
+ if (payload.userId) {
58
+ identifyEvent.userId = payload.userId;
48
59
  }
49
- if (anonymousId) {
50
- user.anonymousId = anonymousId;
60
+ if (payload.anonymousId) {
61
+ identifyEvent.anonymousId = payload.anonymousId;
51
62
  }
52
- const identifyEvent = { event: "identify", user: user };
53
63
  if (config.debug) {
54
64
  console.log("gtag push", identifyEvent);
55
65
  }
@@ -9,8 +9,8 @@ export type InternalPlugin<T> = {
9
9
  };
10
10
 
11
11
  export type CommonDestinationCredentials = {
12
- hosts?: string[];
13
- events?: string[];
12
+ hosts?: string;
13
+ events?: string;
14
14
  };
15
15
 
16
16
  export function satisfyFilter(filter: string, subject: string | undefined): boolean {
@@ -18,10 +18,12 @@ export function satisfyFilter(filter: string, subject: string | undefined): bool
18
18
  }
19
19
 
20
20
  export function applyFilters(event: AnalyticsClientEvent, creds: CommonDestinationCredentials): boolean {
21
- const { hosts = ["*"], events = ["*"] } = creds;
21
+ const { hosts = "*", events = "*" } = creds;
22
+ const eventsArray = events.split("\n");
22
23
  return (
23
- !!hosts.find(hostFilter => satisfyFilter(hostFilter, event.context?.host)) &&
24
- !!events.find(eventFilter => satisfyFilter(eventFilter, event.type))
24
+ !!hosts.split("\n").find(hostFilter => satisfyFilter(hostFilter, event.context?.host)) &&
25
+ (!!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.type)) ||
26
+ !!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.event)))
25
27
  );
26
28
  }
27
29