Install and configure the Icodrip JavaScript SDK for client-side tracking and event logging.
The Icodrip SDK is a lightweight JavaScript library (under 2KB gzipped) that handles client-side tracking. It manages cookie reading, visitor identification, and event tracking without requiring any server-side code changes.
The SDK is designed to work with any JavaScript environment — vanilla websites, React, Next.js, Vue, Svelte, or any other framework. It has zero dependencies and loads asynchronously to avoid impacting your page performance.
Use the SDK when you want to track conversions on the client side, identify visitors who arrived through affiliate links, or send custom events to Icodrip for flexible attribution scenarios.
There are two ways to install the SDK. For projects using a package manager, install via npm: npm install @icodrip/sdk. Then import and initialize it in your application code.
For websites without a build system, include the SDK via a script tag. Add the following to your HTML just before the closing </head> tag: <script src="https://icodrip.com/v1/ak.js" data-org="your-org-slug" async></script>. The script loads asynchronously and initializes automatically.
The npm package includes TypeScript type definitions out of the box. No separate @types package is needed. The SDK exposes a clean, typed API for all its methods.
After installing the SDK, initialize it with your program's public key. The public key is different from your API key — it is safe to include in client-side code. Find your public key in Settings > SDK in your dashboard.
For the npm package, import the SDK and call the init function with your public key and optional configuration. The SDK automatically detects if the current visitor arrived via an affiliate link by checking for the tracking cookie.
The script tag version initializes automatically using the data-program attribute. No additional JavaScript code is needed for basic tracking. The SDK reads the cookie set by the click tracking redirect and stores the affiliate attribution for later use.
The SDK provides a track method for logging conversion events. Call icodrip.track('purchase', { amount: 4999 }) when a purchase occurs. The amount should be in cents (4999 = $49.99). The SDK automatically includes the visitor's affiliate attribution in the event.
You can track any custom event type — not just purchases. Common events include signup, trial_start, upgrade, and add_to_cart. Custom events can be used for multi-step attribution funnels or to award commissions on non-payment events.
Each tracked event is sent to Icodrip's API endpoint as a lightweight POST request. The SDK batches events when multiple events occur in rapid succession (within 100ms) to minimize network requests.
The SDK supports several configuration options. Set the cookie domain to share tracking across subdomains (e.g., .yourcompany.com). Configure the API endpoint if you are using a custom domain for your Icodrip instance.
Enable debug mode during development to log all SDK activity to the browser console. This shows cookie reads, event tracking calls, and API responses. Disable debug mode in production to avoid cluttering the console.
For single-page applications (SPAs), the SDK automatically handles client-side navigation. It listens for URL changes and checks for affiliate parameters on each navigation. If your SPA uses hash-based routing, enable the hashMode option to ensure tracking works correctly across route changes.