Skip to content

Commit 00caa7d

Browse files
committed
feat: moving to dub partners
1 parent e5a4c55 commit 00caa7d

File tree

11 files changed

+80
-47
lines changed

11 files changed

+80
-47
lines changed

apps/frontend/src/app/(app)/layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { VariableContextComponent } from '@gitroom/react/helpers/variable.contex
1313
import { Fragment } from 'react';
1414
import { PHProvider } from '@gitroom/react/helpers/posthog';
1515
import UtmSaver from '@gitroom/helpers/utils/utm.saver';
16-
import { ToltScript } from '@gitroom/frontend/components/layout/tolt.script';
16+
import { DubAnalytics } from '@gitroom/frontend/components/layout/dubAnalytics';
1717
import { FacebookComponent } from '@gitroom/frontend/components/layout/facebook.component';
1818
import { headers } from 'next/headers';
1919
import { headerName } from '@gitroom/react/translation/i18n.config';
@@ -61,7 +61,7 @@ export default async function AppLayout({ children }: { children: ReactNode }) {
6161
oauthLogoUrl={process.env.NEXT_PUBLIC_POSTIZ_OAUTH_LOGO_URL!}
6262
oauthDisplayName={process.env.NEXT_PUBLIC_POSTIZ_OAUTH_DISPLAY_NAME!}
6363
uploadDirectory={process.env.NEXT_PUBLIC_UPLOAD_STATIC_DIRECTORY!}
64-
tolt={process.env.NEXT_PUBLIC_TOLT!}
64+
dub={!!process.env.STRIPE_PUBLISHABLE_KEY}
6565
facebookPixel={process.env.NEXT_PUBLIC_FACEBOOK_PIXEL!}
6666
telegramBotName={process.env.TELEGRAM_BOT_NAME!}
6767
neynarClientId={process.env.NEYNAR_CLIENT_ID!}
@@ -82,7 +82,7 @@ export default async function AppLayout({ children }: { children: ReactNode }) {
8282
<SentryComponent>
8383
{/*<SetTimezone />*/}
8484
<HtmlComponent />
85-
<ToltScript />
85+
<DubAnalytics />
8686
<FacebookComponent />
8787
<Plausible
8888
domain={!!process.env.IS_GENERAL ? 'postiz.com' : 'gitroom.com'}

apps/frontend/src/app/(extension)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default async function AppLayout({ children }: { children: ReactNode }) {
4141
oauthLogoUrl={process.env.NEXT_PUBLIC_POSTIZ_OAUTH_LOGO_URL!}
4242
oauthDisplayName={process.env.NEXT_PUBLIC_POSTIZ_OAUTH_DISPLAY_NAME!}
4343
uploadDirectory={process.env.NEXT_PUBLIC_UPLOAD_STATIC_DIRECTORY!}
44-
tolt={process.env.NEXT_PUBLIC_TOLT!}
44+
dub={false}
4545
facebookPixel={process.env.NEXT_PUBLIC_FACEBOOK_PIXEL!}
4646
telegramBotName={process.env.TELEGRAM_BOT_NAME!}
4747
neynarClientId={process.env.NEYNAR_CLIENT_ID!}

apps/frontend/src/components/billing/first.billing.component.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from '@gitroom/frontend/components/billing/faq.component';
2424
import { useT } from '@gitroom/react/translation/get.transation.service.client';
2525
import { useUser } from '@gitroom/frontend/components/layout/user.context';
26-
import { useTolt } from '@gitroom/frontend/components/layout/tolt.script';
26+
import { useDubClickId } from '@gitroom/frontend/components/layout/dubAnalytics';
2727

2828
const ModeComponent = dynamic(
2929
() => import('@gitroom/frontend/components/layout/mode.component'),
@@ -45,12 +45,12 @@ const EmbeddedBilling = dynamic(
4545
export const FirstBillingComponent = () => {
4646
const { stripeClient } = useVariables();
4747
const user = useUser();
48+
const dub = useDubClickId();
4849
const [stripe, setStripe] = useState<null | Promise<Stripe>>(null);
4950
const [tier, setTier] = useState('STANDARD');
5051
const [period, setPeriod] = useState('MONTHLY');
5152
const fetch = useFetch();
5253
const t = useT();
53-
const tolt = useTolt();
5454

5555
useEffect(() => {
5656
setStripe(loadStripe(stripeClient));
@@ -63,7 +63,7 @@ export const FirstBillingComponent = () => {
6363
body: JSON.stringify({
6464
billing: tier,
6565
period: period,
66-
tolt: tolt(),
66+
...(dub ? { dub } : {}),
6767
}),
6868
})
6969
).json();
@@ -156,7 +156,9 @@ export const FirstBillingComponent = () => {
156156
</div>
157157
<div className="flex px-[80px] tablet:px-[32px] mobile:!px-[16px] flex-1 flex-row tablet:flex-none tablet:flex-col-reverse">
158158
<div className="flex-1 py-[40px] tablet:pt-[80px] flex flex-col pe-[40px] tablet:pe-0">
159-
<div className="block tablet:hidden"><JoinOver /></div>
159+
<div className="block tablet:hidden">
160+
<JoinOver />
161+
</div>
160162
{!isLoading && data && stripe ? (
161163
<>
162164
<EmbeddedBilling stripe={stripe} secret={data.client_secret} />
@@ -168,7 +170,9 @@ export const FirstBillingComponent = () => {
168170
</div>
169171
<div className="flex flex-col ps-[40px] tablet:!ps-[0] border-l border-newColColor py-[40px] mobile:!pt-[24px] tablet:border-none tablet:pb-0">
170172
<div className="top-[20px] sticky">
171-
<div className="hidden tablet:block"><JoinOver /></div>
173+
<div className="hidden tablet:block">
174+
<JoinOver />
175+
</div>
172176
<div className="flex mb-[24px] mobile:flex-col">
173177
<div className="flex-1 text-[24px] font-[700]">
174178
{t('billing_choose_plan', 'Choose a Plan')}

apps/frontend/src/components/billing/main.billing.component.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@ import { useUser } from '@gitroom/frontend/components/layout/user.context';
1818
import { useRouter, useSearchParams } from 'next/navigation';
1919
import { useVariables } from '@gitroom/react/helpers/variable.context';
2020
import { useModals } from '@gitroom/frontend/components/layout/new-modal';
21-
import { TopTitle } from '@gitroom/frontend/components/launches/helpers/top.title.component';
2221
import { Textarea } from '@gitroom/react/form/textarea';
2322
import { useFireEvents } from '@gitroom/helpers/utils/use.fire.events';
2423
import { useUtmUrl } from '@gitroom/helpers/utils/utm.saver';
25-
import { useTolt } from '@gitroom/frontend/components/layout/tolt.script';
2624
import { useTrack } from '@gitroom/react/helpers/use.track';
2725
import { TrackEnum } from '@gitroom/nestjs-libraries/user/track.enum';
2826
import { PurchaseCrypto } from '@gitroom/frontend/components/billing/purchase.crypto';
2927
import { useT } from '@gitroom/react/translation/get.transation.service.client';
3028
import { FinishTrial } from '@gitroom/frontend/components/billing/finish.trial';
3129
import { newDayjs } from '@gitroom/frontend/components/layout/set.timezone';
30+
import { useDubClickId } from '@gitroom/frontend/components/layout/dubAnalytics';
3231

3332
export const Prorate: FC<{
3433
period: 'MONTHLY' | 'YEARLY';
@@ -218,10 +217,10 @@ export const MainBillingComponent: FC<{
218217
const fetch = useFetch();
219218
const toast = useToaster();
220219
const user = useUser();
220+
const dub = useDubClickId();
221221
const modal = useModals();
222222
const router = useRouter();
223223
const utm = useUtmUrl();
224-
const tolt = useTolt();
225224
const track = useTrack();
226225
const t = useT();
227226
const queryParams = useSearchParams();
@@ -387,7 +386,7 @@ export const MainBillingComponent: FC<{
387386
period: monthlyOrYearly === 'on' ? 'YEARLY' : 'MONTHLY',
388387
utm,
389388
billing,
390-
tolt: tolt(),
389+
...(dub ? { dub } : {}),
391390
}),
392391
})
393392
).json();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use client';
2+
3+
import { useVariables } from '@gitroom/react/helpers/variable.context';
4+
import { Analytics as DubAnalyticsIn } from '@dub/analytics/react';
5+
import { getCookie } from 'react-use-cookie';
6+
7+
export const DubAnalytics = () => {
8+
const { dub } = useVariables();
9+
if (!dub) return null;
10+
return (
11+
<DubAnalyticsIn
12+
domainsConfig={{
13+
refer: 'affiliate.postiz.com',
14+
}}
15+
/>
16+
);
17+
};
18+
19+
export const useDubClickId = () => {
20+
const { dub } = useVariables();
21+
if (!dub) return undefined;
22+
23+
const dubCookie = getCookie('dub_partner_data', '{}');
24+
return JSON.parse(dubCookie)?.clickId || undefined;
25+
};

apps/frontend/src/components/layout/tolt.script.tsx

Lines changed: 0 additions & 17 deletions
This file was deleted.

libraries/nestjs-libraries/src/dtos/billing/billing.subscribe.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ export class BillingSubscribeDto {
99

1010
utm: string;
1111

12-
tolt: string;
12+
dub: string;
1313
}

libraries/nestjs-libraries/src/services/stripe.service.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,19 @@ export class StripeService {
375375
// @ts-ignore
376376
apiVersion: '2025-03-31.basil',
377377
});
378+
379+
if (body.dub) {
380+
await stripeCustom.customers.update(customer, {
381+
metadata: {
382+
dubCustomerExternalId: userId,
383+
dubClickId: body.dub,
384+
},
385+
});
386+
}
378387
const isUtm = body.utm ? `&utm_source=${body.utm}` : '';
379388
// @ts-ignore
380389
const { client_secret } = await stripeCustom.checkout.sessions.create({
390+
// @ts-ignore
381391
ui_mode: 'custom',
382392
customer,
383393
return_url:
@@ -394,13 +404,6 @@ export class StripeService {
394404
ud,
395405
},
396406
},
397-
...(body.tolt
398-
? {
399-
metadata: {
400-
tolt_referral: body.tolt,
401-
},
402-
}
403-
: {}),
404407
allow_promotion_codes: body.period === 'MONTHLY',
405408
line_items: [
406409
{
@@ -423,6 +426,16 @@ export class StripeService {
423426
allowTrial: boolean
424427
) {
425428
const isUtm = body.utm ? `&utm_source=${body.utm}` : '';
429+
430+
if (body.dub) {
431+
await stripe.customers.update(customer, {
432+
metadata: {
433+
dubCustomerExternalId: userId,
434+
dubClickId: body.dub,
435+
},
436+
});
437+
}
438+
426439
const { url } = await stripe.checkout.sessions.create({
427440
customer,
428441
cancel_url: process.env['FRONTEND_URL'] + `/billing?cancel=true${isUtm}`,
@@ -440,13 +453,6 @@ export class StripeService {
440453
ud,
441454
},
442455
},
443-
...(body.tolt
444-
? {
445-
metadata: {
446-
tolt_referral: body.tolt,
447-
},
448-
}
449-
: {}),
450456
allow_promotion_codes: body.period === 'MONTHLY',
451457
line_items: [
452458
{

libraries/react-shared-libraries/src/helpers/variable.context.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface VariableContextInterface {
2222
disableImageCompression: boolean;
2323
disableXAnalytics: boolean;
2424
language: string;
25-
tolt: string;
25+
dub: boolean;
2626
transloadit: string[];
2727
sentryDsn: string;
2828
}
@@ -46,7 +46,7 @@ const VariableContext = createContext({
4646
disableImageCompression: false,
4747
disableXAnalytics: false,
4848
language: '',
49-
tolt: '',
49+
dub: false,
5050
transloadit: [],
5151
sentryDsn: '',
5252
} as VariableContextInterface);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@copilotkit/react-textarea": "1.10.6",
5555
"@copilotkit/react-ui": "1.10.6",
5656
"@copilotkit/runtime": "1.10.6",
57+
"@dub/analytics": "^0.0.32",
5758
"@hookform/resolvers": "^3.3.4",
5859
"@langchain/community": "^0.3.40",
5960
"@langchain/core": "^0.3.44",

0 commit comments

Comments
 (0)