Dub

Dub 是一个面向企业家、创作者和增长团队的开源现代链接管理平台。

此插件允许你在用户使用 Dub 链接注册时跟踪潜在客户。它还增加了 OAuth 链接支持,以便你构建扩展 Dub 链接管理基础设施的集成。

【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.】

安装

【Installation】

安装插件

首先,安装插件:

npm install @dub/better-auth

Install the Dub SDK

接下来,在你的服务器上安装 Dub SDK:

npm install dub

Configure the plugin

将插件添加到你的认证配置中:

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()
        })
    ]
})

用法

【Usage】

潜在客户跟进

【Lead Tracking】

默认情况下,插件会将注册事件视为潜在客户进行追踪。你可以通过将 disableLeadTracking 设置为 true 来禁用此功能。

【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
    }),
  ],
});

OAuth 关联

【OAuth Linking】

该插件支持通过 OAuth 进行账户关联。

【The plugin supports OAuth for account linking.】

首先,你需要在 Dub 中设置 OAuth 应用。Dub 支持 OAuth 2.0 认证,如果你构建扩展 Dub 功能的集成,推荐使用此方式。了解更多关于 OAuth

【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.】

一旦你获得客户端 ID 和客户端密钥,就可以配置插件。

【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",
  },
});

在客户端,你需要使用 dubAnalyticsClient 插件。

【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()],
});

要将账户与 Dub 关联,你需要使用 dub.link

【To link account with Dub, you need to use the dub.link.】

POST
/dub/link
const { data, error } = await authClient.dub.link({    callbackURL: "/dashboard", // required});
PropDescriptionType
callbackURL
URL to redirect to after linking
string

选项

【Options】

你可以将以下选项传递给插件:

【You can pass the following options to the plugin:】

dubClient

Dub 客户端实例。

【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。

【Dub OAuth configuration.】

oauth.clientId

Dub OAuth 的客户端 ID。

【Client ID for Dub OAuth.】

oauth.clientSecret

Dub OAuth 的客户端密钥。

【Client secret for Dub OAuth.】

oauth.pkce

为 Dub OAuth 启用 PKCE。

【Enable PKCE for Dub OAuth.】

On this page