Get referrer for the current URL being requested and append it as a UTM parameter


#1

If someone clicks from our website e.g. https://tallyfy.com to our product i.e. https://go.tallyfy.com - we wish to automatically add UTM parameters to track the source of the signup within the URL, via the referrer value in the request. Ideally, the URL then served to the user would be something like this:

https://go.tallyfy.com/#/signup/plan/free?utm_source=blog&utm_medium=post-body-cta&utm_term=definition%20client%20onboarding

In this case, utm_term would be the portion of the URL in the referrer from the root domain i.e. in this case https://tallyfy.com/definition-client-onboarding would be where they clicked before they arrived at the signup page.

How would I implement this automation of utm_tag additions via a Cloudflare worker? Any sample code?