Skip to content

The open alternative to Salesforce, designed for AI.

feat(website): carry ?via= partner attribution to app sign-up links (#28157)

Etienned5a440f6438c
diff --git a/packages/twenty-website/src/app/[locale]/layout.tsx b/packages/twenty-website/src/app/[locale]/layout.tsx
index 049353b1acf..36f4c74374a 100644
--- a/packages/twenty-website/src/app/[locale]/layout.tsx
+++ b/packages/twenty-website/src/app/[locale]/layout.tsx
@@ -8,6 +8,7 @@ import {
type LocaleRouteParams,
} from '@/platform/i18n/get-route-i18n';
import { ContactCalModalRoot } from '@/contact-cal';
+import { PartnerAttributionEffect } from '@/partner-attribution';
import { I18nProvider } from '@/platform/i18n/I18nProvider';
import { resolveLocaleParam } from '@/platform/i18n/resolve-locale-param';
import { WEBSITE_LOCALE_LIST } from '@/platform/i18n/website-locale-list';
@@ -116,6 +117,7 @@ const LocaleLayout = async ({
<body
className={`${tokenCssVariables} ${globalStyles} ${hostGrotesk.variable} ${aleo.variable} ${azeretMono.variable} ${vt323.variable} ${inter.variable}`}
>
+ <PartnerAttributionEffect />
<I18nProvider locale={locale} messages={MESSAGES_BY_LOCALE[locale]}>
<ContactCalModalRoot>{children}</ContactCalModalRoot>
</I18nProvider>
diff --git a/packages/twenty-website/src/partner-attribution/PartnerAttributionEffect.tsx b/packages/twenty-website/src/partner-attribution/PartnerAttributionEffect.tsx
new file mode 100644
index 00000000000..df78522885e
--- /dev/null
+++ b/packages/twenty-website/src/partner-attribution/PartnerAttributionEffect.tsx
@@ -0,0 +1,28 @@
+'use client';
+
+import { useEffect } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+
+import { PARTNER_STORAGE_KEY } from './partner-storage-key';
+
+const PARTNER_QUERY_PARAM = 'via';
+
+export function PartnerAttributionEffect(): null {
+ useEffect(() => {
+ const partner = new URLSearchParams(window.location.search).get(
+ PARTNER_QUERY_PARAM,
+ );
+
+ if (!isDefined(partner) || partner === '') {
+ return;
+ }
+
+ try {
+ sessionStorage.setItem(PARTNER_STORAGE_KEY, partner);
+ } catch {
+ return;
+ }
+ }, []);
+
+ return null;
+}
diff --git a/packages/twenty-website/src/partner-attribution/index.ts b/packages/twenty-website/src/partner-attribution/index.ts
new file mode 100644
index 00000000000..3aff060b808
--- /dev/null
+++ b/packages/twenty-website/src/partner-attribution/index.ts
@@ -0,0 +1 @@
+export { PartnerAttributionEffect } from './PartnerAttributionEffect';
diff --git a/packages/twenty-website/src/partner-attribution/partner-storage-key.ts b/packages/twenty-website/src/partner-attribution/partner-storage-key.ts
new file mode 100644
index 00000000000..c64107d7606
--- /dev/null
+++ b/packages/twenty-website/src/partner-attribution/partner-storage-key.ts
@@ -0,0 +1 @@
+export const PARTNER_STORAGE_KEY = 'partner';
diff --git a/packages/twenty-website/src/partner-attribution/use-partner-on-app-url.ts b/packages/twenty-website/src/partner-attribution/use-partner-on-app-url.ts
new file mode 100644
index 00000000000..0fd7903b146
--- /dev/null
+++ b/packages/twenty-website/src/partner-attribution/use-partner-on-app-url.ts
@@ -0,0 +1,44 @@
+import { useSyncExternalStore } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+
+import { SITE_URLS } from '@/platform/site-urls';
+
+import { PARTNER_STORAGE_KEY } from './partner-storage-key';
+
+const APP_HOSTNAME = new URL(SITE_URLS.appWelcome).hostname;
+
+const subscribe = () => () => {};
+
+const readSavedPartner = (): string | null => {
+ try {
+ return sessionStorage.getItem(PARTNER_STORAGE_KEY);
+ } catch {
+ return null;
+ }
+};
+
+const setPartnerOnAppUrl = (href: string, partner: string): string => {
+ try {
+ const url = new URL(href);
+
+ if (url.hostname !== APP_HOSTNAME) {
+ return href;
+ }
+
+ url.searchParams.set('partner', partner);
+
+ return url.toString();
+ } catch {
+ return href;
+ }
+};
+
+export const usePartnerOnAppUrl = (
+ href: string | undefined,
+): string | undefined => {
+ const partner = useSyncExternalStore(subscribe, readSavedPartner, () => null);
+
+ return isDefined(href) && isDefined(partner)
+ ? setPartnerOnAppUrl(href, partner)
+ : href;
+};
diff --git a/packages/twenty-website/src/ui/Button.tsx b/packages/twenty-website/src/ui/Button.tsx
index 3c75a9631da..21e4d45d699 100644
--- a/packages/twenty-website/src/ui/Button.tsx
+++ b/packages/twenty-website/src/ui/Button.tsx
@@ -15,6 +15,7 @@ import {
} from '@/tokens';
import { ButtonShape } from './ButtonShape';
+import { ExternalLink } from './ExternalLink';
const BUTTON_HEIGHT_PX: Record<ButtonSize, number> = {
regular: 40,
@@ -247,15 +248,9 @@ export function Button({
if (isExternal) {
return (
- <a
- {...sharedAttributes}
- href={href}
- onClick={onClick}
- rel="noopener noreferrer"
- target="_blank"
- >
+ <ExternalLink {...sharedAttributes} href={href} onClick={onClick}>
{inner}
- </a>
+ </ExternalLink>
);
}
diff --git a/packages/twenty-website/src/ui/ExternalLink.tsx b/packages/twenty-website/src/ui/ExternalLink.tsx
index 0060b5ad2e8..cd1b8f6ddcd 100644
--- a/packages/twenty-website/src/ui/ExternalLink.tsx
+++ b/packages/twenty-website/src/ui/ExternalLink.tsx
@@ -1,7 +1,23 @@
+'use client';
+
import { type AnchorHTMLAttributes } from 'react';
+import { usePartnerOnAppUrl } from '@/partner-attribution/use-partner-on-app-url';
+
// The one place the new-tab security attributes exist. Styled variants wrap
// this (styled(ExternalLink)); React 19 forwards ref as a prop.
-export function ExternalLink(props: AnchorHTMLAttributes<HTMLAnchorElement>) {
- return <a rel="noopener noreferrer" target="_blank" {...props} />;
+export function ExternalLink({
+ href,
+ ...props
+}: AnchorHTMLAttributes<HTMLAnchorElement>) {
+ const hrefWithPartner = usePartnerOnAppUrl(href);
+
+ return (
+ <a
+ rel="noopener noreferrer"
+ target="_blank"
+ {...props}
+ href={hrefWithPartner}
+ />
+ );
}