Skip to content

Commit a6e87c7

Browse files
committed
change GA tracking place
1 parent 3ec0051 commit a6e87c7

5 files changed

Lines changed: 52 additions & 1042 deletions

File tree

.storybook/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const config: StorybookConfig = {
1515
},
1616
},
1717
'@storybook/addon-themes',
18-
'@storybook/addon-google-analytics',
1918
],
2019
staticDirs: ['../src/static', '../src/lib/assets/fonts'],
2120
framework: {

.storybook/manager.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@ import yourTheme from './theme';
44
addons.setConfig({
55
theme: yourTheme,
66
});
7-
8-
window.STORYBOOK_GA_ID = 'G-H4X1J4017T';
9-
window.STORYBOOK_REACT_GA_OPTIONS = {};

.storybook/preview.tsx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import 'react-loading-skeleton/dist/skeleton.css';
33
import type { Preview } from '@storybook/react-vite';
44

@@ -16,11 +16,35 @@ const GlobalStyles = createGlobalStyle`
1616
const preview: Preview = {
1717
// tags: ['autodocs'], // turn on when fix some components stories
1818
decorators: [
19-
(Story) => (
20-
<ThemeProvider theme={themeConfig}>
21-
<Story />
22-
</ThemeProvider>
23-
),
19+
(Story) => {
20+
useEffect(() => {
21+
// Google Analytics tracking code
22+
const script = document.createElement('script');
23+
script.async = true;
24+
script.src = 'https://www.googletagmanager.com/gtag/js?id=G-H4X1J4017T'; // Replace with your GA4 Measurement ID
25+
document.head.appendChild(script);
26+
27+
script.onload = () => {
28+
window.dataLayer = window.dataLayer || [];
29+
function gtag() {
30+
dataLayer.push(arguments);
31+
}
32+
gtag('js', new Date());
33+
gtag('config', 'G-H4X1J4017T'); // Replace with your GA4 Measurement ID
34+
};
35+
36+
return () => {
37+
// Optional: Clean up the script if needed
38+
document.head.removeChild(script);
39+
};
40+
}, []);
41+
42+
return (
43+
<ThemeProvider theme={themeConfig}>
44+
<Story />
45+
</ThemeProvider>
46+
);
47+
},
2448
withThemeFromJSXProvider({
2549
themes: {
2650
light: themeConfig.light,

0 commit comments

Comments
 (0)