@uxf/analytics 10.1.0 → 10.1.1

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/gtm/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "../src/gtm/gmt-script";
2
2
  export type * from "../src/gtm/types";
3
+ export * from "../src/gtm/use-gtm-script";
3
4
  export * from "../src/gtm/utils";
package/gtm/index.js CHANGED
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("../src/gtm/gmt-script"), exports);
18
+ __exportStar(require("../src/gtm/use-gtm-script"), exports);
18
19
  __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.0",
3
+ "version": "10.1.1",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "tsc -P tsconfig.json",
@@ -2,5 +2,8 @@ import { FC } from "react";
2
2
  interface Props {
3
3
  gtmId: string;
4
4
  }
5
+ /**
6
+ * @deprecated use useGtmScript hook instead
7
+ */
5
8
  export declare const GtmScript: FC<Props>;
6
9
  export {};
@@ -7,6 +7,9 @@ exports.GtmScript = void 0;
7
7
  const useIsMounted_1 = require("@uxf/core/hooks/useIsMounted");
8
8
  const react_1 = __importDefault(require("react"));
9
9
  const consent_1 = require("../consent");
10
+ /**
11
+ * @deprecated use useGtmScript hook instead
12
+ */
10
13
  const GtmScript = (props) => {
11
14
  const isMounted = (0, useIsMounted_1.useIsMounted)();
12
15
  if (!isMounted) {
@@ -0,0 +1 @@
1
+ export declare const useGtmScript: (gtmId: string) => string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useGtmScript = void 0;
4
+ const consent_1 = require("../consent");
5
+ const useGtmScript = (gtmId) => {
6
+ const decodedCookie = (0, consent_1.readConsentFromCookie)();
7
+ const defaultGtmCookie = `
8
+ window.dataLayer = window.dataLayer || [];
9
+ if (typeof gtag !== "function") { function gtag(){dataLayer.push(arguments)}; }
10
+ gtag("consent", "default", {
11
+ 'analytics_storage': '${decodedCookie.analytics_storage ? "granted" : "denied"}',
12
+ 'ad_storage': '${decodedCookie.ad_storage ? "granted" : "denied"}',
13
+ 'personalization_storage': '${decodedCookie.personalization_storage ? "granted" : "denied"}'}
14
+ );`;
15
+ return (defaultGtmCookie +
16
+ `(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','${gtmId}');`);
17
+ };
18
+ exports.useGtmScript = useGtmScript;