Security, Tech & Programming
How to add custom inline javascript to NextJs

How to add custom inline javascript to NextJs

Use the following method to include the custom javascript code as inline javascript on your nextjs page:

NextJs add Script inline

// import next/script on top of the file
import Script from "next/script";

// add following code where you want javascript output to be added:
// node that id is required
<Script id="custom-id">
      console.log("ping - pong, working!");

Replace the content inside {` ... `} with whatever you want to output.

How to add Facebook Pixel to nextjs page

To add facebook pixel, get your facebook pixel code and place it where you want to show this code in your files: (replace YOUR-FB-PIXEL-ID-HERE with your own here, or simply use the complete code from facebook)

        s.parentNode.insertBefore(t,s)}(window, document,'script',
        fbq('init', 'YOUR-FB-PIXEL-ID-HERE');
        fbq('track', 'PageView');

For more scenarios and details, see this link:

Leave a Reply

Your email address will not be published. Required fields are marked *

Hire Me!