0

We need to store a query parameter (gclid) in a cookie - if it exists. Using Cookie Plus on an EE 2.8 installation.

ie: domain.com/page?gclid=12345

How can I detect that the query exists and then how do I grab the data in the query? I believe this would work if it was segments: {if segment_2=="gclid"} {exp:cookie_plus:set name="cookie" value="{segment_3}" seconds="86400"} {/if}

1 Answer 1

1

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:

https://devot-ee.com/add-ons/pg

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:

{exp:cookie_plus:set
    name="cookie"
    value="{exp:my_query_plugin:get query='gclid'}"
    seconds="86400"
    parse="inward"}

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:

https://davidwalsh.name/query-string-javascript
https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie

You can test if the query param exists, and if so, set a cookie in JS.

1
  • I was able to get MoVariables and Cookie Plus working. Thank you for that tip! The only problem I have now is reading the current value of the cookie. It appears to require a second page refresh to read the value of the cookie. Here is the code I'm using: {if query_string != ""} {exp:cookie_plus:set name="cookie" value="{query_string}" seconds="86400" parse="inward"} {/if} and {exp:cookie_plus:get name="exp_pusa_gclid"} to read the cookie. Is there any workaround to read the cookie instantly and output it?
    – glider
    Mar 30, 2020 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.