0.0.2 • Published 6 months ago
@dub/better-auth v0.0.2
Dub Analytics - Better Auth Plugin
Dub Analytics Plugin is a plugin for Dub that allows you to track conversion events in your Better Auth application.
Installation
npm install @dub/better-authUsage
Lead Tracking
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,
}),
],
});OAuth
Dub Better Auth supports OAuth for authentication. You can configure the OAuth client ID and client secret in the dubAnalytics function.
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.
const response = await authClient.dub.link({
callbackURL: "/dashboard", // URL to redirect to after linking
});Options
dubClient
The Dub client instance.
disableLeadTracking
Disable lead tracking for sign up events.
leadEventName
Event name for sign up leads.
customLeadTrack
Custom lead track function.
oauth
Dub OAuth configuration.
oauth.clientId
Client ID for Dub OAuth.
oauth.clientSecret
Client secret for Dub OAuth.
oauth.pkce
Enable PKCE for Dub OAuth.
License
MIT