Skip to content

Commit 7ad2dea

Browse files
committed
add meta pixel
1 parent 9d8cfbb commit 7ad2dea

4 files changed

Lines changed: 49 additions & 1 deletion

File tree

‎app/(main)/layout.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import PlayerFloating from "@/components/player-floating";
2727
import { PlayerProvider } from "@/components/player-context";
2828
import { toPlainText, VisualEditing } from "next-sanity";
2929
import { DisableDraftMode } from "@/components/disable-draft-mode";
30+
import MetaPixel from "./meta-pixel";
3031

3132
const nunito = Nunito({
3233
subsets: ["latin"],
@@ -94,6 +95,10 @@ export default async function RootLayout({
9495
inter.variable,
9596
)}
9697
>
98+
<SpeedInsights />
99+
<MetaPixel />
100+
<DisableDraftMode />
101+
<VisualEditing />
97102
<PlayerProvider>
98103
<ThemeProvider
99104
attribute="class"

‎app/(main)/meta-pixel.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use client'
2+
3+
import { useEffect } from 'react'
4+
import { usePathname, useSearchParams } from 'next/navigation'
5+
6+
// biome-ignore lint/style/noNonNullAssertion: <explanation>
7+
const FB_PIXEL_ID = process.env.NEXT_PUBLIC_FB_PIXEL_ID!;
8+
9+
export default function MetaPixel() {
10+
const pathname = usePathname()
11+
const searchParams = useSearchParams()
12+
13+
useEffect(() => {
14+
import('react-facebook-pixel')
15+
.then((x) => x.default)
16+
.then((ReactPixel) => {
17+
ReactPixel.init(FB_PIXEL_ID)
18+
ReactPixel.pageView()
19+
})
20+
}, [])
21+
22+
useEffect(() => {
23+
import('react-facebook-pixel')
24+
.then((x) => x.default)
25+
.then((ReactPixel) => {
26+
ReactPixel.pageView()
27+
})
28+
}, [pathname, searchParams])
29+
30+
return null
31+
}

‎package.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"react-day-picker": "^9.5.1",
8787
"react-dom": "^18.3.1",
8888
"react-dropzone": "^14.3.5",
89+
"react-facebook-pixel": "^1.0.4",
8990
"react-hook-form": "^7.54.2",
9091
"react-icons": "^5.4.0",
9192
"react-inlinesvg": "^4.1.8",
@@ -121,7 +122,10 @@
121122
},
122123
"pnpm": {
123124
"peerDependencyRules": {
124-
"allowAny": ["react", "react-dom"]
125+
"allowAny": [
126+
"react",
127+
"react-dom"
128+
]
125129
}
126130
}
127131
}

‎pnpm-lock.yaml‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)