feat: support affonso affiliate
This commit is contained in:
parent
1a4917c874
commit
8dd3e12824
@ -129,3 +129,9 @@ NEXT_PUBLIC_DATAFAST_ANALYTICS_DOMAIN=""
|
|||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
NEXT_PUBLIC_DISCORD_WIDGET_SERVER_ID=""
|
NEXT_PUBLIC_DISCORD_WIDGET_SERVER_ID=""
|
||||||
NEXT_PUBLIC_DISCORD_WIDGET_CHANNEL_ID=""
|
NEXT_PUBLIC_DISCORD_WIDGET_CHANNEL_ID=""
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Affiliate (Affonso)
|
||||||
|
# https://mksaas.com/docs/affiliate
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
NEXT_PUBLIC_AFFILIATE_AFFONSO_ID=""
|
||||||
|
@ -12,7 +12,6 @@ import StatsSection from '@/components/blocks/stats/stats';
|
|||||||
import TestimonialsSection from '@/components/blocks/testimonials/testimonials';
|
import TestimonialsSection from '@/components/blocks/testimonials/testimonials';
|
||||||
import { NewsletterCard } from '@/components/newsletter/newsletter-card';
|
import { NewsletterCard } from '@/components/newsletter/newsletter-card';
|
||||||
import DiscordWidget from '@/components/shared/discord-widget';
|
import DiscordWidget from '@/components/shared/discord-widget';
|
||||||
import { websiteConfig } from '@/config/website';
|
|
||||||
import { constructMetadata } from '@/lib/metadata';
|
import { constructMetadata } from '@/lib/metadata';
|
||||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||||
import type { Metadata } from 'next';
|
import type { Metadata } from 'next';
|
||||||
|
33
src/components/affiliate/affonso.tsx
Normal file
33
src/components/affiliate/affonso.tsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { websiteConfig } from '@/config/website';
|
||||||
|
import Script from 'next/script';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Affonso Affiliate
|
||||||
|
*
|
||||||
|
* https://affonso.com
|
||||||
|
*/
|
||||||
|
export function AffonsoAffiliate() {
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!websiteConfig.features.enableAffonsoAffiliate) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const affiliateId = process.env.NEXT_PUBLIC_AFFILIATE_AFFONSO_ID as string;
|
||||||
|
if (!affiliateId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Script
|
||||||
|
src="https://affonso.io/js/pixel.min.js"
|
||||||
|
strategy="afterInteractive"
|
||||||
|
data-affonso={affiliateId}
|
||||||
|
data-cookie_duration="30"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
@ -13,6 +13,7 @@ import {
|
|||||||
FormMessage,
|
FormMessage,
|
||||||
} from '@/components/ui/form';
|
} from '@/components/ui/form';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { websiteConfig } from '@/config/website';
|
||||||
import { authClient } from '@/lib/auth-client';
|
import { authClient } from '@/lib/auth-client';
|
||||||
import { getUrlWithLocaleInCallbackUrl } from '@/lib/urls/urls';
|
import { getUrlWithLocaleInCallbackUrl } from '@/lib/urls/urls';
|
||||||
import { DEFAULT_LOGIN_REDIRECT, Routes } from '@/routes';
|
import { DEFAULT_LOGIN_REDIRECT, Routes } from '@/routes';
|
||||||
@ -97,6 +98,13 @@ export const RegisterForm = ({
|
|||||||
// sign up success, user information stored in ctx.data
|
// sign up success, user information stored in ctx.data
|
||||||
// console.log("register, success:", ctx.data);
|
// console.log("register, success:", ctx.data);
|
||||||
setSuccess(t('checkEmail'));
|
setSuccess(t('checkEmail'));
|
||||||
|
|
||||||
|
// add affonso affiliate
|
||||||
|
// https://affonso.io/app/affiliate-program/connect
|
||||||
|
if (websiteConfig.features.enableAffonsoAffiliate) {
|
||||||
|
console.log('register, affonso affiliate:', values.email);
|
||||||
|
window.Affonso.signup(values.email);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onError: (ctx) => {
|
onError: (ctx) => {
|
||||||
// sign up fail, display the error message
|
// sign up fail, display the error message
|
||||||
|
@ -13,7 +13,6 @@ import {
|
|||||||
useSidebar,
|
useSidebar,
|
||||||
} from '@/components/ui/sidebar';
|
} from '@/components/ui/sidebar';
|
||||||
import { getSidebarLinks } from '@/config/sidebar-config';
|
import { getSidebarLinks } from '@/config/sidebar-config';
|
||||||
import { websiteConfig } from '@/config/website';
|
|
||||||
import { LocaleLink } from '@/i18n/navigation';
|
import { LocaleLink } from '@/i18n/navigation';
|
||||||
import { authClient } from '@/lib/auth-client';
|
import { authClient } from '@/lib/auth-client';
|
||||||
import { Routes } from '@/routes';
|
import { Routes } from '@/routes';
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { createCheckoutAction } from '@/actions/create-checkout-session';
|
import { createCheckoutAction } from '@/actions/create-checkout-session';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { websiteConfig } from '@/config/website';
|
||||||
import { Loader2Icon } from 'lucide-react';
|
import { Loader2Icon } from 'lucide-react';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
@ -50,12 +51,35 @@ export function CheckoutButton({
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
|
const mergedMetadata = metadata ? { ...metadata } : {};
|
||||||
|
|
||||||
|
// add affonso_referral to metadata if enabled affonso affiliate
|
||||||
|
if (websiteConfig.features.enableAffonsoAffiliate) {
|
||||||
|
const affonsoReferral =
|
||||||
|
typeof document !== 'undefined'
|
||||||
|
? (() => {
|
||||||
|
const match = document.cookie.match(
|
||||||
|
/(?:^|; )affonso_referral=([^;]*)/
|
||||||
|
);
|
||||||
|
return match ? decodeURIComponent(match[1]) : null;
|
||||||
|
})()
|
||||||
|
: null;
|
||||||
|
if (affonsoReferral) {
|
||||||
|
console.log(
|
||||||
|
'create checkout button, affonsoReferral:',
|
||||||
|
affonsoReferral
|
||||||
|
);
|
||||||
|
mergedMetadata.affonso_referral = affonsoReferral;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create checkout session using server action
|
// Create checkout session using server action
|
||||||
const result = await createCheckoutAction({
|
const result = await createCheckoutAction({
|
||||||
userId,
|
userId,
|
||||||
planId,
|
planId,
|
||||||
priceId,
|
priceId,
|
||||||
metadata,
|
metadata:
|
||||||
|
Object.keys(mergedMetadata).length > 0 ? mergedMetadata : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Redirect to checkout page
|
// Redirect to checkout page
|
||||||
|
@ -35,6 +35,7 @@ export const websiteConfig: WebsiteConfig = {
|
|||||||
features: {
|
features: {
|
||||||
enableDiscordWidget: true,
|
enableDiscordWidget: true,
|
||||||
enableUpgradeCard: true,
|
enableUpgradeCard: true,
|
||||||
|
enableAffonsoAffiliate: false,
|
||||||
},
|
},
|
||||||
routes: {
|
routes: {
|
||||||
defaultLoginRedirect: '/dashboard',
|
defaultLoginRedirect: '/dashboard',
|
||||||
|
1
src/types/index.d.ts
vendored
1
src/types/index.d.ts
vendored
@ -67,6 +67,7 @@ export interface SocialConfig {
|
|||||||
export interface FeaturesConfig {
|
export interface FeaturesConfig {
|
||||||
enableDiscordWidget?: boolean; // Whether to enable the discord widget
|
enableDiscordWidget?: boolean; // Whether to enable the discord widget
|
||||||
enableUpgradeCard?: boolean; // Whether to enable the upgrade card in the sidebar
|
enableUpgradeCard?: boolean; // Whether to enable the upgrade card in the sidebar
|
||||||
|
enableAffonsoAffiliate?: boolean; // Whether to enable affonso affiliate
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user