Integrating a Vanilla Next.js Application with Sitecore CDP using Engage SDK
If you're working with a vanilla version of Next.js and need to integrate it with Sitecore CDP, this blog will walk you through using the Engage SDK to send behavioral and identity data to Sitecore CDP.
Note: If you're using the XM Cloud Starter Kit, you can skip this guide — . This guide is only applicable for standalone (vanilla) Next.js applications.
đ§Š Why Use Engage SDK?
Sitecore CDP's Engage SDK allows developers to:
-
Track user behaviors such as page views.
-
Identify users using custom identifiers (e.g., email).
-
Send data to Sitecore CDP in real time.
✅ Prerequisites
-
A vanilla Next.js project (not the XM Cloud starter).
-
Sitecore CDP access with appropriate client credentials.
-
A Point of Sale (POS) configured in CDP.
đ Steps to Integrate Engage SDK with Next.js
1. Create a Vanilla Next.js Project
We won’t go into details here — this guide assumes you're already familiar with setting up a Next.js app.
2. Install Engage SDK
Run the following command to install Sitecore’s Engage SDK:
3. Configure Environment Variables
Create a .env.local file in the root of your project (not inside /src) and add the following:
How to find these values:
-
NEXT_PUBLIC_CDP_CLIENT_KEY: Available in your Sitecore CDP instance under API Access. -
NEXT_PUBLIC_CDP_POINTOFSALE: You can create a new POS in Sitecore CDP. This is used to segment and track data effectively.
4. Initialize the Engage SDK
Create a file called engage.ts inside the /src folder:
5. Create a Component to Trigger PageView & Identity Events
Create a component called CdpPageviewengage.tsx inside the /components folder:
6. Import the Component in Your Layout
To ensure events are fired on each page load, import the CdpPageviewengage component into your main layout component (e.g., _app.tsx or wherever your layout is defined):
✅ Verification Steps
Once everything is wired up, here’s how to validate the integration:
-
Browser Cookies: Check the
bx_guest_refcookie in DevTools > Application > Cookies.
-
Network Tab: You should see network requests for:
-
PageViewevent -
Identityevent
-
Sitecore CDP:
-
Log into your CDP instance.
-
Search by
bx_guest_refcookie value. -
You should see the guest profile and associated data.
đ GitHub Repo
You can find the full implementation in this GitHub repository
đ§ Final Thoughts
Using the Engage SDK is a straightforward way to connect a vanilla Next.js app with Sitecore CDP for personalized tracking and customer identification. Once implemented correctly, you unlock the power of Sitecore CDP to deliver real-time personalization and deep customer insights.
Happy coding! đ
Comments
Post a Comment