Installation
Install the required packages:Setup
Environment Variables
Add your Dub API key to.env.local:
Initialize Dub Client
Create a Dub client instance inlib/dub.ts:
Add Analytics Component
App Router
Add the Analytics component to your root layout:Pages Router
Add the Analytics component to_app.tsx:
Configuration
Customize the Analytics component for your domain:Track Conversions
Server Actions (App Router)
Create a server action to track lead conversions:API Routes
Create an API route to track conversions:Track Sales
Track purchase conversions:Link Management
Create and manage short links from your Next.js app:Create Links
List Links
Middleware Integration
Add custom middleware to enhance tracking:Customer Tracking
Retrieve customer information:TypeScript Types
Full type safety with TypeScript:Best Practices
- Store API keys in environment variables
- Track conversions server-side for security
- Clear the
dub_idcookie after tracking - Use server actions for better type safety
- Handle errors gracefully
Example Application
Complete Next.js example with authentication:Next Steps
API Reference
Explore the complete API
Conversion Tracking
Learn about conversions
React Component
React SDK documentation
Server SDKs
Server-side SDKs