Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

SDK Quickstart Docs

Kiran Ka3dbded6deae
diff --git a/apps/docs/mint.json b/apps/docs/mint.json
index ca608985ab..7ddf7bfb57 100644
--- a/apps/docs/mint.json
+++ b/apps/docs/mint.json
@@ -186,6 +186,21 @@
"pages": ["sdks/typescript/metatags/get"]
}
]
+ },
+ {
+ "group": "Quickstart",
+ "pages": [
+ {
+ "group": "Node.js",
+ "pages": [
+ "sdks/nodejs",
+ "sdks/nextjs",
+ "sdks/remix",
+ "sdks/nuxt",
+ "sdks/express"
+ ]
+ }
+ ]
}
],
"api": {
diff --git a/apps/docs/sdks/express.mdx b/apps/docs/sdks/express.mdx
new file mode 100644
index 0000000000..fe83c10a1f
--- /dev/null
+++ b/apps/docs/sdks/express.mdx
@@ -0,0 +1,4 @@
+---
+title: "Express"
+description: "Learn how to create a short link using the Express and Dub Node.js SDK."
+---
diff --git a/apps/docs/sdks/nextjs.mdx b/apps/docs/sdks/nextjs.mdx
new file mode 100644
index 0000000000..c19b0b8bc6
--- /dev/null
+++ b/apps/docs/sdks/nextjs.mdx
@@ -0,0 +1,4 @@
+---
+title: "Next.js"
+description: "Learn how to create a short link using the Next.js and Dub Node.js SDK."
+---
diff --git a/apps/docs/sdks/nodejs.mdx b/apps/docs/sdks/nodejs.mdx
new file mode 100644
index 0000000000..29b8fed256
--- /dev/null
+++ b/apps/docs/sdks/nodejs.mdx
@@ -0,0 +1,127 @@
+---
+title: "Introduction"
+description: "Learn how to create a short link using the Dub Node.js SDK."
+---
+
+## 1. Prerequisites
+
+To follow this guide, you will need to:
+
+- [Create a Dub account](https://app.dub.co/login)
+- [Create an API key](https://app.dub.co/settings/tokens)
+
+## 2. Install
+
+Install the Dub Node.js SDK using your preferred package manager:
+
+<Tabs>
+ <Tab title="npm">
+
+ ```bash
+ npm install dub
+ ```
+
+ </Tab>
+
+ <Tab title="pnpm">
+
+ ```bash
+ pnpm add dub
+ ```
+
+ </Tab>
+
+ <Tab title="yarn">
+
+ ```bash
+ yarn add dub
+ ```
+
+ </Tab>
+</Tabs>
+
+## 3. Create link
+
+Let's create a short link using the Dub Node.js SDK.
+
+```typescript create-link.ts
+import { Dub } from "dub";
+
+const dub = new Dub({
+ token: process.env.DUB_API_KEY,
+ workspaceId: "ws_clugls3...",
+});
+
+await dub.links.create({
+ url: "https://google.com",
+});
+```
+
+## 4. Upsert link
+
+Dub Node.js SDK provides a method to create or update a link so you don't have to worry about checking if the link already exists.
+
+```typescript upsert-link.ts
+const { shortLink } = await dub.links.upsert({
+ url: "https://www.google.com",
+});
+
+console.log(shortLink); // will always be the same short link
+```
+
+## 5. Update link
+
+Let's update an existing link using the Dub Node.js SDK.
+
+```typescript update-link.ts
+// Update a link by its linkId
+await dub.links.update("clv3o9p9q000au1h0mc7r6l63", {
+ url: "https://www.google.uk",
+ archived: true,
+});
+
+// Update a link by its externalId
+await dub.links.update("ext_123", {
+ url: "https://www.google.uk",
+ archived: true,
+});
+```
+
+Both `upsert` and `update` methods accept the same parameters.
+
+## 6. Retrieve analytics for link
+
+Dub allows you to retrieve analytics for a link using the Dub Node.js SDK.
+
+```typescript get-analytics.ts
+import { ClicksCount, ClicksTimeseries } from "dub/models/components";
+
+// Retrieve total clicks for a link
+const response = await dub.analytics.retrieve({
+ key: "dummy",
+ domain: "dub.sh",
+ interval: "30d",
+ event: "clicks",
+});
+
+const clicks = response as ClicksCount;
+
+// Retrieve timeseries analytics for a link
+const response = await dub.analytics.retrieve({
+ key: "dummy",
+ domain: "dub.sh",
+ interval: "30d",
+ event: "clicks",
+ groupBy: "timeseries",
+});
+
+const timeseries = response as ClicksTimeseries[];
+```
+
+## 7. Examples
+
+<CardGroup cols={2}>
+ <Card title="Node.js Example" icon="arrow-up-right-from-square" href="https://github.com/dubinc/examples">
+ See the full example on GitHub.
+ </Card>
+</CardGroup>
\ No newline at end of file
diff --git a/apps/docs/sdks/nuxt.mdx b/apps/docs/sdks/nuxt.mdx
new file mode 100644
index 0000000000..3c66ab1deb
--- /dev/null
+++ b/apps/docs/sdks/nuxt.mdx
@@ -0,0 +1,4 @@
+---
+title: "Nuxt"
+description: "Learn how to create a short link using the Nuxt and Dub Node.js SDK."
+---
diff --git a/apps/docs/sdks/overview.mdx b/apps/docs/sdks/overview.mdx
index 3badd22f96..bf0801f888 100644
--- a/apps/docs/sdks/overview.mdx
+++ b/apps/docs/sdks/overview.mdx
@@ -5,26 +5,22 @@ description: "Open-source client libraries for the Dub.co API"
---
<CardGroup cols={2}>
- <Card
- title="TypeScript"
- icon="github"
- href="/sdks/typescript/overview"
- color="#333333"
- >
+ <Card title="TypeScript" icon="node-js" href="/sdks/typescript/overview">
TypeScript library for the Dub API
</Card>
- <Card title="Go" icon="github" href="https://d.to/go" color="#333333">
+ <Card title="Go" icon="golang" href="/sdks/go/overview" iconType="brands">
Go library for the Dub API
</Card>
- <Card title="Python" icon="github" href="https://d.to/python" color="#333333">
+ <Card title="Python" icon="python" href="/sdks/python/overview">
Python library for the Dub API
</Card>
- <Card
- title="Flutter (Dart)"
- icon="github"
- href="https://d.to/dart"
- color="#333333"
- >
+ <Card title="Ruby" icon="gem" href="/sdks/ruby/overview">
+ Ruby library for the Dub API
+ </Card>
+ <Card title="PHP" icon="php" href="/sdks/php/overview">
+ PHP library for the Dub API
+ </Card>
+ <Card title="Flutter (Dart)" icon="github" href="https://d.to/dart">
Dart SDK for Dub.co API
</Card>
</CardGroup>
diff --git a/apps/docs/sdks/remix.mdx b/apps/docs/sdks/remix.mdx
new file mode 100644
index 0000000000..32e88413e7
--- /dev/null
+++ b/apps/docs/sdks/remix.mdx
@@ -0,0 +1,4 @@
+---
+title: "Remix"
+description: "Learn how to create a short link using the Remix and Dub Node.js SDK."
+---