Step 1 - Get Stiddle Pixel
Navigate to settings screen, select the pixel tab, and click ‘Copy Pixel Code’ under ‘Stiddle Pixel for Shopify’. If the code is successfully copied to your clipboard, you should see a toaster on the top right of your screen like this:Step 2 - Setup the Non-Checkout Pages
There are three ways to integrate the Stiddle Pixel with a NextJS store. We strongly suggest opting for method #1 as the primary choice. Method #2 should only be considered if method #1 fails to function properly. Method #3 should only be considered if method #1 and method #2 fails to function properly. You only need to implement any of the three methods.Method #1 (Recommended)
- Locate your base layout file. Using the NextJS 14 recommended layout above - you can locate the layout.js file (or layout.tsx if you’re using ts) within your frontend repository. This file should be found within src folder -> app folder -> layout.js
Alternatively, you can also locate a page like _app.tsx or _app.js within the pages folder that can be found with src folder -> pages folder -> _app.tsx - Import Head from ‘next/head’ and create a <Head><Head/> tag pair above component like the example below.
- Then create a div tag and use dangerouslySetInnerHTML to create the following code snippet:
Method #2 - Use public/static (Recommended Fallback)
- Create a folder for your static files in :
<root>/public/static/script.js
- Then, in the index.js at
<root>/pages/index.js, paste the script in between the <Head /> tags.
Method #3 - Modify Root Layout (Less Recommended Fallback)
Next.js uses a root layout component to wrap all pages. We’ll modify this component to include the Stiddle Pixel script.Step 1: Convert the Stiddle Pixel into a NextJS Script Component
Let’s start with the original script tag you want to convert:<script type="text/javascript" defer src="//tracking.stiddlepixel.com/" id="stiddle-script" apiKey="SOME API KEY"></script>
1. Identify the Attributes of the Script Tag
The original script tag has several attributes:- type=“text/javascript”
- defer
- src=“//tracking.stiddlepixel.com/”
- id=“stiddle-script”
- apiKey=“SOME API KEY”
2. Install Next.js Script Component
Next.js provides aScript component to manage script loading. First, ensure you have Next.js installed and set up.
3. Import the Script Component
In the file where you want to include the script (typically_app.js or _app.tsx), import the Script component from next/script.
Add import Script from 'next/script'; to the top of your file.
4. Use the Script Component
Replace the traditional script tag with theScript component from Next.js.
- Replace src attribute. Use the src prop.
- Replace ‘id’ attribute. Use the id prop.
- Set ‘strategy’ prop. Use
strategy="lazyOnload"to defer loading. - Embed the
apiKeyas a query parameter in thesrcURL.
- Add the Script tag we created before the closing body tag in _app.js
Step 3 - Setup the checkout page
If you are using customer events, refer to this guide. If you’re currently utilizing checkout.liquid in conjunction with extra checkout script, it’s recommended to shift to customer events with the provided instructions, as Shopify will be phasing out the extra checkout script by August 2024.Step 4 - Test your store to confirm that Stiddle is tracking properly.
1. Run Your Next.js Application
Start your Next.js application using the following command:npm run dev
Open your browser and navigate to the URL where your application is running (e.g., http://localhost:3000 or your real domain if changes have been published).
2. Open Developer Tools
Right-click anywhere on the page and select “Inspect” or press Ctrl+Shift+I for Windows and Linux or Cmd+Option+I for Mac to open the browser developer tools.3. Go to the Network Tab
In the Developer Tools, click on the “Network” tab. This tab allows you to see all network requests made by the page.4. Filter Network Requests
- In the “Network” tab, locate the “Filter” box.
- Type ‘track’ in the filter box to narrow down the list of network requests to only those that contain “track” in the URL. This helps you find the Stiddle Pixel’s tracking calls.
5. Check the Network Request
- Look for a network request to ‘api.stiddle.com/api/v1/contacts/track’. The filtered results should help you identify this request quickly.
- Click on this request to view its details.
6. Verify the Response
- In the details pane for the network request, check the “Status” column.
- Ensure the status code is ‘201 Created’, indicating a successful request.
7. Inspect Response Details
- After clicking on the network request, a new pane will show detailed information about the request.
- Optionally, check the profiles section of the platform to verify that your request has been saved correctly in our database.