Menu

1.1.10

提示

版本号请查看 package.json 文件的 version 字段

集成 Affiliate

更新代码前请先阅读 Affiliate 集成步骤,完成注册和获取 Affiliate ID。

步骤1:添加 app/ToltScript.tsx 文件

请直接到源码仓库复制

步骤2:在 app/[locale]/layout.tsx 引入 ToltScript 组件

app/[locale]/layout.tsx
<head>
  {process.env.NODE_ENV === "development" ? (
    <></>
  ) : (
    <>
      <ToltScript />
    </>
  )}
</head>

步骤3:修改 components/home/PricingCTA.tsx,将 referral 参数传给 checkout-session

  const handleCheckout = async () => {
    // ...other code...
 
    try {
      const toltReferral = (window as any).tolt_referral;
 
      const requestBody: {
        priceId: string;
        couponCode?: string;
        referral?: string;
      } = {
        priceId: stripePriceId,
      };
 
      if (toltReferral) {
        requestBody.referral = toltReferral;
      }
 
      const response = await fetch("/api/stripe/checkout-session", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "Accept-Language": (locale || DEFAULT_LOCALE) as string,
        },
        body: JSON.stringify(requestBody),
      });
 
      // ...other code...
    } catch (error) {
      // ...other code...
    }
  };

步骤4:修改 app/api/stripe/checkout-session/route.ts,接收 referral 参数传给

type RequestData = {
  priceId: string;
  couponCode?: string;
  referral?: string; // add
};
 
 
// const { priceId, couponCode } = requestData; // remove
const { priceId, couponCode, referral } = requestData; // add
 
const sessionParams: Stripe.Checkout.SessionCreateParams = {
  // ...other code...
  metadata: {
    userId: userId,
    planId: plan.id,
    planName: plan.card_title,
    priceId: priceId,
    ...(referral && { tolt_referral: referral }), // add
  },
}

步骤5:修改 components/BuiltWithButton.tsx,使用 Nexty Affiliate 链接

注册 Nexty Affiliate,然后将 BuiltWithButton 里面的链接修改成你创建的 Affiliate 链接,这样你就可以开始赚取佣金了。