File tree Expand file tree Collapse file tree 11 files changed +97
-0
lines changed
examples/with-facebook-pixel Expand file tree Collapse file tree 11 files changed +97
-0
lines changed File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 1+ import Link from 'next/link'
2+
3+ export default function About ( ) {
4+ return (
5+ < >
6+ < h1 > About</ h1 >
7+
8+ < Link href = "/" > back to home</ Link >
9+ </ >
10+ )
11+ }
Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ import { usePathname } from 'next/navigation'
4+ import Script from 'next/script'
5+ import { useEffect , useState } from 'react'
6+ import * as pixel from '/lib/fpixel'
7+
8+ const FacebookPixel = ( ) => {
9+ const [ loaded , setLoaded ] = useState ( false )
10+ const pathname = usePathname ( )
11+
12+ useEffect ( ( ) => {
13+ if ( ! loaded ) return
14+
15+ pixel . pageview ( )
16+ } , [ pathname , loaded ] )
17+
18+ return (
19+ < div >
20+ < Script
21+ id = "fb-pixel"
22+ src = "/scripts/pixel.js"
23+ strategy = "afterInteractive"
24+ onLoad = { ( ) => setLoaded ( true ) }
25+ data-pixel-id = { pixel . FB_PIXEL_ID }
26+ />
27+ </ div >
28+ )
29+ }
30+
31+ export default FacebookPixel
Original file line number Diff line number Diff line change 1+ export { default as FacebookPixel } from './FacebookPixel'
Original file line number Diff line number Diff line change 1+ import { FacebookPixel } from './components'
2+
3+ export default function RootLayout ( { children } ) {
4+ return (
5+ < html lang = "en" >
6+ < body >
7+ { children }
8+ < FacebookPixel />
9+ </ body >
10+ </ html >
11+ )
12+ }
Original file line number Diff line number Diff line change 1+ import Link from 'next/link'
2+
3+ export default function Home ( ) {
4+ return (
5+ < >
6+ < h2 >
7+ Go to `app/layout.js` to see how to implement Facebook Pixel in Next.js
8+ 13 with the App Router
9+ </ h2 >
10+ < h2 > If you want to see old implementation, go to `_pages/index.js`</ h2 >
11+ < Link href = "/about" > About page</ Link >
12+ </ >
13+ )
14+ }
Original file line number Diff line number Diff line change 1+ Implementation for Next 13+ using the App Router.
You can’t perform that action at this time.
0 commit comments