Skip to content

Commit

Permalink
Support custom utm_source
Browse files Browse the repository at this point in the history
  • Loading branch information
markulrich committed Dec 6, 2023
1 parent 9928400 commit 130aeeb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ export interface WidgetConfig {
monthlyTitle?: string;

showGiftCardOption?: boolean;

utmSource?: string;
}
8 changes: 5 additions & 3 deletions packages/donate-button-v4/src/helpers/constructDonateUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface BaseUrlParams {
noExit?: boolean;
methods?: PaymentMethod[];
privateNote?: string;
utmSource?: string;
}

interface DonateUrlParams extends BaseUrlParams {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion packages/donate-button-v4/src/helpers/parseDonateUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -87,6 +90,7 @@ export function parseDonateUrl(
lockMonthlyFrequency,
monthlyTitle,
addAmounts,
utmSource,
defaultDonationAmount
};
}

0 comments on commit 130aeeb

Please sign in to comment.