Skip to main content
The Knock2 tracking script is the foundation of your visitor identification pipeline. Once embedded in your site’s <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 a script_url and a ready-to-paste embed_html tag pre-configured with your tenant slug.
Copy the 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).

Identify Known Visitors

Everything above is inferred identification — Knock2 matches a visitor’s IP and browsing behavior to a company and, where possible, a person. When your own site already knows who a visitor is — they log in, sign up, or submit a form you’ve wired up yourself — you can tell Knock2 directly and skip the guesswork for that visitor. Once the tracking script has loaded, call window.knock2.identify() with the visitor’s email:
You can optionally pass a second traits argument with any additional attributes you want to record alongside the email:
Call this as soon as you know who the visitor is — typically right after a successful login or signup, the same moment you’d call an analytics tool’s own identify() method.
window.knock2.identify() only runs once the tracking script has loaded. Guard calls that might fire before that (e.g. on your very first paint) with window.knock2?.identify?.(email), or call it from code that only runs after your page has fully loaded.
A visitor who has opted out via Global Privacy Control or your site’s own privacy preferences is automatically excluded — calling identify() for an opted-out visitor is a no-op, and nothing is sent to Knock2.
A confirmed identity recorded this way is kept separate from Knock2’s inferred contact and company records. It does not automatically change or correct an existing contact or company in your workspace.

Pass Your Own IDs

window.knock2 exposes a few other methods alongside identify():
  • window.knock2.setExternalId(...) — hand Knock2 your own ID for a visit (a chat session ID, a user ID), and get it back on every identification of that visitor so you can join it to your own record.
  • window.knock2.getVisitorId() — read Knock2’s own visitor ID for this browser, for customers who would rather store ours.
  • window.knock2.ready(fn) — run code only once the script is live on the page.
See Pass Your Own IDs for the full reference, including the queue snippet for calling setExternalId before the tracking script has loaded.

React to Identification in the Browser

Once the script is installed, you can also get a browser event the moment Knock2 identifies a visitor’s company, with their ICP score and inferred persona, to fire ad conversions or personalize the page. See Website events.

Framework-Specific Tips

Pages Router (_document.js)Add the script tag inside the <Head> component in pages/_document.js:
App Router (app/layout.tsx)Use the Next.js <Script> component with strategy="afterInteractive" inside your root layout:
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.
  1. Open your Webflow project and go to Site Settings → Custom Code.
  2. Paste your embed_html snippet into the Head Code text area.
  3. Click Save Changes, then publish your site.
The script will load on every page of your published Webflow site. If you only want to track specific pages, use Webflow’s per-page Custom Code section (available on paid plans) under Page Settings → Custom Code → Head Code.
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.