Unverified Commit 2b88467d authored by Luke Shumard's avatar Luke Shumard Committed by GitHub

Example/facebook pixel script (#34417)

The [with-facebook-pixel](https://github.com/vercel/next.js/tree/canary/examples/with-facebook-pixel) example attempts to run the <Script /> loading the Facebook Pixel on every request. This results in a warning stating `[Meta Pixel] - Duplicate Pixel ID: xxx`. According to the Next.js docs, by using an [id on the inline script](https://nextjs.org/docs/basic-features/script#inline-scripts) Next is able to track and optimize the script. Since this is absent on the present example, the inline script is continuously loaded on every request.

I've added an id to this inline script, and the warning from facebook is no longer present.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
Co-authored-by: 's avatarBalázs Orbán <18369201+balazsorban44@users.noreply.github.com>
parent 521f88e1
......@@ -24,6 +24,7 @@ function MyApp({ Component, pageProps }) {
<>
{/* Global Site Code Pixel - Facebook Pixel */}
<Script
id="fb-pixel"
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `
......
import Link from 'next/link'
import * as fbq from '../lib/fpixel'
export default function Home() {
......@@ -14,6 +15,13 @@ export default function Home() {
<button type="button" onClick={handleClick}>
Buy $10
</button>
<p>
Click the link below to navigate to another page.
<br />
<Link href="/navigation">
<a>Navigation page</a>
</Link>
</p>
</div>
)
}
import Link from 'next/link'
export default function NavigationPage() {
return (
<div>
<p>
Navigating between pages will trigger a pageview event in Facebook
Pixel, but will not reinitialize the pixel.
</p>
<Link href="/">
<a>Return to home</a>
</Link>
</div>
)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment