Skip to content

Commit

Permalink
[feat] GTM 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
euije committed Mar 15, 2024
1 parent fa98c5d commit 27f5fbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 14 additions & 1 deletion app/event/university/Booth/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,34 @@ import {
GOOGLE_PLAY_URL,
LANDING_PAGE_URL,
} from '@/util/string';
import { sendGTMEvent } from '@next/third-parties/google';
import { useSearchParams } from 'next/navigation';
import React, { useEffect } from 'react';
import { isAndroid, isIOS } from 'react-device-detect';

export default function Page() {
const params = useSearchParams();

useEffect(() => {
if (typeof window !== 'undefined') {
let platform;
if (isIOS) {
window.location.replace(APP_STORE_URL);
platform = 'iOS';
} else if (isAndroid) {
window.location.replace(GOOGLE_PLAY_URL);
platform = 'Android';
} else {
window.location.replace(LANDING_PAGE_URL);
platform = 'others';
}
sendGTMEvent({
id: params.get('id'),
platform: platform,
from: document.referrer,
});
}
}, []);
}, [params]);

return (
<>
Expand Down
3 changes: 2 additions & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Metadata } from 'next';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { Analytics } from '@vercel/analytics/react';
import { SpeedInsights } from '@vercel/speed-insights/next';
import { GoogleAnalytics } from '@next/third-parties/google';
import { GoogleAnalytics, GoogleTagManager } from '@next/third-parties/google';

import '@/styles/globals.css';
import { StyledComponentsRegistry } from '@/component/Provider/StyledComponentsRegistry';
Expand All @@ -29,6 +29,7 @@ export default function RootLayout({
<Analytics />
<SpeedInsights />
<GoogleAnalytics gaId='G-9Z53ZMP9VC' />
<GoogleTagManager gtmId='GTM-KCF3MM5S' />
<ReactQueryClientProvider>
<ReactQueryDevtools initialIsOpen={false} />
<StyledComponentsRegistry>
Expand Down

0 comments on commit 27f5fbe

Please sign in to comment.