The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
improve the guides
Kiran K5b36ac10bbec
diff --git a/apps/web/integration-guides/appwrite.md b/apps/web/integration-guides/appwrite.mdindex 6363d7646c..f693d1b00d 100644--- a/apps/web/integration-guides/appwrite.md+++ b/apps/web/integration-guides/appwrite.md@@ -1,6 +1,6 @@Configure Appwrite to track lead conversion events during the sign up process.-### Step 1+## Step 1Head to [Appwrite Cloud](https://apwr.dev/appwrite-dub) and create a new project.@@ -16,7 +16,7 @@ Then, in your Next.js app, install the Appwrite Node.js SDK.npm i node-appwrite```-### Step 2+## Step 2Add the following environment variables to your app.@@ -27,11 +27,11 @@ NEXT_APPWRITE_KEY=<APPWRITE_API_KEY>NEXT_DUB_API_KEY=<DUB_API_KEY>```-### Step 3+## Step 3Add the `DubAnalytics` component from the `@dub/analytics` package to your app's root layout.-```tsx src/app/layout.tsx+```javascriptimport type { Metadata } from "next";import { Analytics as DubAnalytics } from "@dub/analytics/react";@@ -54,11 +54,11 @@ export default function RootLayout({}```-### Step 4+## Step 4Create the Appwrite Session and Admin client (necessary for SSR apps, as explained in the [Appwrite docs](https://appwrite.io/docs/products/auth/server-side-rendering)). Additionally, create a function to verify user login.-```ts src/lib/server/appwrite.ts+```javascript"use server";import { Client, Account } from "node-appwrite";import { cookies } from "next/headers";@@ -96,11 +96,11 @@ export async function createAdminClient() {}```-### Step 5+## Step 5Create the Dub client and send leads to Dub using the `dub.track.lead()` function.-```ts src/lib/server/dub.ts+```javascriptimport type { Models } from "node-appwrite";import { Dub } from "dub";@@ -122,11 +122,11 @@ export function addDubLead(}```-### Step 6+## Step 6In the `/auth` page, use the Appwrite Admin client to allow users to sign up. Post sign up, check if the `dub_id` cookie is present, send a lead event to Dub if found, and delete the `dub_id` cookie.-```tsx src/app/auth/page.tsx+```javascriptimport { ID } from "node-appwrite";import { createAdminClient, getLoggedInUser } from "@/lib/server/appwrite";import { cookies } from "next/headers";diff --git a/apps/web/integration-guides/auth0.md b/apps/web/integration-guides/auth0.mdindex dc6971e9a8..613f9f34fa 100644--- a/apps/web/integration-guides/auth0.md+++ b/apps/web/integration-guides/auth0.md@@ -7,7 +7,7 @@ Here's how it works in a nutshell:3. If the `dub_id` cookie is present, send a lead event to Dub using `dub.track.lead`4. Delete the `dub_id` cookie.-```typescript+```javascriptimport { handleAuth, handleCallback, type Session } from "@auth0/nextjs-auth0";import { cookies } from "next/headers";import { dub } from "@/lib/dub";diff --git a/apps/web/integration-guides/betterauth.md b/apps/web/integration-guides/betterauth.mdindex e9deaba95f..d882b754f8 100644--- a/apps/web/integration-guides/betterauth.md+++ b/apps/web/integration-guides/betterauth.md@@ -1,67 +1,32 @@-This guide will show you how to integrate Dub Analytics with your Better Auth application.+Configure Better Auth to track lead conversion events when a new user signs up.-### Step 1: Install package--Using the package manager of your choice, add the `@dub/analytics` to your project.--```bash-npm install @dub/analytics-```--### Step 2: Initialize package in your code--If you are using a React framework with Better Auth, you can use the `<Analytics />` component to track conversions on your website.--E.g. if you're using Next.js with Better Auth, you can add the `<Analytics />` component to your root layout component or any other pages where you want to track conversions.--You will also need to set up the `domainsConfig.refer` property to enable client-side click-tracking.--```jsx-import { Analytics as DubAnalytics } from '@dub/analytics/react';--export default function RootLayout({- children,-}: Readonly<{- children: React.ReactNode;-}>) {- return (- <html lang="en">- <body>{children}</body>- <DubAnalytics domainsConfig={{- refer: "yourcompany.link"- }} />- </html>- );-}-```--### Step 3: Track authentication events+## Step 1: Track authentication eventsYou can track authentication events by calling the `track` function from the Dub Analytics package:-```jsx-import { track } from '@dub/analytics';+```javascript+import { track } from "@dub/analytics";// Track user sign up-track('user_signed_up', {+track("user_signed_up", {userId: user.id,email: user.email,- provider: 'better-auth'+ provider: "better-auth",});// Track user sign in-track('user_signed_in', {+track("user_signed_in", {userId: user.id,email: user.email,- provider: 'better-auth'+ provider: "better-auth",});```-### Step 4: Integration with Better Auth hooks+## Step 2: Integration with Better Auth hooksIf you're using Better Auth's React hooks, you can integrate tracking directly into your authentication flow:-```jsx+```javascriptimport { useAuth } from 'better-auth/react';import { track } from '@dub/analytics';diff --git a/apps/web/integration-guides/clerk.md b/apps/web/integration-guides/clerk.mdindex 39687c9b1b..051c8a91f8 100644--- a/apps/web/integration-guides/clerk.md+++ b/apps/web/integration-guides/clerk.md@@ -1,10 +1,6 @@Configure Clerk to track lead conversion events when a new user signs up.-Here's a quick video showing how to do this:--<iframe width="100%" height="469px" className="rounded-xl" src="https://www.loom.com/embed/7338589f0c0c4ee1b71c9f2aa28aac87?sid=04c67f3b-1bec-468a-b0c7-5b24d24cd96e" title="Loom video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen />--### Step 1: Add environment variables+## Step 1: Add environment variablesAdd the following environment variables to your app:@@ -17,7 +13,7 @@ CLERK_SECRET_KEY=your_secret_keyDUB_API_KEY=your_api_key```-### Step 2: Add a custom claim to your Clerk session token+## Step 2: Add a custom claim to your Clerk session tokenAdd the following JSON as a [custom claim](https://clerk.com/docs/references/nextjs/add-onboarding-flow#add-custom-claims-to-your-session-token) to your Clerk session token:@@ -27,11 +23,11 @@ Add the following JSON as a [custom claim](https://clerk.com/docs/references/nex}```-### Step 3: Extend the `@dub/analytics` package with Clerk's `useUser` hook+## Step 3: Extend the `@dub/analytics` package with Clerk's `useUser` hookExtend the `@dub/analytics` package to include a `trackLead` server action.-```tsx+```javascript"use client";import { trackLead } from "@/actions/track-lead";@@ -79,7 +75,7 @@ export function DubAnalytics(props: AnalyticsProps) {Then, add the `DubAnalytics` component to your app's root layout component:-```tsx+```javascriptimport { DubAnalytics } from "@/components/dub-analytics";export default function RootLayout({@@ -98,11 +94,11 @@ export default function RootLayout({}```-### Step 4: Implement the `trackLead` server action+## Step 4: Implement the `trackLead` server actionOn the server side, implement the `trackLead` server action.-```tsx /actions/track-lead.ts+```javascript// This is a server action"use server";@@ -159,7 +155,7 @@ export async function trackLead({Alternatively, you can also create an API route instead:-```tsx+```javascript// This is an API routeimport { NextRequest, NextResponse } from "next/server";@@ -191,4 +187,4 @@ export async function POST(req: NextRequest) {});return res;}-```\ No newline at end of file+```diff --git a/apps/web/integration-guides/nextauth.md b/apps/web/integration-guides/nextauth.mdindex a9355fbc17..e875364c0e 100644--- a/apps/web/integration-guides/nextauth.md+++ b/apps/web/integration-guides/nextauth.md@@ -1,6 +1,4 @@-Configure NextAuth to track lead conversion events in your app.--Here's how it works in a nutshell:+Configure NextAuth to track lead conversion events when a new user signs up.1. Use NextAuth's [`signIn` event](https://next-auth.js.org/configuration/events#signin) to detect when there's a new sign up.2. If the user is a new sign up, check if the `dub_id` cookie is present.@@ -9,7 +7,7 @@ Here's how it works in a nutshell:Under the hood, Dub records the user as a customer and associates them with the click event that they came from. The user's unique ID is now the source of truth for all future events – hence why we don't need the `dub_id` cookie anymore.-```typescript+```javascript// app/api/auth/[...nextauth]/options.tsimport type { NextAuthOptions } from "next-auth";import { cookies } from "next/headers";diff --git a/apps/web/integration-guides/supabase.md b/apps/web/integration-guides/supabase.mdindex 453c6ddacd..9c9f225c39 100644--- a/apps/web/integration-guides/supabase.md+++ b/apps/web/integration-guides/supabase.md@@ -8,7 +8,7 @@ Here's how it works in a nutshell:2. If the `dub_id` cookie is present and the user is a new sign up, send a lead event to Dub using `dub.track.lead`3. Delete the `dub_id` cookie.-```typescript+```javascript// app/api/auth/callback/route.tsimport { dub } from "@/lib/dub";import { createClient } from "@/lib/supabase/server";