@arkyn/components 1.3.146 → 1.3.147

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. package/dist/bundle.js +75901 -20440
  2. package/dist/bundle.umd.cjs +1645 -260
  3. package/dist/components/ClientOnly.d.ts +7 -0
  4. package/dist/components/ClientOnly.d.ts.map +1 -0
  5. package/dist/components/ClientOnly.js +5 -0
  6. package/dist/components/GoogleTagManager/GoogleTagManager.client.d.ts +11 -0
  7. package/dist/components/GoogleTagManager/GoogleTagManager.client.d.ts.map +1 -0
  8. package/dist/components/GoogleTagManager/GoogleTagManager.client.js +8 -0
  9. package/dist/components/GoogleTagManager/googleTagManager.d.ts +20 -0
  10. package/dist/components/GoogleTagManager/googleTagManager.d.ts.map +1 -0
  11. package/dist/components/GoogleTagManager/googleTagManager.js +52 -0
  12. package/dist/components/GoogleTagManager/index.d.ts +11 -0
  13. package/dist/components/GoogleTagManager/index.d.ts.map +1 -0
  14. package/dist/components/GoogleTagManager/index.js +8 -0
  15. package/dist/components/GoogleTagManager/snippets/appendToDataLayer.d.ts +7 -0
  16. package/dist/components/GoogleTagManager/snippets/appendToDataLayer.d.ts.map +1 -0
  17. package/dist/components/GoogleTagManager/snippets/appendToDataLayer.js +7 -0
  18. package/dist/components/GoogleTagManager/snippets/generateGTMElements.d.ts +15 -0
  19. package/dist/components/GoogleTagManager/snippets/generateGTMElements.d.ts.map +1 -0
  20. package/dist/components/GoogleTagManager/snippets/generateGTMElements.js +25 -0
  21. package/dist/hooks/useHydrated.d.ts +3 -0
  22. package/dist/hooks/useHydrated.d.ts.map +1 -0
  23. package/dist/hooks/useHydrated.js +8 -0
  24. package/dist/index.d.ts +4 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +5 -1
  27. package/dist/style.css +1 -1
  28. package/package.json +1 -1
  29. package/src/components/ClientOnly.tsx +10 -0
  30. package/src/components/GoogleTagManager/GoogleTagManager.client.tsx +19 -0
  31. package/src/components/GoogleTagManager/googleTagManager.ts +100 -0
  32. package/src/components/GoogleTagManager/index.tsx +39 -0
  33. package/src/components/GoogleTagManager/snippets/appendToDataLayer.ts +14 -0
  34. package/src/components/GoogleTagManager/snippets/generateGTMElements.ts +43 -0
  35. package/src/hooks/useHydrated.ts +15 -0
  36. package/src/index.ts +6 -1
@@ -0,0 +1,39 @@
1
+ import { ClientOnly } from "../../components/ClientOnly";
2
+ import { GoogleTagManagerClient } from "./GoogleTagManager.client";
3
+
4
+ type GoogleTagManagerProps = {
5
+ gtmId: string;
6
+ events?: Record<string, string>;
7
+ dataLayer?: Record<string, string>;
8
+ dataLayerName?: string;
9
+ auth?: string;
10
+ preview?: string;
11
+ };
12
+
13
+ function GoogleTagManager(props: GoogleTagManagerProps) {
14
+ const {
15
+ gtmId,
16
+ auth = "",
17
+ preview = "",
18
+ dataLayerName = "dataLayer",
19
+ events = {},
20
+ dataLayer = {},
21
+ } = props;
22
+
23
+ return (
24
+ <ClientOnly>
25
+ {() => (
26
+ <GoogleTagManagerClient
27
+ auth={auth}
28
+ dataLayer={dataLayer}
29
+ dataLayerName={dataLayerName}
30
+ events={events}
31
+ gtmId={gtmId}
32
+ preview={preview}
33
+ />
34
+ )}
35
+ </ClientOnly>
36
+ );
37
+ }
38
+
39
+ export { GoogleTagManager };
@@ -0,0 +1,14 @@
1
+ type AppendToDataLayer = {
2
+ dataLayer: Record<string, string>;
3
+ dataLayerName: string;
4
+ };
5
+
6
+ function appendToDataLayer(props: AppendToDataLayer) {
7
+ const { dataLayer, dataLayerName } = props;
8
+
9
+ return `
10
+ window.${dataLayerName} = window.${dataLayerName} || [];
11
+ window.${dataLayerName}.push(${JSON.stringify(dataLayer)})`;
12
+ }
13
+
14
+ export { appendToDataLayer };
@@ -0,0 +1,43 @@
1
+ import { appendToDataLayer } from "./appendToDataLayer";
2
+
3
+ type GenerateGTMElementsProps = {
4
+ id: string;
5
+ events: Record<string, string>;
6
+ dataLayer: Record<string, string>;
7
+ dataLayerName: string;
8
+ preview: string;
9
+ auth: string;
10
+ };
11
+
12
+ function generateGTMElements(props: GenerateGTMElementsProps) {
13
+ const { id, events, dataLayer, dataLayerName, preview, auth } = props;
14
+
15
+ const gtmAuth = `&gtm_auth=${auth}`;
16
+ const gtmPreview = `&gtm_preview=${preview}`;
17
+
18
+ if (!id) console.warn("GTM Id is required");
19
+
20
+ const iframe = `
21
+ <iframe src="https://www.googletagmanager.com/ns.html?id=${id}${gtmAuth}${gtmPreview}&gtm_cookies_win=x"
22
+ height="0" width="0" style="display:none;visibility:hidden" id="tag-manager"></iframe>`;
23
+
24
+ const script = `
25
+ (function(w,d,s,l,i){w[l]=w[l]||[];
26
+ w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js', ${JSON.stringify(
27
+ events
28
+ ).slice(1, -1)}});
29
+ var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';
30
+ j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl+'${gtmAuth}${gtmPreview}&gtm_cookies_win=x';
31
+ f.parentNode.insertBefore(j,f);
32
+ })(window,document,'script','${dataLayerName}','${id}');`;
33
+
34
+ const dataLayerVar = appendToDataLayer({ dataLayer, dataLayerName });
35
+
36
+ return {
37
+ iframe,
38
+ script,
39
+ dataLayerVar,
40
+ };
41
+ }
42
+
43
+ export { generateGTMElements };
@@ -0,0 +1,15 @@
1
+ import { useSyncExternalStore } from "react";
2
+
3
+ function subscribe() {
4
+ return () => {};
5
+ }
6
+
7
+ function useHydrated() {
8
+ return useSyncExternalStore(
9
+ subscribe,
10
+ () => true,
11
+ () => false
12
+ );
13
+ }
14
+
15
+ export { useHydrated };
package/src/index.ts CHANGED
@@ -9,7 +9,6 @@ export {
9
9
  export { Badge } from "./components/Badge";
10
10
  export { Card } from "./components/Card";
11
11
  export { Divider } from "./components/Divider";
12
- export { GoogleMap } from "./components/GoogleMap";
13
12
  export { Skeleton } from "./components/Skeleton";
14
13
  export {
15
14
  TableBody,
@@ -49,6 +48,7 @@ export { Tooltip } from "./components/Tooltip";
49
48
  export { useAutomation } from "./hooks/useAutomation";
50
49
  export { useDrawer } from "./hooks/useDrawer";
51
50
  export { useFieldErrors } from "./hooks/useFieldErrors";
51
+ export { useHydrated } from "./hooks/useHydrated";
52
52
  export { useModal } from "./hooks/useModal";
53
53
  export { useScopedParams } from "./hooks/useScopedParams";
54
54
  export { useToast } from "./hooks/useToast";
@@ -58,3 +58,8 @@ export { DrawerProvider } from "./provider/DrawerProvider";
58
58
  export { GoogleProvider } from "./provider/GoogleProvider";
59
59
  export { ModalProvider } from "./provider/ModalProvider";
60
60
  export { ToastProvider } from "./provider/ToastProvider";
61
+
62
+ // Others
63
+ export { ClientOnly } from "./components/ClientOnly";
64
+ export { GoogleMap } from "./components/GoogleMap";
65
+ export { GoogleTagManager } from "./components/GoogleTagManager";