Skip to content

Commit fe3169b

Browse files
committed
PM-3203 - use utm cookies on the login & signup links
1 parent b22aa18 commit fe3169b

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/lib/components/user-area/UserArea.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { AUTH0_AUTHENTICATOR_URL } from 'lib/config';
66
import { AUTH_USER_ROLE } from 'lib/config/auth';
77
import { DISABLE_NUDGES } from "lib/config/profile-toasts.config";
8+
import { appendUtmParamsToUrl } from 'lib/functions/utm-cookies.handler';
89
910
import ToolSelector from '../tool-selector/ToolSelector.svelte';
1011
@@ -65,12 +66,15 @@
6566
function onSignIn(signup?: any) {
6667
const locationHref = `${window.location.origin}${window.location.pathname}`
6768
68-
const signupUrl = [
69+
let signupUrl = [
6970
`${AUTH0_AUTHENTICATOR_URL}?retUrl=${encodeURIComponent(locationHref)}`,
7071
signup === true ? '&mode=signUp' : '',
7172
$ctx.signupUtmCodes,
7273
].filter(Boolean).join('&')
7374
75+
// Append UTM parameters from cookie if they exist
76+
signupUrl = appendUtmParamsToUrl(signupUrl);
77+
7478
window.location.href = signupUrl;
7579
}
7680

src/lib/functions/utm-cookies.handler.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,40 @@ export function getUtmCookie(): UtmParams | null {
199199
return null;
200200
}
201201
}
202+
203+
/**
204+
* Appends UTM parameters from the tc_utm cookie to a given URL
205+
* Only appends parameters that exist in the cookie
206+
* @param url - The base URL to append parameters to
207+
* @returns URL with UTM parameters appended, or original URL if no cookie exists
208+
*/
209+
export function appendUtmParamsToUrl(url: string): string {
210+
if (!url) {
211+
return url;
212+
}
213+
214+
const utmParams = getUtmCookie();
215+
if (!utmParams || Object.keys(utmParams).length === 0) {
216+
return url;
217+
}
218+
219+
try {
220+
const urlObj = new URL(url, window.location.origin);
221+
222+
// Append only the UTM parameters that exist in the cookie
223+
if (utmParams.utm_source) {
224+
urlObj.searchParams.set('utm_source', utmParams.utm_source);
225+
}
226+
if (utmParams.utm_medium) {
227+
urlObj.searchParams.set('utm_medium', utmParams.utm_medium);
228+
}
229+
if (utmParams.utm_campaign) {
230+
urlObj.searchParams.set('utm_campaign', utmParams.utm_campaign);
231+
}
232+
233+
return urlObj.toString();
234+
} catch (error) {
235+
console.warn('Error appending UTM parameters to URL:', error);
236+
return url;
237+
}
238+
}

0 commit comments

Comments
 (0)