@uniformdev/context-gtag 17.7.0 → 17.7.1-alpha.167
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 +65 -1
- package/dist/index.js +90 -1
- package/dist/index.mjs +65 -1
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -1 +1,65 @@
|
|
|
1
|
-
|
|
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";
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "17.7.1-alpha.167+a358adea9",
|
|
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
|
|
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.
|
|
31
|
+
"@uniformdev/context": "^17.7.1-alpha.167+a358adea9"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
34
|
"/dist"
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "a358adea91b24a877e577be784d56b794c4cfab8"
|
|
40
40
|
}
|