Given your outdated EE version, I'm not sure there are any viable add-on's that can help you with this (maybe Mo' Variables if you can get an old version?).
A quick search shows this add-on:
Might do the trick. And there maybe other plugins if you search for them. If not...
You have two options. The first would be to craft a plugin that can grab, parse, and return query variables you ask it for. Then you could (probably) do something like this:
Not sure all of that would work with EE 2.8, I have no access to an install earlier than EE 4.
The second is to simply skip using templating to get this done. It's easily done in JS:
You can test if the query param exists, and if so, set a cookie in JS.