What is Dub?
Dub is an open-source link management platform — like Bitly, but with developer-first features: analytics, custom domains, QR codes, and a powerful API. Built with Next.js.
Free tier: 1,000 links, 5,000 tracked clicks/month.
The REST API
export DUB_TOKEN="your-api-key"
Create Short Link
curl -X POST "https://api.dub.co/links" \
-H "Authorization: Bearer $DUB_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"url": "https://dev.to/aandrew_n/my-long-article-url",
"domain": "dub.sh",
"key": "my-article",
"externalId": "article_123"
}'
Result: https://dub.sh/my-article
Get Link Analytics
# Click count
curl "https://api.dub.co/analytics?linkId=LINK_ID&event=clicks" \
-H "Authorization: Bearer $DUB_TOKEN"
# Clicks by country
curl "https://api.dub.co/analytics?linkId=LINK_ID&event=clicks&groupBy=country" \
-H "Authorization: Bearer $DUB_TOKEN"
# Clicks by device
curl "https://api.dub.co/analytics?linkId=LINK_ID&event=clicks&groupBy=device" \
-H "Authorization: Bearer $DUB_TOKEN"
# Clicks over time
curl "https://api.dub.co/analytics?linkId=LINK_ID&event=clicks&groupBy=timeseries&interval=7d" \
-H "Authorization: Bearer $DUB_TOKEN"
Bulk Create Links
curl -X POST "https://api.dub.co/links/bulk" \
-H "Authorization: Bearer $DUB_TOKEN" \
-d '[
{"url": "https://example.com/page-1", "key": "p1"},
{"url": "https://example.com/page-2", "key": "p2"},
{"url": "https://example.com/page-3", "key": "p3"}
]'
Update Link
curl -X PATCH "https://api.dub.co/links/LINK_ID" \
-H "Authorization: Bearer $DUB_TOKEN" \
-d '{"url": "https://new-destination.com"}'
QR Codes
# Get QR code for a link
curl "https://api.dub.co/qr?url=https://dub.sh/my-article" \
-o qr-code.png
TypeScript SDK
import { Dub } from "dub";
const dub = new Dub({ token: process.env.DUB_TOKEN });
// Create link
const link = await dub.links.create({
url: "https://example.com/long-url",
domain: "dub.sh",
key: "my-link",
tagIds: ["tag_123"],
});
console.log(link.shortLink); // https://dub.sh/my-link
// Get analytics
const analytics = await dub.analytics.retrieve({
linkId: link.id,
event: "clicks",
groupBy: "country",
interval: "30d",
});
// Track conversions
await dub.track.lead({
clickId: "click_123",
eventName: "Signup",
customerId: "user_456",
});
await dub.track.sale({
clickId: "click_123",
eventName: "Purchase",
customerId: "user_456",
amount: 4900, // cents
currency: "usd",
});
Conversion Tracking
Dub tracks the full funnel: click → lead → sale.
// In your signup handler
await dub.track.lead({
clickId: req.cookies.dub_id,
eventName: "Signup",
customerId: newUser.id,
customerName: newUser.name,
customerEmail: newUser.email,
});
// In your payment handler
await dub.track.sale({
clickId: req.cookies.dub_id,
eventName: "Purchase",
customerId: user.id,
amount: 4900,
});
Dub vs Bitly
| Feature | Dub | Bitly | Short.io |
|---|---|---|---|
| Open source | Yes | No | No |
| Free links | 1,000 | 10/mo | 1,000 |
| Custom domains | Yes | Paid | Yes |
| Conversion tracking | Yes | No | Partial |
| API | Full REST + SDK | REST | REST |
| QR codes | Free | Paid | Free |
Need link tracking or marketing analytics automation?
📧 spinov001@gmail.com
🔧 My tools on Apify Store
Bitly, Dub, or custom shortener? What do you use?
Top comments (0)