From d8e2fa27d9c3c9c4b7d92f55ea8be1ef4b5d0a60 Mon Sep 17 00:00:00 2001 From: gyeongza Date: Sun, 14 Jul 2024 16:43:46 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20facebook=20pixel=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/layout.tsx | 18 ++++++++++ src/shared/components/PixelEvents/index.tsx | 37 +++++++++++++++++++++ src/shared/utils/pixel.ts | 9 +++++ 3 files changed, 64 insertions(+) create mode 100644 src/shared/components/PixelEvents/index.tsx create mode 100644 src/shared/utils/pixel.ts diff --git a/src/app/layout.tsx b/src/app/layout.tsx index fbd2f61..2935675 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -6,6 +6,10 @@ import GoogleAnalytics from '@/shared/components/GoogleAnalytics'; import { getMetadata } from '@/shared/utils/metadata'; import { Toaster } from '@/shared/components/shadcn/ui/toaster'; import { UserStatusProvider } from '@/features/auth/context/userStatusContext'; +import { Suspense } from 'react'; +import NavigationEvents from '@/shared/components/PixelEvents'; +import Image from 'next/image'; +import { FB_PIXEL_ID } from '@/shared/utils/pixel'; const roboto = Roboto({ weight: ['400', '700'], @@ -27,6 +31,17 @@ export default function RootLayout({ return ( + + + {process.env.NEXT_PUBLIC_GA_ID && } @@ -35,6 +50,9 @@ export default function RootLayout({ {children} + + + diff --git a/src/shared/components/PixelEvents/index.tsx b/src/shared/components/PixelEvents/index.tsx new file mode 100644 index 0000000..333083c --- /dev/null +++ b/src/shared/components/PixelEvents/index.tsx @@ -0,0 +1,37 @@ +'use client'; + +import { usePathname, useSearchParams } from 'next/navigation'; +import { useEffect } from 'react'; +import * as fbq from '../../utils/pixel'; +import Script from 'next/script'; +import { FB_PIXEL_ID } from '@/shared/utils/pixel'; + +export default function NavigationEvents() { + const pathname = usePathname(); + const searchParams = useSearchParams(); + useEffect(() => { + fbq.pageview(); + }, [pathname, searchParams]); + return ( + <> +