Append all queries in a url not working

Background

We get traffic from various sources on our website. Google ads, Facebook ads, and LinkedIn ads are the ones that we can directly identify via UTM parameters.

Based on these UTM parameters, we’d like to CTA link or button links to change. Apart from this, we’d also like to append the link URL with these UTMs.

Problem statement 1

How do I append all utms when someone clicks any CTA on my website. (Or clicks on certain types of buttons.)

Example Solution:

My website is growthx.club

If someone comes LinkedIn ads they land with the following URL
growthx.club/?utm_source=linkedIn&utm_campaign=example1

The main call to actions on the website all take the user to this link = https://growth-x.typeform.com/to/eqTXe0pn

We want to append all the parameters after ‘?’ to this link

The link should become https://growth-x.typeform.com/to/eqTXe0pn?utm_source=LinkedIn&utm_campaign=example1

Problem statement 2

How do change the CTA link for a specific type of UTM parameter (Or clicks on certain types of buttons.)

Example Solution:

Let’s continue with the same example. My website is growthx.club

If someone comes LinkedIn ads they land with the following URL
growthx.club/?utm_source=linkedIn&utm_campaign=example1

The main call to actions on the website all take the user to this link = https://growth-x.typeform.com/to/eqTXe0pn

In this case, we’d like not only to append the UTM parameters but also to change the link destination.

So instead of going to https://growth-x.typeform.com/to/eqTXe0pn ?utm_source=LinkedIn&utm_campaign=example1

it should go to
https://growthx.club/curriculum ?utm_source=LinkedIn&utm_campaign=example1

When utm_source=linkedin
and when utm_source=facebook it would go to another URL + appending utms as usual

Problem statement 2 is a subset of problem statement 1.

What I’ve done until now

For now, this is what I have been able to do. Whenever someone comes from a ?referral=anything I change the link location and utms.

import wixLocation from 'wix-location';

$w.onReady(() => {let referral = wixLocation.query.referral;

if (referral)$w('#button8').link ='https://pages.razorpay.com/pl_FfIZu7T72pwizj/view?referral=' + referral;

if (referral)$w('#button60').link ='https://pages.razorpay.com/pl_FfIZu7T72pwizj/view?referral=' + referral;

if (referral)$w('#button54').link ='https://pages.razorpay.com/pl_FfIZu7T72pwizj/view?referral=' + referral;

if (referral)$w('#button61').link ='https://pages.razorpay.com/pl_FfIZu7T72pwizj/view?referral=' + referral;

if (referral)$w('#button53').link ='https://pages.razorpay.com/pl_FfIZu7T72pwizj/view?referral=' + referral;

if (referral)$w('#button51').link ='https://pages.razorpay.com/pl_FfIZu7T72pwizj/view?referral=' + referral;

if (referral)$w('#button55').link ='https://pages.razorpay.com/pl_FfIZu7T72pwizj/view?referral=' + referral;

if (referral)$w('#button52').link ='https://pages.razorpay.com/pl_FfIZu7T72pwizj/view?referral=' + referral;

if (referral)$w('#button56').link ='https://pages.razorpay.com/pl_FfIZu7T72pwizj/view?referral=' + referral;
})

I then ask my teammates to use linkedinsource=example instead of utm_source=linkedin and then repeat this code for LinkedIn and Google / FB etc.

I’m sure there has to be a cleaner solution than this. Also, my solution is limited. It does not change according to utm_source=“value” it changes according to the “utm_source” itself.

I also tried this - https://www.wix.com/velo/forum/main/comment/5bf80e7b70da85044be4f31d

Does anyone have an answer on this? Any Wix experts looking for a consult. Do let me know.