I have a situation and I am not sure how to solve it.
I am using a script in Google Tag Manager to define where marketing sources are coming from (i.e. organic search, organic social, paid search, referral, direct traffic, etc.).
I am taking the data from that script and storing it in a 1st party cookie & first party cookie variable.
However, I need the data from the cookie to populate in the URL query string, similar to how utms populate in a query string when someone clicks a Google Ad.
For example, when someone clicks on a Google ad, they arrive on the landing page and the URL looks something like this www.examplesite.com/?utm_source=Google&utm_medium=ppc&utm_campaign=example
I need similar functionality to that. So in my example, if someone came from an organic search result, I would want it to look like this:
www.examplesite.com/?Source=Organic&SourceDetail=Google.
Is this even possible to do on the initial page?
Yes, there are a few ways of going around it. I will only highlight the most elegant option, but first, you don't need to touch your query string. You can override the string that is being sent to GA with GTM. It's a lot more elegant than tinkering with the user-exposed front-end. Here is how:
That's how you override your location dimension (dl) in your pageview tag.
Now the only thing that remains is to make that custom javascript variable returning a string that would be just your current url with the proper utm-params appended to it.
This is a very clean and non-intrusive implementation. You can also do it on a GA settings variable level, which may be even a better solution, depending on your situation.
Also, you can override your source/medium using an event, rather than a pageview, but be careful with events. A change of source/medium will force GA to generate a brand new session for this user. That is done to be able to build different attribution models on the same dataset.