feat: tolt affiliate

This commit is contained in:
Nevo David 2024-12-05 20:45:23 +07:00
parent 573de24e9c
commit 65e3bf0852
6 changed files with 38 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import { VariableContextComponent } from '@gitroom/react/helpers/variable.contex
import { Fragment } from 'react';
import { PHProvider } from '@gitroom/react/helpers/posthog';
import UtmSaver from '@gitroom/helpers/utils/utm.saver';
import { ToltScript } from '@gitroom/frontend/components/layout/tolt.script';
const chakra = Chakra_Petch({ weight: '400', subsets: ['latin'] });
@ -42,7 +43,9 @@ export default async function AppLayout({ children }: { children: ReactNode }) {
frontEndUrl={process.env.FRONTEND_URL!}
isGeneral={!!process.env.IS_GENERAL}
uploadDirectory={process.env.NEXT_PUBLIC_UPLOAD_STATIC_DIRECTORY!}
tolt={process.env.NEXT_PUBLIC_TOLT!}
>
<ToltScript />
<Plausible
domain={!!process.env.IS_GENERAL ? 'postiz.com' : 'gitroom.com'}
>

View File

@ -23,6 +23,7 @@ import { TopTitle } from '@gitroom/frontend/components/launches/helpers/top.titl
import { Textarea } from '@gitroom/react/form/textarea';
import { useFireEvents } from '@gitroom/helpers/utils/use.fire.events';
import { useUtmUrl } from '@gitroom/helpers/utils/utm.saver';
import { useTolt } from '@gitroom/frontend/components/layout/tolt.script';
export interface Tiers {
month: Array<{
@ -221,6 +222,7 @@ export const MainBillingComponent: FC<{
const modal = useModals();
const router = useRouter();
const utm = useUtmUrl();
const tolt = useTolt();
const [subscription, setSubscription] = useState<Subscription | undefined>(
sub
@ -348,6 +350,7 @@ export const MainBillingComponent: FC<{
period: monthlyOrYearly === 'on' ? 'YEARLY' : 'MONTHLY',
utm,
billing,
tolt: tolt()
}),
})
).json();

View File

@ -0,0 +1,23 @@
'use client';
import { useVariables } from '@gitroom/react/helpers/variable.context';
import Script from 'next/script';
export const useTolt = () => {
return () => {
// @ts-ignore
return window?.tolt_referral || '';
};
};
export const ToltScript = () => {
const { tolt } = useVariables();
if (!tolt) return null;
return (
<Script
async={true}
src="https://cdn.tolt.io/tolt.js"
data-tolt={tolt}
/>
);
};

View File

@ -8,4 +8,6 @@ export class BillingSubscribeDto {
billing: 'STANDARD' | 'PRO' | 'TEAM' | 'ULTIMATE';
utm: string;
tolt: string;
}

View File

@ -286,6 +286,11 @@ export class StripeService {
uniqueId,
},
},
...body.tolt ? {
metadata: {
tolt_referral: body.tolt,
}
} : {},
allow_promotion_codes: true,
line_items: [
{

View File

@ -11,6 +11,7 @@ interface VariableContextInterface {
backendUrl: string;
discordUrl: string;
uploadDirectory: string;
tolt: string;
}
const VariableContext = createContext({
billingEnabled: false,
@ -21,6 +22,7 @@ const VariableContext = createContext({
backendUrl: '',
discordUrl: '',
uploadDirectory: '',
tolt: '',
} as VariableContextInterface);
export const VariableContextComponent: FC<