Skip to content

Commit

Permalink
fix(with-facebook-pixel): prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
niko20 committed May 19, 2023
1 parent e62c64a commit 91260a9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 49 deletions.
8 changes: 3 additions & 5 deletions examples/with-facebook-pixel/app/about/page.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import Link from "next/link";
import Link from 'next/link'

export default function About() {
return (
<>
<h1>About</h1>

<Link href="/">
back to home
</Link>
<Link href="/">back to home</Link>
</>
);
)
}
26 changes: 13 additions & 13 deletions examples/with-facebook-pixel/app/components/FacebookPixel.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
'use client';
'use client'

import { usePathname } from 'next/navigation';
import Script from 'next/script';
import { useEffect, useState } from 'react';
import * as pixel from '/lib/fpixel';
import { usePathname } from 'next/navigation'
import Script from 'next/script'
import { useEffect, useState } from 'react'
import * as pixel from '/lib/fpixel'

const FacebookPixel = () => {
const [loaded, setLoaded] = useState(false);
const pathname = usePathname();
const [loaded, setLoaded] = useState(false)
const pathname = usePathname()

useEffect(() => {
if (!loaded) return;
if (!loaded) return

pixel.pageview();
}, [pathname, loaded]);
pixel.pageview()
}, [pathname, loaded])

return (
<div>
Expand All @@ -25,7 +25,7 @@ const FacebookPixel = () => {
data-pixel-id={pixel.FB_PIXEL_ID}
/>
</div>
);
};
)
}

export default FacebookPixel;
export default FacebookPixel
2 changes: 1 addition & 1 deletion examples/with-facebook-pixel/app/components/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as FacebookPixel } from './FacebookPixel';
export { default as FacebookPixel } from './FacebookPixel'
8 changes: 3 additions & 5 deletions examples/with-facebook-pixel/app/layout.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { FacebookPixel } from './components';
import { FacebookPixel } from './components'

export default function RootLayout({
children,
}) {
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
{children}
<FacebookPixel />
</body>
</html>
);
)
}
15 changes: 6 additions & 9 deletions examples/with-facebook-pixel/app/page.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import Link from "next/link";
import Link from 'next/link'

export default function Home() {
return (
<>
<h2>
Go to `app/layout.js` to see how implement Facebook Pixel in NextJS ˆ13 with app folder
Go to `app/layout.js` to see how implement Facebook Pixel in NextJS ˆ13
with app folder
</h2>
<h2>
If you want to see old implementation, go to `_pages/index.js`
</h2>
<Link href="/about">
About page
</Link>
<h2>If you want to see old implementation, go to `_pages/index.js`</h2>
<Link href="/about">About page</Link>
</>
);
)
}
37 changes: 21 additions & 16 deletions examples/with-facebook-pixel/public/scripts/pixel.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
const PIXEL_ID = document.currentScript.getAttribute('data-pixel-id')

function initializeFacebookPixel(f, b, e, v, n, t, s) {
if(f.fbq) return;
n = f.fbq = function() {
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
};
if(!f._fbq) f._fbq = n;
n.push = n;
n.loaded = !0;
n.version = '2.0';
n.queue = [];
t = b.createElement(e);
t.async = !0;
t.src = v;
s = b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t, s);
if (f.fbq) return
n = f.fbq = function () {
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments)
}
if (!f._fbq) f._fbq = n
n.push = n
n.loaded = !0
n.version = '2.0'
n.queue = []
t = b.createElement(e)
t.async = !0
t.src = v
s = b.getElementsByTagName(e)[0]
s.parentNode.insertBefore(t, s)
}

initializeFacebookPixel(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
initializeFacebookPixel(
window,
document,
'script',
'https://connect.facebook.net/en_US/fbevents.js'
)

window.fbq('init', PIXEL_ID);
window.fbq('init', PIXEL_ID)

0 comments on commit 91260a9

Please sign in to comment.