Skip to content
KnockDevelopers

Install the SDK

Add Knock to your logged-in app with @knock-ai/sdk to identify people, track events and open your scheduling modal.

Chat with a Developer

@knock-ai/sdk is the SDK for your logged-in app. init() loads your Knock product tag, then your code identifies people, tracks events and opens your scheduling modal.

Get it from npm. The source is on GitHub.

Quickstart

You need your Product tag ID. In Knock, go to Settings > Administration > Tracking Codes and copy it from the Add Knock to your App card. If you don't see the card, ask your Knock contact.

Install with your AI agent

Terminal
npx skills add knock-org/knock-sdk

Then ask your agent:

Claude Code
/install-knock-sdk product=<your-product-tag-id> events=signed_up,plan_upgraded

In Codex, type $install-knock-sdk. In other agents, ask "Install the Knock SDK" with the same product= and events=.

Replace <your-product-tag-id> with your ID and list the events you want to track, in snake_case and the past tense. events= is optional: without it, the agent suggests some. The agent shows you a plan and waits for your yes before it changes anything. It never commits.

Install manually

Terminal
npm install @knock-ai/sdk
Core calls
import { knock } from '@knock-ai/sdk';

// 1. Load your product tag, once
knock.init({ tagId: 'YOUR_PRODUCT_TAG_ID' });

// 2. Identify the signed-in person (email is required)
knock.identify({ email: user.email, firstName: user.firstName });

// 3. Track what they do
knock.track('trial_started', { plan: 'pro' });

// 4. Open your scheduling modal, or load it first and open it later
knock.modal.open({ magicLinkId: 'YOUR_MAGIC_LINK_ID' });
const scheduling = knock.scheduling.load({ magicLinkId: 'YOUR_MAGIC_LINK_ID' });
scheduling.open();

// 5. Open a Knock chat link and keep the person's identity
window.open(knock.wrapLink('https://start-chat.com/slack/acme/sales'));

Calls made before your tag has loaded are queued, so you never wait for it. On the server, every call does nothing.

Product tag or website tag

Your Knock workspace has two tags, and init() loads one of them. The API is the same on both.

  • Product tag, in your logged-in app: identify() tells Knock which signed-in customer this is. Only your track() and identify() calls are sent, plus clicks on Knock's widget if you show it.
  • Website tag, on your marketing site: identify() captures a lead, and the tag also captures what it's set up to capture (page views, clicks, forms). Use its ID instead, for example in VITE_KNOCK_WEBSITE_TAG_ID. It's the part of your Knock tag's script URL between js.knock-ai.com/ and .js.

A page runs one tag: the first init() wins. If the page already has a Knock tag <script>, the SDK uses that tag instead of loading a second one.

Next steps

Chat with a Developer

On this page