@arkyn/components 1.3.146 → 1.3.148
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/bundle.js +87045 -20514
- package/dist/bundle.umd.cjs +1920 -260
- package/dist/components/ClientOnly.d.ts +7 -0
- package/dist/components/ClientOnly.d.ts.map +1 -0
- package/dist/components/ClientOnly.js +5 -0
- package/dist/components/GoogleTagManager/GoogleTagManager.client.d.ts +11 -0
- package/dist/components/GoogleTagManager/GoogleTagManager.client.d.ts.map +1 -0
- package/dist/components/GoogleTagManager/GoogleTagManager.client.js +8 -0
- package/dist/components/GoogleTagManager/googleTagManager.d.ts +20 -0
- package/dist/components/GoogleTagManager/googleTagManager.d.ts.map +1 -0
- package/dist/components/GoogleTagManager/googleTagManager.js +52 -0
- package/dist/components/GoogleTagManager/index.d.ts +11 -0
- package/dist/components/GoogleTagManager/index.d.ts.map +1 -0
- package/dist/components/GoogleTagManager/index.js +8 -0
- package/dist/components/GoogleTagManager/snippets/appendToDataLayer.d.ts +7 -0
- package/dist/components/GoogleTagManager/snippets/appendToDataLayer.d.ts.map +1 -0
- package/dist/components/GoogleTagManager/snippets/appendToDataLayer.js +7 -0
- package/dist/components/GoogleTagManager/snippets/generateGTMElements.d.ts +15 -0
- package/dist/components/GoogleTagManager/snippets/generateGTMElements.d.ts.map +1 -0
- package/dist/components/GoogleTagManager/snippets/generateGTMElements.js +25 -0
- package/dist/components/ImageUpload/index.d.ts.map +1 -1
- package/dist/components/ImageUpload/index.js +1 -0
- package/dist/hooks/useHydrated.d.ts +3 -0
- package/dist/hooks/useHydrated.d.ts.map +1 -0
- package/dist/hooks/useHydrated.js +8 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/ClientOnly.tsx +10 -0
- package/src/components/GoogleTagManager/GoogleTagManager.client.tsx +19 -0
- package/src/components/GoogleTagManager/googleTagManager.ts +100 -0
- package/src/components/GoogleTagManager/index.tsx +39 -0
- package/src/components/GoogleTagManager/snippets/appendToDataLayer.ts +14 -0
- package/src/components/GoogleTagManager/snippets/generateGTMElements.ts +43 -0
- package/src/components/ImageUpload/index.tsx +1 -0
- package/src/hooks/useHydrated.ts +15 -0
- package/src/index.ts +6 -1
@@ -0,0 +1,100 @@
|
|
1
|
+
import { appendToDataLayer } from "./snippets/appendToDataLayer";
|
2
|
+
import { generateGTMElements } from "./snippets/generateGTMElements";
|
3
|
+
|
4
|
+
type InitializeDataLayerProps = {
|
5
|
+
dataLayerName: string;
|
6
|
+
dataLayer: Record<string, string>;
|
7
|
+
};
|
8
|
+
|
9
|
+
type InitializeGTMProps = {
|
10
|
+
id: string;
|
11
|
+
events: Record<string, string>;
|
12
|
+
dataLayer: Record<string, string>;
|
13
|
+
dataLayerName: string;
|
14
|
+
preview: string;
|
15
|
+
auth: string;
|
16
|
+
};
|
17
|
+
|
18
|
+
type InitializeProps = {
|
19
|
+
gtmId: string;
|
20
|
+
events: Record<string, string>;
|
21
|
+
dataLayer: Record<string, string>;
|
22
|
+
dataLayerName: string;
|
23
|
+
auth: string;
|
24
|
+
preview: string;
|
25
|
+
};
|
26
|
+
|
27
|
+
interface Window {
|
28
|
+
[key: string]: any;
|
29
|
+
}
|
30
|
+
|
31
|
+
declare var window: Window;
|
32
|
+
|
33
|
+
class GoogleTagManager {
|
34
|
+
private initializeDataScript(dataLayer: string) {
|
35
|
+
const script = document.createElement("script");
|
36
|
+
script.innerHTML = dataLayer;
|
37
|
+
return script;
|
38
|
+
}
|
39
|
+
|
40
|
+
private initializeGTMElements(props: InitializeGTMProps) {
|
41
|
+
const snippets = generateGTMElements(props);
|
42
|
+
|
43
|
+
const noScript = () => {
|
44
|
+
const noscript = document.createElement("noscript");
|
45
|
+
noscript.innerHTML = snippets.iframe;
|
46
|
+
return noscript;
|
47
|
+
};
|
48
|
+
|
49
|
+
const script = () => {
|
50
|
+
const script = document.createElement("script");
|
51
|
+
script.innerHTML = snippets.script;
|
52
|
+
return script;
|
53
|
+
};
|
54
|
+
|
55
|
+
const dataScript = this.initializeDataScript(snippets.dataLayerVar);
|
56
|
+
|
57
|
+
return {
|
58
|
+
noScript,
|
59
|
+
script,
|
60
|
+
dataScript,
|
61
|
+
};
|
62
|
+
}
|
63
|
+
|
64
|
+
initializeDataLayer(props: InitializeDataLayerProps) {
|
65
|
+
const { dataLayer, dataLayerName } = props;
|
66
|
+
|
67
|
+
if (window[dataLayerName]) return window[dataLayerName].push(dataLayer);
|
68
|
+
|
69
|
+
const snippets = appendToDataLayer({ dataLayer, dataLayerName });
|
70
|
+
const dataScript = this.initializeDataScript(snippets);
|
71
|
+
|
72
|
+
document.head.insertBefore(dataScript, document.head.childNodes[0]);
|
73
|
+
}
|
74
|
+
|
75
|
+
initialize(props: InitializeProps) {
|
76
|
+
const {
|
77
|
+
events,
|
78
|
+
gtmId,
|
79
|
+
dataLayer,
|
80
|
+
auth = "",
|
81
|
+
preview = "",
|
82
|
+
dataLayerName = "dataLayer",
|
83
|
+
} = props;
|
84
|
+
|
85
|
+
const gtm = this.initializeGTMElements({
|
86
|
+
id: gtmId,
|
87
|
+
events: events,
|
88
|
+
dataLayer: dataLayer || undefined,
|
89
|
+
dataLayerName: dataLayerName,
|
90
|
+
auth,
|
91
|
+
preview,
|
92
|
+
});
|
93
|
+
|
94
|
+
if (dataLayer) document.head.appendChild(gtm.dataScript);
|
95
|
+
document.head.insertBefore(gtm.script(), document.head.childNodes[0]);
|
96
|
+
document.body.insertBefore(gtm.noScript(), document.body.childNodes[0]);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
export { GoogleTagManager };
|
@@ -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 = `>m_auth=${auth}`;
|
16
|
+
const gtmPreview = `>m_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}>m_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}>m_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 };
|
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";
|