@uniformdev/context-gtag 17.7.1-alpha.140 → 17.7.1-alpha.169

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/dist/index.esm.js CHANGED
@@ -1 +1,65 @@
1
- var f=g=>{let{disableEventSignals:_,theWindow:e=typeof window!="undefined"?window:void 0,emitAll:l}=g||{},i=()=>typeof e!="undefined"&&typeof e.gtag=="function";return{init:o=>{let r=n=>{var t;if(!i()){o.log("warn",700);return}!l&&!n.changed||(t=e.gtag)==null||t.call(e,"event",n.name,{event_category:"Uniform Personalization",event_label:n.variantIds.join(", "),is_control_group:n.control?1:0})},s=n=>{var t,a;if(!i()){o.log("warn",700);return}!l&&!n.variantAssigned||(a=e.gtag)==null||a.call(e,"event",n.name,{event_category:"Uniform AB Testing",event_label:(t=n.variantId)!=null?t:"No Variant"})};if(o.events.on("personalizationResult",r),o.events.on("testResult",s),!_&&i()&&!(e!=null&&e.__UF_PATCHED_GTAG__)){let n=e.gtag;e.gtag=(...t)=>{var a;n(...t),t[0]==="event"&&!["Uniform AB Testing","Uniform Personalization"].includes((a=t[2])==null?void 0:a.event_category)&&o.update({events:[{event:t[1]}]})},o.log("debug",701),e.__UF_PATCHED_GTAG__=!0}return()=>{o.events.off("personalizationResult",r),o.events.off("testResult",s)}}}};export{f as enableGoogleGtagAnalytics};
1
+ // src/index.ts
2
+ var enableGoogleGtagAnalytics = (options) => {
3
+ const {
4
+ disableEventSignals,
5
+ theWindow = typeof window !== "undefined" ? window : void 0,
6
+ emitAll
7
+ } = options || {};
8
+ const isGtagConfigured = () => {
9
+ return typeof theWindow !== "undefined" && typeof theWindow.gtag === "function";
10
+ };
11
+ return {
12
+ init: (context) => {
13
+ const onPersonalizationResult = (result) => {
14
+ var _a;
15
+ if (!isGtagConfigured()) {
16
+ context.log("warn", 700);
17
+ return;
18
+ }
19
+ if (!emitAll && !result.changed) {
20
+ return;
21
+ }
22
+ (_a = theWindow.gtag) == null ? void 0 : _a.call(theWindow, "event", result.name, {
23
+ event_category: "Uniform Personalization",
24
+ event_label: result.variantIds.join(", "),
25
+ is_control_group: result.control ? 1 : 0
26
+ });
27
+ };
28
+ const onTestResult = (result) => {
29
+ var _a, _b;
30
+ if (!isGtagConfigured()) {
31
+ context.log("warn", 700);
32
+ return;
33
+ }
34
+ if (!emitAll && !result.variantAssigned) {
35
+ return;
36
+ }
37
+ (_b = theWindow.gtag) == null ? void 0 : _b.call(theWindow, "event", result.name, {
38
+ event_category: "Uniform AB Testing",
39
+ event_label: (_a = result.variantId) != null ? _a : "No Variant"
40
+ });
41
+ };
42
+ context.events.on("personalizationResult", onPersonalizationResult);
43
+ context.events.on("testResult", onTestResult);
44
+ if (!disableEventSignals && isGtagConfigured() && !(theWindow == null ? void 0 : theWindow.__UF_PATCHED_GTAG__)) {
45
+ const defaultGtag = theWindow.gtag;
46
+ theWindow.gtag = (...args) => {
47
+ var _a;
48
+ defaultGtag(...args);
49
+ if (args[0] === "event" && !["Uniform AB Testing", "Uniform Personalization"].includes((_a = args[2]) == null ? void 0 : _a.event_category)) {
50
+ context.update({ events: [{ event: args[1] }] });
51
+ }
52
+ };
53
+ context.log("debug", 701);
54
+ theWindow.__UF_PATCHED_GTAG__ = true;
55
+ }
56
+ return () => {
57
+ context.events.off("personalizationResult", onPersonalizationResult);
58
+ context.events.off("testResult", onTestResult);
59
+ };
60
+ }
61
+ };
62
+ };
63
+ export {
64
+ enableGoogleGtagAnalytics
65
+ };
package/dist/index.js CHANGED
@@ -1 +1,90 @@
1
- "use strict";var g=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var A=(a,n)=>{for(var e in n)g(a,e,{get:n[e],enumerable:!0})},G=(a,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of u(n))!d.call(a,i)&&i!==e&&g(a,i,{get:()=>n[i],enumerable:!(r=v(n,i))||r.enumerable});return a};var T=a=>G(g({},"__esModule",{value:!0}),a);var P={};A(P,{enableGoogleGtagAnalytics:()=>b});module.exports=T(P);var b=a=>{let{disableEventSignals:n,theWindow:e=typeof window!="undefined"?window:void 0,emitAll:r}=a||{},i=()=>typeof e!="undefined"&&typeof e.gtag=="function";return{init:l=>{let _=t=>{var o;if(!i()){l.log("warn",700);return}!r&&!t.changed||(o=e.gtag)==null||o.call(e,"event",t.name,{event_category:"Uniform Personalization",event_label:t.variantIds.join(", "),is_control_group:t.control?1:0})},f=t=>{var o,s;if(!i()){l.log("warn",700);return}!r&&!t.variantAssigned||(s=e.gtag)==null||s.call(e,"event",t.name,{event_category:"Uniform AB Testing",event_label:(o=t.variantId)!=null?o:"No Variant"})};if(l.events.on("personalizationResult",_),l.events.on("testResult",f),!n&&i()&&!(e!=null&&e.__UF_PATCHED_GTAG__)){let t=e.gtag;e.gtag=(...o)=>{var s;t(...o),o[0]==="event"&&!["Uniform AB Testing","Uniform Personalization"].includes((s=o[2])==null?void 0:s.event_category)&&l.update({events:[{event:o[1]}]})},l.log("debug",701),e.__UF_PATCHED_GTAG__=!0}return()=>{l.events.off("personalizationResult",_),l.events.off("testResult",f)}}}};0&&(module.exports={enableGoogleGtagAnalytics});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ enableGoogleGtagAnalytics: () => enableGoogleGtagAnalytics
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ var enableGoogleGtagAnalytics = (options) => {
27
+ const {
28
+ disableEventSignals,
29
+ theWindow = typeof window !== "undefined" ? window : void 0,
30
+ emitAll
31
+ } = options || {};
32
+ const isGtagConfigured = () => {
33
+ return typeof theWindow !== "undefined" && typeof theWindow.gtag === "function";
34
+ };
35
+ return {
36
+ init: (context) => {
37
+ const onPersonalizationResult = (result) => {
38
+ var _a;
39
+ if (!isGtagConfigured()) {
40
+ context.log("warn", 700);
41
+ return;
42
+ }
43
+ if (!emitAll && !result.changed) {
44
+ return;
45
+ }
46
+ (_a = theWindow.gtag) == null ? void 0 : _a.call(theWindow, "event", result.name, {
47
+ event_category: "Uniform Personalization",
48
+ event_label: result.variantIds.join(", "),
49
+ is_control_group: result.control ? 1 : 0
50
+ });
51
+ };
52
+ const onTestResult = (result) => {
53
+ var _a, _b;
54
+ if (!isGtagConfigured()) {
55
+ context.log("warn", 700);
56
+ return;
57
+ }
58
+ if (!emitAll && !result.variantAssigned) {
59
+ return;
60
+ }
61
+ (_b = theWindow.gtag) == null ? void 0 : _b.call(theWindow, "event", result.name, {
62
+ event_category: "Uniform AB Testing",
63
+ event_label: (_a = result.variantId) != null ? _a : "No Variant"
64
+ });
65
+ };
66
+ context.events.on("personalizationResult", onPersonalizationResult);
67
+ context.events.on("testResult", onTestResult);
68
+ if (!disableEventSignals && isGtagConfigured() && !(theWindow == null ? void 0 : theWindow.__UF_PATCHED_GTAG__)) {
69
+ const defaultGtag = theWindow.gtag;
70
+ theWindow.gtag = (...args) => {
71
+ var _a;
72
+ defaultGtag(...args);
73
+ if (args[0] === "event" && !["Uniform AB Testing", "Uniform Personalization"].includes((_a = args[2]) == null ? void 0 : _a.event_category)) {
74
+ context.update({ events: [{ event: args[1] }] });
75
+ }
76
+ };
77
+ context.log("debug", 701);
78
+ theWindow.__UF_PATCHED_GTAG__ = true;
79
+ }
80
+ return () => {
81
+ context.events.off("personalizationResult", onPersonalizationResult);
82
+ context.events.off("testResult", onTestResult);
83
+ };
84
+ }
85
+ };
86
+ };
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ enableGoogleGtagAnalytics
90
+ });
package/dist/index.mjs CHANGED
@@ -1 +1,65 @@
1
- var f=g=>{let{disableEventSignals:_,theWindow:e=typeof window!="undefined"?window:void 0,emitAll:l}=g||{},i=()=>typeof e!="undefined"&&typeof e.gtag=="function";return{init:o=>{let r=n=>{var t;if(!i()){o.log("warn",700);return}!l&&!n.changed||(t=e.gtag)==null||t.call(e,"event",n.name,{event_category:"Uniform Personalization",event_label:n.variantIds.join(", "),is_control_group:n.control?1:0})},s=n=>{var t,a;if(!i()){o.log("warn",700);return}!l&&!n.variantAssigned||(a=e.gtag)==null||a.call(e,"event",n.name,{event_category:"Uniform AB Testing",event_label:(t=n.variantId)!=null?t:"No Variant"})};if(o.events.on("personalizationResult",r),o.events.on("testResult",s),!_&&i()&&!(e!=null&&e.__UF_PATCHED_GTAG__)){let n=e.gtag;e.gtag=(...t)=>{var a;n(...t),t[0]==="event"&&!["Uniform AB Testing","Uniform Personalization"].includes((a=t[2])==null?void 0:a.event_category)&&o.update({events:[{event:t[1]}]})},o.log("debug",701),e.__UF_PATCHED_GTAG__=!0}return()=>{o.events.off("personalizationResult",r),o.events.off("testResult",s)}}}};export{f as enableGoogleGtagAnalytics};
1
+ // src/index.ts
2
+ var enableGoogleGtagAnalytics = (options) => {
3
+ const {
4
+ disableEventSignals,
5
+ theWindow = typeof window !== "undefined" ? window : void 0,
6
+ emitAll
7
+ } = options || {};
8
+ const isGtagConfigured = () => {
9
+ return typeof theWindow !== "undefined" && typeof theWindow.gtag === "function";
10
+ };
11
+ return {
12
+ init: (context) => {
13
+ const onPersonalizationResult = (result) => {
14
+ var _a;
15
+ if (!isGtagConfigured()) {
16
+ context.log("warn", 700);
17
+ return;
18
+ }
19
+ if (!emitAll && !result.changed) {
20
+ return;
21
+ }
22
+ (_a = theWindow.gtag) == null ? void 0 : _a.call(theWindow, "event", result.name, {
23
+ event_category: "Uniform Personalization",
24
+ event_label: result.variantIds.join(", "),
25
+ is_control_group: result.control ? 1 : 0
26
+ });
27
+ };
28
+ const onTestResult = (result) => {
29
+ var _a, _b;
30
+ if (!isGtagConfigured()) {
31
+ context.log("warn", 700);
32
+ return;
33
+ }
34
+ if (!emitAll && !result.variantAssigned) {
35
+ return;
36
+ }
37
+ (_b = theWindow.gtag) == null ? void 0 : _b.call(theWindow, "event", result.name, {
38
+ event_category: "Uniform AB Testing",
39
+ event_label: (_a = result.variantId) != null ? _a : "No Variant"
40
+ });
41
+ };
42
+ context.events.on("personalizationResult", onPersonalizationResult);
43
+ context.events.on("testResult", onTestResult);
44
+ if (!disableEventSignals && isGtagConfigured() && !(theWindow == null ? void 0 : theWindow.__UF_PATCHED_GTAG__)) {
45
+ const defaultGtag = theWindow.gtag;
46
+ theWindow.gtag = (...args) => {
47
+ var _a;
48
+ defaultGtag(...args);
49
+ if (args[0] === "event" && !["Uniform AB Testing", "Uniform Personalization"].includes((_a = args[2]) == null ? void 0 : _a.event_category)) {
50
+ context.update({ events: [{ event: args[1] }] });
51
+ }
52
+ };
53
+ context.log("debug", 701);
54
+ theWindow.__UF_PATCHED_GTAG__ = true;
55
+ }
56
+ return () => {
57
+ context.events.off("personalizationResult", onPersonalizationResult);
58
+ context.events.off("testResult", onTestResult);
59
+ };
60
+ }
61
+ };
62
+ };
63
+ export {
64
+ enableGoogleGtagAnalytics
65
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/context-gtag",
3
- "version": "17.7.1-alpha.140+80ab6baf9",
3
+ "version": "17.7.1-alpha.169+522807b78",
4
4
  "description": "Uniform Context Google global site tag analytics package",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -17,7 +17,7 @@
17
17
  "types": "./dist/index.d.ts",
18
18
  "sideEffects": false,
19
19
  "scripts": {
20
- "build": "tsup --minify",
20
+ "build": "tsup",
21
21
  "dev": "tsup --watch",
22
22
  "clean": "rimraf dist",
23
23
  "test": "jest --maxWorkers=1",
@@ -28,7 +28,7 @@
28
28
  "@types/gtag.js": "0.0.12"
29
29
  },
30
30
  "dependencies": {
31
- "@uniformdev/context": "^17.7.1-alpha.140+80ab6baf9"
31
+ "@uniformdev/context": "^17.7.1-alpha.169+522807b78"
32
32
  },
33
33
  "files": [
34
34
  "/dist"
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "80ab6baf9edea6b520738bd3dff5c6afc882bf77"
39
+ "gitHead": "522807b78c5e15b076bd07b4a1a4124de07dcb5b"
40
40
  }