Li2 Analytics SDK for conversion tracking
npm install @li2/analyticsConversion tracking SDK for Li2.ai. Track leads and sales from your marketing campaigns with automatic click ID attribution.
``bash`
npm install @li2/analyticsor
pnpm add @li2/analyticsor
yarn add @li2/analytics
The client-side SDK automatically captures click IDs from URLs (?uid=...) and cookies, making it easy to track conversions in the browser. You don't need to pass clickId manually - it's auto-detected.
> Note: If you need to track conversions on the server (e.g., after a webhook or server-side payment confirmation), use getClickId() to capture the click ID on the client and pass it to your server. See Server-Side SDK for details.
Add this snippet to your
tag. It loads the SDK asynchronously and queues any tracking calls made before the script loads.`html
`$3
`html
src="https://unpkg.com/@li2/analytics/dist/index.global.js"
data-publishable-key="li2_pk_..."
>
`$3
| Attribute | Description |
| --------- | ----------- |
|
data-publishable-key | Your publishable API key (li2_pk_...) |
| data-api-url | Custom API endpoint (default: https://api.li2.ai) |
| data-debug | Enable debug logging (presence enables, no value needed) |
| data-cookie-options | JSON object for cookie customization (see below) |
| data-outbound | JSON array of domains for outbound link tracking (e.g., ["partner.com"]) |$3
By default, the SDK stores the click ID in a cookie scoped to the current domain with a 30-day expiration. Use
data-cookie-options for cross-domain tracking or custom expiration.`html
src="https://unpkg.com/@li2/analytics/dist/index.global.js"
data-publishable-key="li2_pk_..."
data-cookie-options='{"domain":".example.com","expiresInDays":60}'
>
`| Property | Type | Default | Description |
| -------- | ---- | ------- | ----------- |
|
domain | string | (current domain) | Cookie domain for cross-subdomain tracking (e.g., .example.com) |
| expiresInDays | number | 30 | Days until the cookie expires |
| path | string | "/" | Cookie path |Cross-domain tracking example: If users land on
www.example.com but convert on app.example.com, set domain to .example.com to share the click ID across subdomains.$3
Automatically append click IDs to outbound links and iframes pointing to specified domains. This is useful for tracking conversions across multiple domains or passing attribution data to partner sites.
Key Benefits:
- ✅ Reduced bundle size - Only loads when configured (separate module)
- ✅ Automatic tracking - No manual link modification needed
- ✅ Dynamic content support - Tracks links added after page load
- ✅ SPA compatible - Works with client-side routing
#### Script Tag Usage
Add the
data-outbound attribute with a JSON array of domains to track:`html
src="https://unpkg.com/@li2/analytics/dist/index.global.js"
data-publishable-key="li2_pk_..."
data-outbound='["partner.com", "checkout.example.com"]'
>
`The SDK will automatically:
1. Find all
and