Tracking Product Interactions
Example usage with Next.js
Using DPC as a client-side library
Since DPC handles tracking by observing the DOM it can only run in the browser. This requires DPC to be loaded in a way so that it’s not executed on the server when using a framework capable of Server-side rendering (SSR) like Next.js.
Initializing DPC in your entry point
In Next.js you can make sure code is only executed client-side by checking typeof window !== "undefined"
. Since we are importing DPC as a module we can’t do it the with the normal import { DPC } from "depict-ai/dpc"
syntax. Instead, we can use dynamic imports. This is also documented by Next.js.
TypeScript
Was this page helpful?