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 docs

Steven Tey6fa9d2ace13f
diff --git a/apps/docs/mint.json b/apps/docs/mint.json
index 83faed97b8..63ab4b11fc 100644
--- a/apps/docs/mint.json
+++ b/apps/docs/mint.json
@@ -240,6 +240,42 @@
{
"source": "/api-reference/endpoint/edit-a-domain",
"destination": "/api-reference/endpoint/update-a-domain"
+ },
+ {
+ "source": "/sdks/typescript/analytics/browsers",
+ "destination": "/sdks/typescript/analytics/clicks"
+ },
+ {
+ "source": "/sdks/typescript/analytics/cities",
+ "destination": "/sdks/typescript/analytics/clicks"
+ },
+ {
+ "source": "/sdks/typescript/analytics/countries",
+ "destination": "/sdks/typescript/analytics/clicks"
+ },
+ {
+ "source": "/sdks/typescript/analytics/devices",
+ "destination": "/sdks/typescript/analytics/clicks"
+ },
+ {
+ "source": "/sdks/typescript/analytics/os",
+ "destination": "/sdks/typescript/analytics/clicks"
+ },
+ {
+ "source": "/sdks/typescript/analytics/referers",
+ "destination": "/sdks/typescript/analytics/clicks"
+ },
+ {
+ "source": "/sdks/typescript/analytics/timeseries",
+ "destination": "/sdks/typescript/analytics/clicks"
+ },
+ {
+ "source": "/sdks/typescript/analytics/top-links",
+ "destination": "/sdks/typescript/analytics/clicks"
+ },
+ {
+ "source": "/sdks/typescript/analytics/top-urls",
+ "destination": "/sdks/typescript/analytics/clicks"
}
]
}
diff --git a/apps/docs/sdks/typescript/analytics/browsers.mdx b/apps/docs/sdks/typescript/analytics/browsers.mdx
deleted file mode 100644
index 53d747a25c..0000000000
--- a/apps/docs/sdks/typescript/analytics/browsers.mdx
+++ /dev/null
@@ -1,47 +0,0 @@
----
-title: "Browsers"
-"og:title": "dub.analytics.browsers - Retrieve browser analytics - TypeScript SDK"
-description: "Retrieve the top browsers by number of clicks for a link, a domain, or the authenticated workspace."
----
-
-import AnalyticsArguments from "/snippets/analytics-arguments.mdx";
-
-<Note>
- Analytics endpoints require a [Pro plan](https://d.to/pro) subscription or
- higher.
-</Note>
-
-<AnalyticsArguments />
-
-## Response
-
-<ResponseField name="browser" type="string" required>
- The name of the browser
-</ResponseField>
-
-<ResponseField name="clicks" type="number" required>
- The number of clicks from this browser
-</ResponseField>
-
-<RequestExample>
-
-```typescript
-await dub.analytics.browsers({
- key: "dummy",
- domain: "dub.sh",
- interval: "30d",
-});
-```
-
-</RequestExample>
-
-<ResponseExample>
-
-```typescript
-[
- { browser: "Chrome", clicks: 19 },
- { browser: "Safari", clicks: 12 },
-];
-```
-
-</ResponseExample>
diff --git a/apps/docs/sdks/typescript/analytics/cities.mdx b/apps/docs/sdks/typescript/analytics/cities.mdx
deleted file mode 100644
index 6155b69479..0000000000
--- a/apps/docs/sdks/typescript/analytics/cities.mdx
+++ /dev/null
@@ -1,51 +0,0 @@
----
-title: "Cities"
-"og:title": "dub.analytics.cities - Retrieve city analytics - TypeScript SDK"
-description: "Retrieve the top countries by number of clicks for a link, a domain, or the authenticated workspace."
----
-
-import AnalyticsArguments from "/snippets/analytics-arguments.mdx";
-
-<Note>
- Analytics endpoints require a [Pro plan](https://d.to/pro) subscription or
- higher.
-</Note>
-
-<AnalyticsArguments />
-
-## Response
-
-<ResponseField name="city" type="string" required>
- The name of the city
-</ResponseField>
-
-<ResponseField name="country" type="string" required>
- The 2-letter country code: [https://d.to/geo](https://d.to/geo)
-</ResponseField>
-
-<ResponseField name="clicks" type="number" required>
- The number of clicks from this city
-</ResponseField>
-
-<RequestExample>
-
-```typescript
-await dub.analytics.cities({
- key: "dummy",
- domain: "dub.sh",
- interval: "30d",
-});
-```
-
-</RequestExample>
-
-<ResponseExample>
-
-```typescript
-[
- { city: "San Francisco", country: "US", clicks: 18 },
- { city: "Lviv", country: "UA", clicks: 1 },
-];
-```
-
-</ResponseExample>
diff --git a/apps/docs/sdks/typescript/analytics/clicks.mdx b/apps/docs/sdks/typescript/analytics/clicks.mdx
index 46d165ecdc..6e27e35158 100644
--- a/apps/docs/sdks/typescript/analytics/clicks.mdx
+++ b/apps/docs/sdks/typescript/analytics/clicks.mdx
@@ -1,5 +1,5 @@
---
-title: "Clicks"
+title: "Clicks Analytics"
"og:title": "dub.analytics.clicks - Retrieve clicks analytics - TypeScript SDK"
description: "Retrieve the number of clicks for a link, a domain, or the authenticated workspace."
---
diff --git a/apps/docs/sdks/typescript/analytics/countries.mdx b/apps/docs/sdks/typescript/analytics/countries.mdx
deleted file mode 100644
index d54a7903a5..0000000000
--- a/apps/docs/sdks/typescript/analytics/countries.mdx
+++ /dev/null
@@ -1,47 +0,0 @@
----
-title: "Countries"
-"og:title": "dub.analytics.countries - Retrieve country analytics - TypeScript SDK"
-description: "Retrieve the top countries by number of clicks for a link, a domain, or the authenticated workspace."
----
-
-import AnalyticsArguments from "/snippets/analytics-arguments.mdx";
-
-<Note>
- Analytics endpoints require a [Pro plan](https://d.to/pro) subscription or
- higher.
-</Note>
-
-<AnalyticsArguments />
-
-## Response
-
-<ResponseField name="country" type="string" required>
- The 2-letter country code: [https://d.to/geo](https://d.to/geo)
-</ResponseField>
-
-<ResponseField name="clicks" type="number" required>
- The number of clicks from this country
-</ResponseField>
-
-<RequestExample>
-
-```typescript
-await dub.analytics.countries({
- key: "dummy",
- domain: "dub.sh",
- interval: "30d",
-});
-```
-
-</RequestExample>
-
-<ResponseExample>
-
-```typescript
-[
- { country: "US", clicks: 18 },
- { country: "UA", clicks: 1 },
-];
-```
-
-</ResponseExample>
diff --git a/apps/docs/sdks/typescript/analytics/devices.mdx b/apps/docs/sdks/typescript/analytics/devices.mdx
deleted file mode 100644
index 1bb9524346..0000000000
--- a/apps/docs/sdks/typescript/analytics/devices.mdx
+++ /dev/null
@@ -1,47 +0,0 @@
----
-title: "Devices"
-"og:title": "dub.analytics.devices - Retrieve device analytics - TypeScript SDK"
-description: "Retrieve the top devices by number of clicks for a link, a domain, or the authenticated workspace."
----
-
-import AnalyticsArguments from "/snippets/analytics-arguments.mdx";
-
-<Note>
- Analytics endpoints require a [Pro plan](https://d.to/pro) subscription or
- higher.
-</Note>
-
-<AnalyticsArguments />
-
-## Response
-
-<ResponseField name="device" type="string" required>
- The name of the device
-</ResponseField>
-
-<ResponseField name="clicks" type="number" required>
- The number of clicks from this device
-</ResponseField>
-
-<RequestExample>
-
-```typescript
-await dub.analytics.devices({
- key: "dummy",
- domain: "dub.sh",
- interval: "30d",
-});
-```
-
-</RequestExample>
-
-<ResponseExample>
-
-```typescript
-[
- { device: "Desktop", clicks: 15 },
- { device: "Mobile", clicks: 12 },
-];
-```
-
-</ResponseExample>
diff --git a/apps/docs/sdks/typescript/analytics/os.mdx b/apps/docs/sdks/typescript/analytics/os.mdx
deleted file mode 100644
index d1a00acf29..0000000000
--- a/apps/docs/sdks/typescript/analytics/os.mdx
+++ /dev/null
@@ -1,47 +0,0 @@
----
-title: "OS"
-"og:title": "dub.analytics.os - Retrieve OS analytics - TypeScript SDK"
-description: "Retrieve the top OS by number of clicks for a link, a domain, or the authenticated workspace."
----
-
-import AnalyticsArguments from "/snippets/analytics-arguments.mdx";
-
-<Note>
- Analytics endpoints require a [Pro plan](https://d.to/pro) subscription or
- higher.
-</Note>
-
-<AnalyticsArguments />
-
-## Response
-
-<ResponseField name="os" type="string" required>
- The name of the OS
-</ResponseField>
-
-<ResponseField name="clicks" type="number" required>
- The number of clicks from this OS
-</ResponseField>
-
-<RequestExample>
-
-```typescript
-await dub.analytics.os({
- key: "dummy",
- domain: "dub.sh",
- interval: "30d",
-});
-```
-
-</RequestExample>
-
-<ResponseExample>
-
-```typescript
-[
- { os: "Mac OS", clicks: 19 },
- { os: "Windows", clicks: 12 },
-];
-```
-
-</ResponseExample>
diff --git a/apps/docs/sdks/typescript/analytics/referers.mdx b/apps/docs/sdks/typescript/analytics/referers.mdx
deleted file mode 100644
index 07b1221008..0000000000
--- a/apps/docs/sdks/typescript/analytics/referers.mdx
+++ /dev/null
@@ -1,47 +0,0 @@
----
-title: "Referers"
-"og:title": "dub.analytics.referers - Retrieve referer analytics - TypeScript SDK"
-description: "Retrieve the top referers by number of clicks for a link, a domain, or the authenticated workspace."
----
-
-import AnalyticsArguments from "/snippets/analytics-arguments.mdx";
-
-<Note>
- Analytics endpoints require a [Pro plan](https://d.to/pro) subscription or
- higher.
-</Note>
-
-<AnalyticsArguments />
-
-## Response
-
-<ResponseField name="referer" type="string" required>
- The name of the referer. If unknown, this will be `(direct)`
-</ResponseField>
-
-<ResponseField name="clicks" type="number" required>
- The number of clicks from this referer
-</ResponseField>
-
-<RequestExample>
-
-```typescript
-await dub.analytics.referers({
- key: "dummy",
- domain: "dub.sh",
- interval: "30d",
-});
-```
-
-</RequestExample>
-
-<ResponseExample>
-
-```typescript
-[
- { referer: "(direct)", clicks: 14 },
- { referer: "t.co", clicks: 12 },
-];
-```
-
-</ResponseExample>
diff --git a/apps/docs/sdks/typescript/analytics/timeseries.mdx b/apps/docs/sdks/typescript/analytics/timeseries.mdx
deleted file mode 100644
index 985464d5bc..0000000000
--- a/apps/docs/sdks/typescript/analytics/timeseries.mdx
+++ /dev/null
@@ -1,49 +0,0 @@
----
-title: "Timeseries"
-"og:title": "dub.analytics.timeseries - Retrieve timeseries analytics - TypeScript SDK"
-description: "Retrieve the number of clicks for a link, a domain, or the authenticated workspace over a period of time."
----
-
-import AnalyticsArguments from "/snippets/analytics-arguments.mdx";
-
-<Note>
- Analytics endpoints require a [Pro plan](https://d.to/pro) subscription or
- higher.
-</Note>
-
-<AnalyticsArguments />
-
-## Response
-
-<ResponseField name="start" type="string" required>
- The starting timestamp of the interval
-</ResponseField>
-
-<ResponseField name="clicks" type="number" required>
- The number of clicks in the interval
-</ResponseField>
-
-<RequestExample>
-
-```typescript
-await dub.analytics.timeseries({
- key: "dummy",
- domain: "dub.sh",
- interval: "30d",
-});
-```
-
-</RequestExample>
-
-<ResponseExample>
-
-```typescript
-[
- { start: "2024-03-20T00:00:00.000Z", clicks: 15 },
- { start: "2024-03-21T00:00:00.000Z", clicks: 20 },
- { start: "2024-03-22T00:00:00.000Z", clicks: 18 },
- { start: "2024-03-23T00:00:00.000Z", clicks: 14 },
-];
-```
-
-</ResponseExample>
diff --git a/apps/docs/sdks/typescript/analytics/top-links.mdx b/apps/docs/sdks/typescript/analytics/top-links.mdx
deleted file mode 100644
index 9869b40fb3..0000000000
--- a/apps/docs/sdks/typescript/analytics/top-links.mdx
+++ /dev/null
@@ -1,47 +0,0 @@
----
-title: "Top Links"
-"og:title": "dub.analytics.topLinks - Retrieve top links - TypeScript SDK"
-description: "Retrieve the top links by number of clicks for a domain or the authenticated workspace."
----
-
-import AnalyticsArguments from "/snippets/analytics-arguments.mdx";
-
-<Note>
- Analytics endpoints require a [Pro plan](https://d.to/pro) subscription or
- higher.
-</Note>
-
-<AnalyticsArguments />
-
-## Response
-
-<ResponseField name="link" type="string" required>
- The unique ID of the short link
-</ResponseField>
-
-<ResponseField name="clicks" type="number" required>
- The number of clicks from this link
-</ResponseField>
-
-<RequestExample>
-
-```typescript
-await dub.analytics.topLinks({
- key: "dummy",
- domain: "dub.sh",
- interval: "30d",
-});
-```
-
-</RequestExample>
-
-<ResponseExample>
-
-```typescript
-[
- { link: "cluvb4cwi0001sd593yfdl1sz", clicks: 19 },
- { link: "clri4mgix0001l608ru12tcfr", clicks: 8 },
-];
-```
-
-</ResponseExample>
diff --git a/apps/docs/sdks/typescript/analytics/top-urls.mdx b/apps/docs/sdks/typescript/analytics/top-urls.mdx
deleted file mode 100644
index d6be2ac1e1..0000000000
--- a/apps/docs/sdks/typescript/analytics/top-urls.mdx
+++ /dev/null
@@ -1,47 +0,0 @@
----
-title: "Top Urls"
-"og:title": "dub.analytics.topUrls - Retrieve top urls - TypeScript SDK"
-description: "Retrieve the top URLs by number of clicks for a given short link."
----
-
-import AnalyticsArguments from "/snippets/analytics-arguments.mdx";
-
-<Note>
- Analytics endpoints require a [Pro plan](https://d.to/pro) subscription or
- higher.
-</Note>
-
-<AnalyticsArguments />
-
-## Response
-
-<ResponseField name="url" type="string" required>
- The destination URL
-</ResponseField>
-
-<ResponseField name="clicks" type="number" required>
- The number of clicks from this URL
-</ResponseField>
-
-<RequestExample>
-
-```typescript
-await dub.analytics.topUrls({
- key: "dummy",
- domain: "dub.sh",
- interval: "30d",
-});
-```
-
-</RequestExample>
-
-<ResponseExample>
-
-```typescript
-[
- { url: "https://dub.co/", clicks: 13 },
- { url: "https://dub.co/?qr=", clicks: 4 },
-];
-```
-
-</ResponseExample>
diff --git a/apps/docs/snippets/analytics-arguments.mdx b/apps/docs/snippets/analytics-arguments.mdx
index a11cbcc14b..604b7c8511 100644
--- a/apps/docs/snippets/analytics-arguments.mdx
+++ b/apps/docs/snippets/analytics-arguments.mdx
@@ -1,5 +1,12 @@
## Arguments
+<ParamField body="groupBy" type="enum<string>">
+ The field to group the analytics by. If undefined, returns the total click count.
+
+Available options are `timeseries`, `country`, `city`, `device`, `browser`, `os`, `referer`, `top_links`, and `top_urls`.
+
+</ParamField>
+
<ParamField body="domain" type="string">
The domain of the short link.
</ParamField>
diff --git a/apps/web/lib/analytics/constants.ts b/apps/web/lib/analytics/constants.ts
index 1944d79cca..88b3328e5b 100644
--- a/apps/web/lib/analytics/constants.ts
+++ b/apps/web/lib/analytics/constants.ts
@@ -87,7 +87,6 @@ export const intervalData: Record<
};
export const VALID_TINYBIRD_ENDPOINTS = [
- "clicks",
"timeseries",
"country",
"city",
diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.ts
index e7fd96d64d..37c3272e39 100644
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@ -15,7 +15,7 @@ export const clickAnalyticsQuerySchema = z.object({
})
.optional()
.describe(
- "The group by endpoint. If left empty, returns the total click count.",
+ "The field to group the analytics by. If undefined, returns the total click count.",
),
domain: z.string().optional().describe("The domain to filter analytics for."),
key: z.string().optional().describe("The short link slug."),