@uxf/analytics 10.1.1 → 10.2.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 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 { GtmScript } from "@uxf/analytics/gtm";
56
+ import { useGtmScript } from "@uxf/analytics/gtm";
57
+
58
+ const gtmScript = useGtmScript("GTM-YOURID");
47
59
 
48
60
  // in your head component
49
- <GtmScript gtmId="GTM-YOURID" />
61
+ <script dangerouslySetInnerHTML={{ __html: gtmScript }} />
50
62
  ```
51
63
 
52
64
  ### Update GTM consent
package/gtm/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from "../src/gtm/gmt-script";
2
1
  export type * from "../src/gtm/types";
3
2
  export * from "../src/gtm/use-gtm-script";
4
3
  export * from "../src/gtm/utils";
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.1.1",
3
+ "version": "10.2.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "tsc -P tsconfig.json",
@@ -5,3 +5,4 @@ export type CookiesConsentType = {
5
5
  };
6
6
  export declare const storeConsentToCookie: (consent: CookiesConsentType) => void;
7
7
  export declare const readConsentFromCookie: (ctx?: any) => CookiesConsentType;
8
+ export declare const isConsentCookieSet: (ctx?: any) => boolean;
@@ -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;
@@ -1,9 +0,0 @@
1
- import { FC } from "react";
2
- interface Props {
3
- gtmId: string;
4
- }
5
- /**
6
- * @deprecated use useGtmScript hook instead
7
- */
8
- export declare const GtmScript: FC<Props>;
9
- export {};
@@ -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;