npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@netzkombyse/facebook-conversion-api-nextjs

v1.1.6

Published

Facebook Conversion API for Next.js based on RivercodeAB

Downloads

208

Readme

Next.js wrapper for Facebook's Conversion API

This package is forked from @rivercode/facebook-conversion-api-nextjs

Facebook / Meta Conversion API for Next.js

This package helps you implement Facebook Conversion API in Next.js.

It includes an API route handler for sending server-side events to Facebook and client-side functions to trigger the events.

Facebook recommends sending events with Facebook Pixel and the Conversion API with the same event id to match duplicated events.

Therefore, we have added the option to enable standard Facebook Pixel events in this package, where we handle duplicated events out of the box.

Support Next.js API routes on both Vercel and AWS Amplify.

Install

NPM

npm install @netzkombyse/facebook-conversion-api-nextjs

Yarn

yarn add @netzkombyse/facebook-conversion-api-nextjs

1. Create Next.js API Route

pages/api/fb-events.js

import { fbEventsHandler } from '@netzkombyse/facebook-conversion-api-nextjs/handlers';

export default fbEventsHandler;

Add Facebook Access Token and Pixel ID

.env

FB_ACCESS_TOKEN=accessToken
NEXT_PUBLIC_FB_PIXEL_ID=pixelId
NEXT_PUBLIC_FB_DEBUG=true # optional

Read more here on how you can get your access token and pixel id.

2. Load Facebook Pixel (Optional)

This is only needed if you want to fire standard Pixel Events.

Add Facebook Pixel Provider & Script

pages/_app.js

import { FBPixelScript, FBPixelProvider } from '@netzkombyse/facebook-conversion-api-nextjs/components';

...
<>
  <FBPixelScript />
  <FBPixelProvider>
    <Component {...pageProps} />
  </FBPixelProvider>
</>
...

3. Start Sending Events

Trigger the events you need. For example, add to cart or purchase events.

import { fbEvent } from '@netzkombyse/facebook-conversion-api-nextjs';

useEffect(() => {
    fbEvent({
        eventName: 'ViewContent', // ViewContent, AddToCart, InitiateCheckout, Purchase etc.
        eventId: 'eventId', // optional, unique event id's will be generated by default
        emails: ['email1', 'email2'], // optional
        phones: ['phone1', 'phone2'], // optional
        firstName: 'firstName', // optional
        lastName: 'lastName', // optional
        country: 'country', // optional
        city: 'city', // optional
        zipCode: 'zipCode', // optional
        contentName: 'Product-Label' // optional
        contentIds: ['123456'], // optional
        numItems: 1, // optional
        products: [{ // optional
            sku: 'product123',
            quantity: 1,
        }],
        value: 1000, // optional
        currency: 'USD', // optional
        enableStandardPixel: false // default false (Require Facebook Pixel to be loaded, see step 2)
    });
}, []);