Events Tracking Guide
In this guide: Learn how to use the Li2 Analytics SDK to track lead events (signups, form submissions) and sale events (purchases, subscriptions) with real-world examples.
Prerequisites
Before tracking events, ensure you have:SDK Installed
Completed the Setup Guide and installed Li2 Analytics SDK
Tracking Enabled
Enabled conversion tracking for your touchpoint in Settings
Lead Tracking
A lead event marks when a customer shows genuine interest in your product or service. This is a critical middle step between visit and sale.When to Track Leads?
Form Submissions
Form Submissions
When customers fill out contact forms, request consultations, or ask for demos.Examples: “Contact us” forms, “Schedule demo” forms, “Get a quote”
Account Signups
Account Signups
When customers create new accounts or sign up for trials.Examples: Free plan signup, Start trial, Create account
Newsletter Subscriptions
Newsletter Subscriptions
High-Intent Actions
High-Intent Actions
When customers perform high-intent actions.Examples: Add to cart, Download whitepaper, View pricing page
How to Track Leads
- Client-Side (Browser)
- Server-Side (Node.js)
Use when: Tracking directly in the browser after user submits a form or signs up.
Automatic Click ID: The SDK automatically retrieves the click ID from the
li_cid cookie - you don’t need to pass it manually.Lead Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
eventName | string | ✅ | Name of the lead event (e.g., “Signup”, “Contact Form”) |
customerExternalId | string | ✅ | Customer ID in your system |
customerEmail | string | ⚪ | Customer email (recommended) |
customerName | string | ⚪ | Customer name |
customerAvatar | string | ⚪ | Avatar URL |
metadata | object | ⚪ | Additional data (max 10,000 chars) |
clickId | string | Server only | Click ID (only needed for server-side tracking) |
Sale Tracking
A sale event marks successful conversion - the customer has completed a purchase transaction.When to Track Sales?
E-commerce Purchases
E-commerce Purchases
When customers complete payment and the order is confirmed.Timing: After payment processor confirms success (webhook from Stripe, PayPal, etc.)
Subscription Payments
Subscription Payments
When customers subscribe to a paid plan (monthly/annual).Timing: After first payment succeeds or trial converts to paid
One-time Services
One-time Services
When customers pay for services (consulting, booking, etc.).Timing: After payment confirmed or booking confirmed with payment
How to Track Sales
- Client-Side (Browser)
- Server-Side (Webhook)
Use when: Tracking immediately after checkout success on thank-you page.
Sale Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
customerExternalId | string | ✅ | Customer ID (must match lead event) |
amount | number | ✅ | Amount (smallest unit: cents, pence) |
eventName | string | ⚪ | Sale event name (default: “Purchase”) |
currency | string | ⚪ | Currency code (default: “usd”) |
invoiceId | string | ⚪ | Invoice/transaction ID (for deduplication) |
paymentProcessor | string | ⚪ | Payment processor (“stripe”, “paypal”, etc.) |
customerEmail | string | ⚪ | Email (auto-creates customer if not found) |
customerName | string | ⚪ | Customer name |
metadata | object | ⚪ | Additional data (max 10,000 chars) |
clickId | string | Server only | Click ID (only needed for server-side tracking) |
Multi-currency Support: Li2 currently supports revenue tracking in 2 currencies:
- USD (US Dollar):
currency: "usd" - VND (Vietnamese Dong):
currency: "vnd" - Li2 automatically converts to your organization’s default currency for total revenue calculation
- Original currency is preserved in event data
Common Use Cases
- SaaS Signup → Subscription
- E-commerce: Product Purchase
- Lead Gen: Form → Consultation Booking
Funnel: Visit → Trial Signup → Paid Subscription
Step 1: User clicks touchpoint linkBest Practices
1. Consistent customerExternalId Across Events
1. Consistent customerExternalId Across Events
CRITICAL: Use the SAME Why: Li2 uses
customerExternalId for both lead and sale events for the same customer.customerExternalId to link lead → sale and aggregate metrics.2. Track Sales Server-Side (Recommended)
2. Track Sales Server-Side (Recommended)
Why track sales from server:
- ✅ Fraud prevention: Users can’t fake sale events
- ✅ Accuracy: Webhook confirms payment actually succeeded
- ✅ Reliability: Not affected by ad blockers or network issues
3. Use invoiceId to Handle Webhook Retries
3. Use invoiceId to Handle Webhook Retries
When webhooks retry (Stripe, PayPal typically retry on timeout), How it works:
invoiceId helps Li2 prevent duplicates within a 7-day window:- Within 7 days: Li2 caches and returns the old response, no duplicate created
- After 7 days: Cache expires, may create a new sale event if sent again
4. Metadata for Reporting & Analysis
4. Metadata for Reporting & Analysis
Store additional information in
metadata for later analysis:Metadata limit: 10,000 characters (JSON stringified)
5. Handle Errors Gracefully
5. Handle Errors Gracefully
Tracking failures shouldn’t block user experience:
Utility Functions
Li2 Analytics SDK provides helper functions:isTrackingAvailable()
Check if a click ID is available (did the user come from a tracked link):getClickId()
Get the current click ID (useful when you need to send it to your server):Troubleshooting
Lead/Sale not showing in dashboard?
Lead/Sale not showing in dashboard?
Checklist:
-
Verify response: Check console or Network tab
-
Click ID available?
-
Touchpoint has conversion tracking enabled?
- Go to touchpoint Settings → Conversion Tracking must be ON
-
Allowed hostnames configured?
- Settings → Analytics → Allowed Hostnames must include current domain
-
Publishable key correct?
- Verify key in script tag matches Settings → Analytics
Error: 'customerExternalId is required'
Error: 'customerExternalId is required'
Sale not linked to Lead?
Sale not linked to Lead?
Common cause: Verify: Check customer profile in dashboard to see if it has both lead and sale events.
customerExternalId doesn’t match.Revenue is incorrect?
Revenue is incorrect?
Check amount format: Must use smallest currency unitVND Example:
Server-side tracking: 'clickId is required'
Server-side tracking: 'clickId is required'
Server cannot auto-detect click ID. You MUST capture it from the client:

