<head>, it silently captures session data for every visitor and sends it to Knock2’s identification engine — no personally identifiable information is collected on the client side, and the script never blocks your page from loading.
Get the Embed Snippet
Fetch your personalized embed snippet from the API. The response includes ascript_url and a ready-to-paste embed_html tag pre-configured with your tenant slug.
embed_html value exactly as returned. The script is served directly from Knock2’s API (not a separate CDN domain) — the tenant slug is resolved server-side from your API key and baked into the URL path, so there’s no data-slug attribute to configure.
Add the Script to Your Site
1
Copy the embed HTML
Copy the full value of
embed_html from the API response above. It looks like:2
Paste it inside your site's <head> tag
Place the snippet before the closing
</head> tag on every page you want to track. A typical HTML document looks like this:3
Deploy your site
Publish the change through your normal deployment process. The script will begin collecting visitor data as soon as the updated page is live and receives its first non-localhost visit.
Verify Installation
Once your site is live, confirm that Knock2 is receiving data by calling the script status endpoint.
If
is_installed is false after deploying, double-check that the snippet is present in the rendered HTML of your live site (use your browser’s View Source or DevTools Network tab to confirm the request to your /install/{your_tenant}/prod script URL loads).
Framework-Specific Tips
Next.js
Next.js
Pages Router (App Router (
_document.js)Add the script tag inside the <Head> component in pages/_document.js:app/layout.tsx)Use the Next.js <Script> component with strategy="afterInteractive" inside your root layout:WordPress
WordPress
Option 1 — Header pluginInstall a plugin such as Insert Headers and Footers or WPCode, paste your
embed_html snippet into the Header section, and save. The plugin injects the tag site-wide without touching theme files.Option 2 — Theme CustomizerGo to Appearance → Customize → Additional CSS / Custom Scripts (exact label varies by theme). Some themes expose a Custom Header Code field — paste the snippet there. If your theme doesn’t support this natively, use the plugin approach instead to avoid losing the tag on theme updates.Webflow
Webflow
- Open your Webflow project and go to Site Settings → Custom Code.
- Paste your
embed_htmlsnippet into the Head Code text area. - Click Save Changes, then publish your site.
Single Page Apps (React, Vue, Angular, etc.)
Single Page Apps (React, Vue, Angular, etc.)
Add the snippet once to the
index.html file that serves as your app’s shell — typically public/index.html for Create React App / Vite projects. The tracking script listens for browser popstate and hashchange events and intercepts history.pushState calls, so it automatically tracks navigation between client-side routes without any additional configuration.You do not need to call any JavaScript function on each route change — the script handles this transparently.The script is loaded with the
async attribute and has no impact on page load performance. It will never block rendering or delay your site’s DOMContentLoaded event.