Here’s how you can use the Dub TypeScript SDK to create a link and retrieve click analytics in timeseries format for it:
Copy
Ask AI
import { Dub } from "dub";// Initialize the Dub SDK with your API keyconst dub = new Dub({ token: process.env.DUB_API_KEY, // optional, defaults to DUB_API_KEY});// Create a new linkconst link = await dub.links.create({ url: "https://google.com",});console.log(link.shortLink); // e.g. https://dub.sh/abc123// Get analytics for the linkconst analytics = await dub.analytics.retrieve({ link_id: link.id, groupBy: "timeseries", interval: "30d",});console.log(analytics); // e.g. [{ start: "2024-01-01", clicks: 100 }]