The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add analytics docs
Kiran K69d22ee63ee0
diff --git a/apps/docs/mint.json b/apps/docs/mint.jsonindex 7378d1e0b9..3f276a6d77 100644--- a/apps/docs/mint.json+++ b/apps/docs/mint.json@@ -151,6 +151,21 @@"sdks/typescript/links/create-many"]},+ {+ "group": "Analytics",+ "pages": [+ "sdks/typescript/analytics/clicks",+ "sdks/typescript/analytics/timeseries",+ "sdks/typescript/analytics/countries",+ "sdks/typescript/analytics/cities",+ "sdks/typescript/analytics/devices",+ "sdks/typescript/analytics/browsers",+ "sdks/typescript/analytics/os",+ "sdks/typescript/analytics/referers",+ "sdks/typescript/analytics/top-links",+ "sdks/typescript/analytics/top-urls"+ ]+ },{"group": "Tags","pages": ["sdks/typescript/tags/create", "sdks/typescript/tags/list"]diff --git a/apps/docs/sdks/typescript/analytics/browsers.mdx b/apps/docs/sdks/typescript/analytics/browsers.mdxnew file mode 100644index 0000000000..72e378b169--- /dev/null+++ b/apps/docs/sdks/typescript/analytics/browsers.mdx@@ -0,0 +1,47 @@+---+title: "Browsers"+"og:title": "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](/help/article/pro-plan) subscription+ or higher.+</Note>++<AnalyticsArguments />++## Response++<ResponseField name="browser" type="string" required="true">+ The name of the browser+</ResponseField>++<ResponseField name="clicks" type="number" required="true">+ 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.mdxnew file mode 100644index 0000000000..2bacf0f081--- /dev/null+++ b/apps/docs/sdks/typescript/analytics/cities.mdx@@ -0,0 +1,51 @@+---+title: "Cities"+"og:title": "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](/help/article/pro-plan) subscription+ or higher.+</Note>++<AnalyticsArguments />++## Response++<ResponseField name="city" type="string" required="true">+ The name of the city+</ResponseField>++<ResponseField name="country" type="string" required="true">+ The 2-letter country code: [https://d.to/geo](https://d.to/geo)+</ResponseField>++<ResponseField name="clicks" type="number" required="true">+ 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.mdxnew file mode 100644index 0000000000..49ff0fd624--- /dev/null+++ b/apps/docs/sdks/typescript/analytics/clicks.mdx@@ -0,0 +1,38 @@+---+title: "Clicks"+"og:title": "Retrieve clicks analytics - TypeScript SDK"+description: "Retrieve the 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](/help/article/pro-plan) subscription+ or higher.+</Note>++<AnalyticsArguments />++## Response++The number of clicks matching the specified queries.++<RequestExample>++```typescript+await dub.analytics.clicks({+ key: "dummy",+ domain: "dub.sh",+ interval: "30d",+});+```++</RequestExample>++<ResponseExample>++```typescript+20+```++</ResponseExample>diff --git a/apps/docs/sdks/typescript/analytics/countries.mdx b/apps/docs/sdks/typescript/analytics/countries.mdxnew file mode 100644index 0000000000..d7404fb207--- /dev/null+++ b/apps/docs/sdks/typescript/analytics/countries.mdx@@ -0,0 +1,47 @@+---+title: "Countries"+"og:title": "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](/help/article/pro-plan) subscription+ or higher.+</Note>++<AnalyticsArguments />++## Response++<ResponseField name="country" type="string" required="true">+ The 2-letter country code: [https://d.to/geo](https://d.to/geo)+</ResponseField>++<ResponseField name="clicks" type="number" required="true">+ 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.mdxnew file mode 100644index 0000000000..476ef10392--- /dev/null+++ b/apps/docs/sdks/typescript/analytics/devices.mdx@@ -0,0 +1,47 @@+---+title: "Devices"+"og:title": "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](/help/article/pro-plan) subscription+ or higher.+</Note>++<AnalyticsArguments />++## Response++<ResponseField name="device" type="string" required="true">+ The name of the device+</ResponseField>++<ResponseField name="clicks" type="number" required="true">+ 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.mdxnew file mode 100644index 0000000000..2bc49a802e--- /dev/null+++ b/apps/docs/sdks/typescript/analytics/os.mdx@@ -0,0 +1,47 @@+---+title: "OS"+"og:title": "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](/help/article/pro-plan) subscription+ or higher.+</Note>++<AnalyticsArguments />++## Response++<ResponseField name="os" type="string" required="true">+ The name of the OS+</ResponseField>++<ResponseField name="clicks" type="number" required="true">+ 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.mdxnew file mode 100644index 0000000000..b7c2ebc46d--- /dev/null+++ b/apps/docs/sdks/typescript/analytics/referers.mdx@@ -0,0 +1,47 @@+---+title: "Referers"+"og:title": "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](/help/article/pro-plan) subscription+ or higher.+</Note>++<AnalyticsArguments />++## Response++<ResponseField name="referer" type="string" required="true">+ The name of the referer. If unknown, this will be `(direct)`+</ResponseField>++<ResponseField name="clicks" type="number" required="true">+ 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.mdxnew file mode 100644index 0000000000..d02cf3e6a0--- /dev/null+++ b/apps/docs/sdks/typescript/analytics/timeseries.mdx@@ -0,0 +1,49 @@+---+title: "Timeseries"+"og:title": "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](/help/article/pro-plan) subscription+ or higher.+</Note>++<AnalyticsArguments />++## Response++<ResponseField name="start" type="string" required="true">+ The starting timestamp of the interval+</ResponseField>++<ResponseField name="clicks" type="number" required="true">+ 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.mdxnew file mode 100644index 0000000000..4fd2152823--- /dev/null+++ b/apps/docs/sdks/typescript/analytics/top-links.mdx@@ -0,0 +1,47 @@+---+title: "Top Links"+"og:title": "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](/help/article/pro-plan) subscription+ or higher.+</Note>++<AnalyticsArguments />++## Response++<ResponseField name="link" type="string" required="true">+ The unique ID of the short link+</ResponseField>++<ResponseField name="clicks" type="number" required="true">+ 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.mdxnew file mode 100644index 0000000000..4121c44523--- /dev/null+++ b/apps/docs/sdks/typescript/analytics/top-urls.mdx@@ -0,0 +1,47 @@+---+title: "Top Urls"+"og:title": "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](/help/article/pro-plan) subscription+ or higher.+</Note>++<AnalyticsArguments />++## Response++<ResponseField name="url" type="string" required="true">+ The destination URL+</ResponseField>++<ResponseField name="clicks" type="number" required="true">+ 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/sdks/typescript/links/create-many.mdx b/apps/docs/sdks/typescript/links/create-many.mdxindex 99af8d6ef5..a231390a76 100644--- a/apps/docs/sdks/typescript/links/create-many.mdx+++ b/apps/docs/sdks/typescript/links/create-many.mdx@@ -1,5 +1,5 @@----title: "CreateMany"+title: "Create Many""og:title": "Bulk create links - TypeScript SDK"description: "Bulk create up to 100 links for the authenticated workspace."---diff --git a/apps/docs/snippets/analytics-arguments.mdx b/apps/docs/snippets/analytics-arguments.mdxnew file mode 100644index 0000000000..6767909d46--- /dev/null+++ b/apps/docs/snippets/analytics-arguments.mdx@@ -0,0 +1,72 @@+## Arguments++<ParamField body="domain" type="string">+ The domain of the short link.+</ParamField>++<ParamField body="key" type="string">+ The short link slug.+</ParamField>++<ParamField body="interval" type="enum<string>">+ The interval to retrieve analytics for.++ Available options are `1h`, `24h`, `7d`, `30d`, `90d`, and `all`.+</ParamField>++<ParamField body="country" type="enum<string>">+ The country to retrieve analytics for.++ Available options are `AF`, `AL`, `DZ`,+ `AS`, `AD`, `AO`, `AI`, `AQ`, `AG`, `AR`, `AM`, `AW`, `AU`, `AT`, `AZ`, `BS`,+ `BH`, `BD`, `BB`, `BY`, `BE`, `BZ`, `BJ`, `BM`, `BT`, `BO`, `BA`, `BW`, `BV`,+ `BR`, `IO`, `BN`, `BG`, `BF`, `BI`, `KH`, `CM`, `CA`, `CV`, `KY`, `CF`, `TD`,+ `CL`, `CN`, `CX`, `CC`, `CO`, `KM`, `CG`, `CD`, `CK`, `CR`, `CI`, `HR`, `CU`,+ `CY`, `CZ`, `DK`, `DJ`, `DM`, `DO`, `EC`, `EG`, `SV`, `GQ`, `ER`, `EE`, `ET`,+ `FK`, `FO`, `FJ`, `FI`, `FR`, `GF`, `PF`, `TF`, `GA`, `GM`, `GE`, `DE`, `GH`,+ `GI`, `GR`, `GL`, `GD`, `GP`, `GU`, `GT`, `GN`, `GW`, `GY`, `HT`, `HM`, `VA`,+ `HN`, `HK`, `HU`, `IS`, `IN`, `ID`, `IR`, `IQ`, `IE`, `IL`, `IT`, `JM`, `JP`,+ `JO`, `KZ`, `KE`, `KI`, `KP`, `KR`, `KW`, `KG`, `LA`, `LV`, `LB`, `LS`, `LR`,+ `LY`, `LI`, `LT`, `LU`, `MO`, `MG`, `MW`, `MY`, `MV`, `ML`, `MT`, `MH`, `MQ`,+ `MR`, `MU`, `YT`, `MX`, `FM`, `MD`, `MC`, `MN`, `MS`, `MA`, `MZ`, `MM`, `NA`,+ `NR`, `NP`, `NL`, `NC`, `NZ`, `NI`, `NE`, `NG`, `NU`, `NF`, `MK`, `MP`, `NO`,+ `OM`, `PK`, `PW`, `PS`, `PA`, `PG`, `PY`, `PE`, `PH`, `PN`, `PL`, `PT`, `PR`,+ `QA`, `RE`, `RO`, `RU`, `RW`, `SH`, `KN`, `LC`, `PM`, `VC`, `WS`, `SM`, `ST`,+ `SA`, `SN`, `SC`, `SL`, `SG`, `SK`, `SI`, `SB`, `SO`, `ZA`, `GS`, `ES`, `LK`,+ `SD`, `SR`, `SJ`, `SZ`, `SE`, `CH`, `SY`, `TW`, `TJ`, `TZ`, `TH`, `TL`, `TG`,+ `TK`, `TO`, `TT`, `TN`, `TR`, `TM`, `TC`, `TV`, `UG`, `UA`, `AE`, `GB`, `US`,+ `UM`, `UY`, `UZ`, `VU`, `VE`, `VN`, `VG`, `VI`, `WF`, `EH`, `YE`, `ZM`, `ZW`,+ `AX`, `BQ`, `CW`, `GG`, `IM`, `JE`, `ME`, `BL`, `MF`, `RS`, `SX`, `SS`, `XK`+</ParamField>++<ParamField body="city" type="string">+ The city to retrieve analytics for.+</ParamField>++<ParamField body="device" type="string">+ The device to retrieve analytics for.+</ParamField>++<ParamField body="browser" type="string">+ The browser to retrieve analytics for.+</ParamField>++<ParamField body="os" type="string">+ The OS to retrieve analytics for.+</ParamField>++<ParamField body="referer" type="string">+ The referer to retrieve analytics for.+</ParamField>++<ParamField body="url" type="string">+ The URL to retrieve analytics for.+</ParamField>++<ParamField body="excludeRoot" type="boolean">+ Whether to exclude the root link from the response.+</ParamField>++<ParamField body="tagId" type="string">+ The tag ID to retrieve analytics for.+</ParamField>diff --git a/apps/web/lib/openapi/analytics/clicks.ts b/apps/web/lib/openapi/analytics/clicks.tsindex 59535146ae..22a35ec1d4 100644--- a/apps/web/lib/openapi/analytics/clicks.ts+++ b/apps/web/lib/openapi/analytics/clicks.ts@@ -19,7 +19,7 @@ export const getClicksAnalytics: ZodOpenApiOperationObject = {"application/json": {schema: {type: "number",- description: "The number of clicks",+ description: "The number of clicks matching the specified queries.",},},},