Skip to main content
Links are the core of Dub’s link attribution platform. Create branded short links with powerful tracking, targeting, and customization options.
1

Navigate to Links

From your workspace dashboard, click “Create Link” or navigate to the Links page.
2

Enter Destination URL

Paste the long URL you want to shorten:
https://github.com/dubinc/dub
Dub will automatically fetch Open Graph metadata (title, description, image) from the destination URL.
3

Customize Short Link

Choose from your workspace domains:
  • Default domain (e.g., dub.sh)
  • Custom domains you’ve added
  • Primary domain is selected by default
4

Configure Link Options (Optional)

Add advanced features to your link (covered in detail below).
5

Create Link

Click “Create” to generate your short link. It’s immediately active and ready to share.

Basic Settings

The target URL where users will be redirected.
{
  url: "https://github.com/dubinc/dub"
}
URLs are stored as LongText in the database to support very long URLs.

Metadata and Appearance

Override the default OG metadata for social sharing:
{
  title: "Dub - Open-Source Link Attribution Platform",
  description: "The modern link attribution platform for short links, conversion tracking, and affiliate programs.",
  image: "https://dub.co/og-image.png",
  proxy: true  // Enable to use custom OG tags
}
When proxy: true, Dub will serve custom OG tags. When proxy: false, OG tags from the destination URL are used.

UTM Parameters

Automatically append UTM tracking parameters to your destination URL:
{
  utm_source: "twitter",
  utm_medium: "social",
  utm_campaign: "product-launch",
  utm_term: "dub",
  utm_content: "announcement"
}
The destination URL will become:
https://github.com/dubinc/dub?utm_source=twitter&utm_medium=social&utm_campaign=product-launch&utm_term=dub&utm_content=announcement
UTM parameters are automatically extracted from your destination URL if already present.

Advanced Targeting

Redirect users to different URLs based on their device:
{
  url: "https://example.com",        // Default URL
  ios: "https://apps.apple.com/app", // iOS devices
  android: "https://play.google.com/store/apps" // Android devices
}
Perfect for directing users to platform-specific app stores or experiences.
Route users to different URLs based on their country:
{
  url: "https://example.com",  // Default
  geo: {
    "US": "https://example.com/us",
    "GB": "https://example.com/uk",
    "FR": "https://example.com/fr"
  }
}
Use ISO 3166-1 alpha-2 country codes.

Conversion Tracking

Track leads and sales attributed to this link:
{
  trackConversion: true
}
When enabled, Dub will:
  • Track click events with unique click IDs
  • Associate leads with the link
  • Attribute sales and conversions
  • Calculate revenue and ROI
See the Tracking Conversions guide for implementation details.
Automatically disable links after a specific date:
{
  expiresAt: "2026-12-31T23:59:59.000Z",
  expiredUrl: "https://example.com/expired"  // Optional redirect
}
Expired links will redirect to expiredUrl if set, otherwise return a 404.

Password Protection

Add password protection to your links:
{
  password: "secret123"
}
Users must enter the password before being redirected.

A/B Testing

Test different destination URLs with traffic splitting:
{
  testVariants: [
    { url: "https://example.com/variant-a", weight: 50 },
    { url: "https://example.com/variant-b", weight: 30 },
    { url: "https://example.com/variant-c", weight: 20 }
  ],
  testStartedAt: "2026-01-01T00:00:00.000Z",
  testCompletedAt: "2026-01-31T23:59:59.000Z"
}
Traffic is distributed based on weights (must sum to 100).
import { Dub } from 'dub';

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

const link = await dub.links.create({
  url: 'https://github.com/dubinc/dub',
  domain: 'dub.sh',
  key: 'github',
  trackConversion: true,
  tagNames: ['github', 'open-source'],
  utm_source: 'twitter',
  utm_medium: 'social',
});

console.log(link.shortLink); // https://dub.sh/github
Complete link object structure:
{
  id: string,                   // Unique link ID (link_xxxxx)
  domain: string,               // Short link domain
  key: string,                  // Short link key/slug
  shortLink: string,            // Full short link URL
  url: string,                  // Destination URL
  archived: boolean,            // Archive status
  expiresAt: Date | null,       // Expiration date
  expiredUrl: string | null,    // Redirect when expired
  password: string | null,      // Password protection
  trackConversion: boolean,     // Conversion tracking enabled
  proxy: boolean,               // Use custom OG tags
  title: string | null,         // OG title
  description: string | null,   // OG description
  image: string | null,         // OG image URL
  
  // UTM Parameters
  utm_source: string | null,
  utm_medium: string | null,
  utm_campaign: string | null,
  utm_term: string | null,
  utm_content: string | null,
  
  // Device & Geo targeting
  ios: string | null,           // iOS redirect URL
  android: string | null,       // Android redirect URL
  geo: object | null,           // Geographic redirects
  
  // A/B Testing
  testVariants: object | null,  // Test configuration
  testStartedAt: Date | null,
  testCompletedAt: Date | null,
  
  // Analytics
  clicks: number,               // Total clicks
  leads: number,                // Total leads
  conversions: number,          // Conversions (leads → sales)
  sales: number,                // Total sales
  saleAmount: number,           // Revenue in cents
  
  // Metadata
  publicStats: boolean,         // Public analytics enabled
  createdAt: Date,              // Creation timestamp
  updatedAt: Date,              // Last update
  lastClicked: Date | null,     // Last click time
}
Group related links in folders:
  • Navigate to Links > Folders
  • Create folders by campaign, product, or channel
  • Drag and drop links into folders
  • Filter analytics by folder

Bulk Operations

View detailed analytics for each link:
  • Clicks: Total clicks over time
  • Locations: Geographic distribution
  • Devices: Desktop, mobile, tablet breakdown
  • Browsers: Browser and OS statistics
  • Referrers: Traffic sources
  • Conversions: Leads and sales attributed
Public analytics can be enabled per link to share statistics via a public URL.

Best Practices

Choose memorable, descriptive keys that hint at the destination:dub.sh/github-repodub.sh/abc123
Always enable conversion tracking for marketing and attribution campaigns to measure ROI.
Use consistent tagging conventions to make filtering and reporting easier:
  • channel:twitter, channel:email
  • campaign:q1-2026, campaign:product-launch
  • type:organic, type:paid
For time-limited campaigns, set expiration dates to automatically disable links and redirect to a fallback page.
Always test your short links before sharing in campaigns to verify:
  • Destination URL is correct
  • UTM parameters are appended
  • Device/geo targeting works
  • OG tags display properly on social media

Build docs developers (and LLMs) love