docs/content/docs/plugins/dub.mdx
Dub is an open source modern link management platform for entrepreneurs, creators, and growth teams.
This plugins allows you to track leads when a user signs up using a Dub link. It also adds OAuth linking support to allow you to build integrations extending Dub's linking management infrastructure.
First, install the plugin:
```package-install
@dub/better-auth
```
Next, install the Dub SDK on your server:
```package-install
dub
```
Add the plugin to your auth config:
```ts title="auth.ts"
import { betterAuth } from "better-auth"
import { dubAnalytics } from "@dub/better-auth"
import { dub } from "dub"
export const auth = betterAuth({
plugins: [
dubAnalytics({
dubClient: new Dub()
})
]
})
```
By default, the plugin will track sign up events as leads. You can disable this by setting disableLeadTracking to true.
import { dubAnalytics } from "@dub/better-auth";
import { betterAuth } from "better-auth";
import { Dub } from "dub";
const dub = new Dub();
const betterAuth = betterAuth({
plugins: [
dubAnalytics({
dubClient: dub,
disableLeadTracking: true, // Disable lead tracking
}),
],
});
The plugin supports OAuth for account linking.
First, you need to setup OAuth app in Dub. Dub supports OAuth 2.0 authentication, which is recommended if you build integrations extending Dub’s functionality Learn more about OAuth.
Once you get the client ID and client secret, you can configure the plugin.
dubAnalytics({
dubClient: dub,
oauth: {
clientId: "your-client-id",
clientSecret: "your-client-secret",
},
});
And in the client, you need to use the dubAnalyticsClient plugin.
import { createAuthClient } from "better-auth/client";
import { dubAnalyticsClient } from "@dub/better-auth/client";
const authClient = createAuthClient({
plugins: [dubAnalyticsClient()],
});
To link account with Dub, you need to use the dub.link.
You can pass the following options to the plugin:
dubClientThe Dub client instance.
disableLeadTrackingDisable lead tracking for sign up events.
leadEventNameEvent name for sign up leads.
customLeadTrackCustom lead track function.
oauthDub OAuth configuration.
oauth.clientIdClient ID for Dub OAuth.
oauth.clientSecretClient secret for Dub OAuth.
oauth.pkceEnable PKCE for Dub OAuth.