@uxf/analytics 10.1.1 → 10.4.0
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/README.md +14 -2
- package/gtm/index.d.ts +0 -1
- package/gtm/index.js +0 -1
- package/package.json +2 -2
- package/src/consent/index.d.ts +1 -0
- package/src/consent/index.js +9 -1
- package/src/gtm/gmt-script.d.ts +0 -9
- package/src/gtm/gmt-script.js +0 -32
package/README.md
CHANGED
|
@@ -36,6 +36,16 @@ import { readConsentFromCookie } from "@uxf/analytics/consent";
|
|
|
36
36
|
const consent = readConsentFromCookie();
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
### Check if cookie consent is set
|
|
40
|
+
|
|
41
|
+
This checks if the consent is already stored in cookies.
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { isConsentCookieSet } from "@uxf/analytics/consent";
|
|
45
|
+
|
|
46
|
+
const isSet = isCookieConsentSet(); // boolean
|
|
47
|
+
```
|
|
48
|
+
|
|
39
49
|
## GTM
|
|
40
50
|
|
|
41
51
|
### Initialize GTM
|
|
@@ -43,10 +53,12 @@ const consent = readConsentFromCookie();
|
|
|
43
53
|
This reads the consent from cookie and initializes the GTM dataLayer.
|
|
44
54
|
|
|
45
55
|
```tsx
|
|
46
|
-
import {
|
|
56
|
+
import { useGtmScript } from "@uxf/analytics/gtm";
|
|
57
|
+
|
|
58
|
+
const gtmScript = useGtmScript("GTM-YOURID");
|
|
47
59
|
|
|
48
60
|
// in your head component
|
|
49
|
-
<
|
|
61
|
+
<script dangerouslySetInnerHTML={{ __html: gtmScript }} />
|
|
50
62
|
```
|
|
51
63
|
|
|
52
64
|
### Update GTM consent
|
package/gtm/index.d.ts
CHANGED
package/gtm/index.js
CHANGED
|
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("../src/gtm/gmt-script"), exports);
|
|
18
17
|
__exportStar(require("../src/gtm/use-gtm-script"), exports);
|
|
19
18
|
__exportStar(require("../src/gtm/utils"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/analytics",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc -P tsconfig.json",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"author": "",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@uxf/core": "10.
|
|
18
|
+
"@uxf/core": "10.4.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": ">=18.0.2"
|
package/src/consent/index.d.ts
CHANGED
package/src/consent/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readConsentFromCookie = exports.storeConsentToCookie = void 0;
|
|
3
|
+
exports.isConsentCookieSet = exports.readConsentFromCookie = exports.storeConsentToCookie = void 0;
|
|
4
4
|
const cookie_1 = require("@uxf/core/cookie");
|
|
5
5
|
const COOKIE_NAME = "cookieConsent";
|
|
6
6
|
const storeConsentToCookie = (consent) => {
|
|
@@ -15,3 +15,11 @@ const readConsentFromCookie = (ctx) => {
|
|
|
15
15
|
return JSON.parse(atob(cookieConsent || "") || "{}");
|
|
16
16
|
};
|
|
17
17
|
exports.readConsentFromCookie = readConsentFromCookie;
|
|
18
|
+
const isConsentCookieSet = (ctx) => {
|
|
19
|
+
const cookieConsent = cookie_1.Cookie.create(ctx).get(COOKIE_NAME);
|
|
20
|
+
const parsedConsent = JSON.parse(atob(cookieConsent || "") || "{}");
|
|
21
|
+
return (typeof parsedConsent.ad_storage === "boolean" &&
|
|
22
|
+
typeof parsedConsent.analytics_storage === "boolean" &&
|
|
23
|
+
typeof parsedConsent.personalization_storage === "boolean");
|
|
24
|
+
};
|
|
25
|
+
exports.isConsentCookieSet = isConsentCookieSet;
|
package/src/gtm/gmt-script.d.ts
DELETED
package/src/gtm/gmt-script.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.GtmScript = void 0;
|
|
7
|
-
const useIsMounted_1 = require("@uxf/core/hooks/useIsMounted");
|
|
8
|
-
const react_1 = __importDefault(require("react"));
|
|
9
|
-
const consent_1 = require("../consent");
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated use useGtmScript hook instead
|
|
12
|
-
*/
|
|
13
|
-
const GtmScript = (props) => {
|
|
14
|
-
const isMounted = (0, useIsMounted_1.useIsMounted)();
|
|
15
|
-
if (!isMounted) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
const decodedCookie = (0, consent_1.readConsentFromCookie)();
|
|
19
|
-
const defaultGtmCookie = `
|
|
20
|
-
window.dataLayer = window.dataLayer || [];
|
|
21
|
-
if (typeof gtag !== "function") { function gtag(){dataLayer.push(arguments)}; }
|
|
22
|
-
gtag("consent", "default", {
|
|
23
|
-
'analytics_storage': '${decodedCookie.analytics_storage ? "granted" : "denied"}',
|
|
24
|
-
'ad_storage': '${decodedCookie.ad_storage ? "granted" : "denied"}',
|
|
25
|
-
'personalization_storage': '${decodedCookie.personalization_storage ? "granted" : "denied"}'}
|
|
26
|
-
);`;
|
|
27
|
-
return (react_1.default.createElement("script", { dangerouslySetInnerHTML: {
|
|
28
|
-
__html: defaultGtmCookie +
|
|
29
|
-
`(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.defer=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','${props.gtmId}');`,
|
|
30
|
-
} }));
|
|
31
|
-
};
|
|
32
|
-
exports.GtmScript = GtmScript;
|