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.

update the node docs

Kiran K47ead99b4b47
diff --git a/apps/docs/quickstart/express.mdx b/apps/docs/quickstart/express.mdx
index 496e457677..4d90f8066f 100644
--- a/apps/docs/quickstart/express.mdx
+++ b/apps/docs/quickstart/express.mdx
@@ -73,7 +73,7 @@ Let's update an existing link using the Dub Node.js SDK.
```typescript index.ts
app.get("/update-link", async (req: Request, res: Response) => {
try {
- const result = await dub.links.update("LINK_ID OR EXTERNAL_ID", {
+ const result = await dub.links.update("LINK_ID", {
url: "https://www.google.us",
});
@@ -89,17 +89,21 @@ app.get("/update-link", async (req: Request, res: Response) => {
Dub allows you to retrieve analytics for a link using the Dub Node.js SDK.
```typescript index.ts
+import { ClicksTimeseries } from "dub/models/components";
+
app.get("/analytics", async (req: Request, res: Response) => {
try {
// Retrieve the timeseries analytics for the last 7 days for a link
- const result = await dub.analytics.retrieve({
+ const response = await dub.analytics.retrieve({
linkId: "LINK_ID",
interval: "7d",
event: "clicks",
groupBy: "timeseries",
});
- res.status(200).json(result);
+ const timeseries = response as ClicksTimeseries[];
+
+ res.status(200).json(timeseries);
} catch (error: any) {
res.status(400).json(error);
}
diff --git a/apps/docs/quickstart/nextjs.mdx b/apps/docs/quickstart/nextjs.mdx
index f3ff4245ee..f5cf458e03 100644
--- a/apps/docs/quickstart/nextjs.mdx
+++ b/apps/docs/quickstart/nextjs.mdx
@@ -64,7 +64,7 @@ Let's update an existing link using the Dub Node.js SDK.
```typescript app/api/links/route.ts
export async function PATCH() {
try {
- const link = await dub.links.update("clv3o9p9q000au1h0mc7r6l63", {
+ const link = await dub.links.update("LINK_ID", {
url: "https://www.google.uk",
archived: true,
});
@@ -81,32 +81,21 @@ export async function PATCH() {
Dub allows you to retrieve analytics for a link using the Dub Node.js SDK.
```typescript app/api/analytics/route.ts
-import { ClicksCount, ClicksTimeseries } from "dub/models/components";
+import { ClicksTimeseries } from "dub/models/components";
export async function GET() {
try {
- // Retrieve total clicks for a link
- let 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
- response = await dub.analytics.retrieve({
- key: "dummy",
- domain: "dub.sh",
- interval: "30d",
+ // Retrieve the timeseries analytics for the last 7 days for a link
+ const response = await dub.analytics.retrieve({
+ linkId: "LINK_ID",
+ interval: "7d",
event: "clicks",
groupBy: "timeseries",
});
const timeseries = response as ClicksTimeseries[];
- return Response.json({ clicks, timeseries });
+ return Response.json(timeseries);
} catch (error) {
return Response.json({ error }, { status: 500 });
}
diff --git a/apps/docs/quickstart/nodejs.mdx b/apps/docs/quickstart/nodejs.mdx
index 8b890ec559..750e8833fa 100644
--- a/apps/docs/quickstart/nodejs.mdx
+++ b/apps/docs/quickstart/nodejs.mdx
@@ -66,23 +66,12 @@ await dub.links.update("ext_123", {
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";
+import { ClicksTimeseries } from "dub/models/components";
-// Retrieve total clicks for a link
+// Retrieve the timeseries analytics for the last 7 days 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",
+ linkId: "LINK_ID",
+ interval: "7d",
event: "clicks",
groupBy: "timeseries",
});
diff --git a/apps/docs/quickstart/nuxt.mdx b/apps/docs/quickstart/nuxt.mdx
index d7feb62409..6cddaa0a4d 100644
--- a/apps/docs/quickstart/nuxt.mdx
+++ b/apps/docs/quickstart/nuxt.mdx
@@ -95,17 +95,21 @@ Dub allows you to retrieve analytics for a link using the Dub Node.js SDK.
```typescript server/api/analytics.get.ts
import { dub } from "../utils/dub";
+import { ClicksTimeseries } from "dub/models/components";
export default defineEventHandler(async () => {
try {
- const result = await dub.analytics.retrieve({
+ // Retrieve the timeseries analytics for the last 7 days for a link
+ const response = await dub.analytics.retrieve({
linkId: "LINK_ID",
interval: "7d",
event: "clicks",
groupBy: "timeseries",
});
- return result;
+ const timeseries = response as ClicksTimeseries[];
+
+ return timeseries;
} catch (error) {
console.error(error);
return error;