diff --git a/packages/donate-button-v4/src/components/widget/types/WidgetConfig.ts b/packages/donate-button-v4/src/components/widget/types/WidgetConfig.ts index b77689e4..a889e822 100644 --- a/packages/donate-button-v4/src/components/widget/types/WidgetConfig.ts +++ b/packages/donate-button-v4/src/components/widget/types/WidgetConfig.ts @@ -31,4 +31,6 @@ export interface WidgetConfig { monthlyTitle?: string; showGiftCardOption?: boolean; + + utmSource?: string; } diff --git a/packages/donate-button-v4/src/helpers/constructDonateUrl.ts b/packages/donate-button-v4/src/helpers/constructDonateUrl.ts index 40c506fc..16c4cbfb 100644 --- a/packages/donate-button-v4/src/helpers/constructDonateUrl.ts +++ b/packages/donate-button-v4/src/helpers/constructDonateUrl.ts @@ -13,6 +13,7 @@ interface BaseUrlParams { noExit?: boolean; methods?: PaymentMethod[]; privateNote?: string; + utmSource?: string; } interface DonateUrlParams extends BaseUrlParams { @@ -56,15 +57,16 @@ function getBaseParams({ methods, nonprofitSlug, noExit, - privateNote + privateNote, + utmSource }: Pick< BaseUrlParams, - 'nonprofitSlug' | 'methods' | 'noExit' | 'privateNote' + 'nonprofitSlug' | 'methods' | 'noExit' | 'privateNote' | 'utmSource' >) { return { method: methods?.join(','), utm_campaign: 'donate-button', - utm_source: nonprofitSlug, + utm_source: utmSource ?? nonprofitSlug, utm_medium: UTM_MEDIUM, no_exit: noExit ?? 1, private_note: privateNote diff --git a/packages/donate-button-v4/src/helpers/parseDonateUrl.ts b/packages/donate-button-v4/src/helpers/parseDonateUrl.ts index e9b5c5d9..7f4083f0 100644 --- a/packages/donate-button-v4/src/helpers/parseDonateUrl.ts +++ b/packages/donate-button-v4/src/helpers/parseDonateUrl.ts @@ -12,7 +12,8 @@ enum DonateUrlParameters { FREQUENCY = 'frequency', MONTHLY_TITLE = 'monthlyTitle', SUGGESTED_AMOUNTS = 'suggestedAmounts', - AMOUNT = 'amount' + AMOUNT = 'amount', + UTM_SOURCE = 'utm_source' } function methodsFromString(string?: string | null) { @@ -73,6 +74,8 @@ export function parseDonateUrl( const addAmounts = addAmountsFromString( searchParameters.get(DonateUrlParameters.SUGGESTED_AMOUNTS) ); + const utmSource = + searchParameters.get(DonateUrlParameters.UTM_SOURCE) ?? undefined; const lockMonthlyFrequency = defaultFrequency === DonationFrequency.Monthly; if (!nonprofitSlug) { @@ -87,6 +90,7 @@ export function parseDonateUrl( lockMonthlyFrequency, monthlyTitle, addAmounts, + utmSource, defaultDonationAmount }; }