custom: support promotekit affiliate

This commit is contained in:
javayhu 2025-05-31 12:03:54 +08:00
parent 80763b4efb
commit 34b7c1c74f
7 changed files with 64 additions and 3 deletions

View File

@ -131,7 +131,15 @@ NEXT_PUBLIC_DISCORD_WIDGET_SERVER_ID=""
NEXT_PUBLIC_DISCORD_WIDGET_CHANNEL_ID=""
# -----------------------------------------------------------------------------
# Affiliate (Affonso)
# Affiliate
# https://mksaas.com/docs/affiliate
# -----------------------------------------------------------------------------
# Affonso
# https://affonso.com/
# -----------------------------------------------------------------------------
NEXT_PUBLIC_AFFILIATE_AFFONSO_ID=""
# -----------------------------------------------------------------------------
# PromoteKit
# https://www.promotekit.com/
# -----------------------------------------------------------------------------
NEXT_PUBLIC_AFFILIATE_PROMOTEKIT_ID=""

View File

@ -5,7 +5,8 @@ import {
fontNotoSansMono,
fontNotoSerif,
} from '@/assets/fonts';
import { AffonsoScript } from '@/components/affiliate/affonso';
import AffonsoScript from '@/components/affiliate/affonso';
import PromotekitScript from '@/components/affiliate/promotekit';
import { TailwindIndicator } from '@/components/layout/tailwind-indicator';
import { routing } from '@/i18n/routing';
import { cn } from '@/lib/utils';
@ -44,6 +45,7 @@ export default async function LocaleLayout({
<html suppressHydrationWarning lang={locale}>
<head>
<AffonsoScript />
<PromotekitScript />
</head>
<body
suppressHydrationWarning

View File

@ -8,7 +8,7 @@ import Script from 'next/script';
*
* https://affonso.com
*/
export function AffonsoScript() {
export default function AffonsoScript() {
if (process.env.NODE_ENV !== 'production') {
return null;
}

View File

@ -0,0 +1,34 @@
'use client';
import { websiteConfig } from '@/config/website';
import Script from 'next/script';
/**
* PromoteKit
*
* https://www.promotekit.com
*/
export default function PromotekitScript() {
if (process.env.NODE_ENV !== 'production') {
return null;
}
if (!websiteConfig.features.enablePromotekitAffiliate) {
return null;
}
const promotekitKey = process.env.NEXT_PUBLIC_AFFILIATE_PROMOTEKIT_ID;
if (!promotekitKey) {
return null;
}
return (
<>
<Script
src="https://cdn.promotekit.com/promotekit.js"
data-promotekit={promotekitKey}
strategy="afterInteractive"
/>
</>
);
}

View File

@ -53,6 +53,21 @@ export function CheckoutButton({
const mergedMetadata = metadata ? { ...metadata } : {};
// add promotekit_referral to metadata if enabled promotekit affiliate
if (websiteConfig.features.enablePromotekitAffiliate) {
const promotekitReferral =
typeof window !== 'undefined'
? (window as any).promotekit_referral
: undefined;
if (promotekitReferral) {
console.log(
'create checkout button, promotekitReferral:',
promotekitReferral
);
mergedMetadata.promotekit_referral = promotekitReferral;
}
}
// add affonso_referral to metadata if enabled affonso affiliate
if (websiteConfig.features.enableAffonsoAffiliate) {
const affonsoReferral =

View File

@ -36,6 +36,7 @@ export const websiteConfig: WebsiteConfig = {
enableDiscordWidget: true,
enableUpgradeCard: true,
enableAffonsoAffiliate: false,
enablePromotekitAffiliate: false,
},
routes: {
defaultLoginRedirect: '/dashboard',

View File

@ -68,6 +68,7 @@ export interface FeaturesConfig {
enableDiscordWidget?: boolean; // Whether to enable the discord widget
enableUpgradeCard?: boolean; // Whether to enable the upgrade card in the sidebar
enableAffonsoAffiliate?: boolean; // Whether to enable affonso affiliate
enablePromotekitAffiliate?: boolean; // Whether to enable promotekit affiliate
}
/**