Skip to main content
Dub’s client-side SDKs enable you to track clicks, conversions, and user attribution directly on your website. These tools work seamlessly with the server-side SDKs to provide complete attribution tracking.

Available Client-Side Tools

Analytics Script

Lightweight JavaScript snippet for any website

React

React component for analytics and embeds

Next.js

Next.js integration with App Router support

How It Works

Client-side tracking enables end-to-end conversion attribution:
1

User Clicks Short Link

A user clicks your Dub short link with a unique click ID
2

Click ID Stored

The Dub script automatically stores the click ID as a first-party cookie
3

User Converts

When the user signs up or makes a purchase, you track the conversion
4

Attribution Matched

Dub matches the conversion to the original click for complete attribution

Features

All client-side tools provide:
  • Automatic Click Tracking - Stores click IDs from Dub short links
  • First-Party Cookies - Uses your domain for better privacy and tracking
  • Conversion Events - Track leads, sales, and custom events
  • Privacy Compliant - No third-party tracking or PII storage
  • Lightweight - Minimal performance impact on your site

Installation Methods

Choose the installation method that fits your tech stack:

Vanilla JavaScript

Add the analytics script to any HTML website:
<script 
  defer
  src="https://www.dubcdn.com/analytics/script.js" 
></script>

React/Next.js

Install the @dub/analytics package:
npm install @dub/analytics

Google Tag Manager

Add the Dub script through GTM for centralized tag management.

Tracking Conversions

After installing the client-side script, use the server-side SDK to track conversions:
import { Dub } from "dub";

const dub = new Dub({ token: process.env.DUB_API_KEY });

// Track a lead conversion
await dub.track.lead({
  clickId: dubId, // From cookie
  eventName: "Sign Up",
  customerExternalId: user.id,
  customerEmail: user.email,
});
The Dub script stores click IDs in a first-party cookie:
  • Cookie Name: dub_id
  • Domain: Your website domain
  • Duration: 30 days (configurable)
  • SameSite: Lax
  • Secure: true (HTTPS only)

Privacy Considerations

  • No personal data is stored in cookies
  • Only anonymous click IDs are tracked
  • Fully compliant with GDPR and privacy regulations
  • First-party cookies for better browser compatibility

Next Steps

Choose your implementation method:

Analytics Script

Add to any HTML website

React Component

Use in React applications

Next.js Integration

Integrate with Next.js

Track Conversions

Learn about conversion tracking

Build docs developers (and LLMs) love