How can access URL parameters and set cookies using Hubl?
SOLVE
Hi people! We have to implement a solution via Hubl so we can take an URL parameter and create a cookie with its value. I have been searching this on the forum but nobody have catched an URL parameter and no one have create a cookie this way (maybe just I didn't find it, sorry then). We can't use Javascript because we need to set some properties in the cookie like "Http" or "Secure Flags"... so we need server-side code... Thanks to everybody in advance! Regards!
How can access URL parameters and set cookies using Hubl?
SOLVE
Hi John!
First of all, thank's a lot for your help!
If I get you: - Accesing cookies values with Hubl --> Breaks page caching --> Page more slower - I can't read url param with Hubl --> I've to mix different techonologies for a single thing... - You can set secure flag with Javasctipt --> But we can set HttpOnly... - It can be possible to use serverless functions (on enterprise) --> For this client, we have a pro solution...
So the best way (and I can say, the only one possible) is to have an enterprise account so you can use servelss functions, haven't it? Tell me if I undertanded all that you said and I put your answer like the solution of the post!
How can access URL parameters and set cookies using Hubl?
SOLVE
Helo Piersg:
Thanks for correct the part of the URL param, so the definitive solution is: - I can access cookies values with Hubl but breaking page caching. - I can read url param with Hubl. - I can set secure flag with Javasctipt
- I can't set the HttpOnly flag. - It can be possible to use serverless functions (on enterprise).
Thanks Piersg and thanks John, I`ll try to mark you both as accepted solution.
How can access URL parameters and set cookies using Hubl?
SOLVE
Hi John!
First of all, thank's a lot for your help!
If I get you: - Accesing cookies values with Hubl --> Breaks page caching --> Page more slower - I can't read url param with Hubl --> I've to mix different techonologies for a single thing... - You can set secure flag with Javasctipt --> But we can set HttpOnly... - It can be possible to use serverless functions (on enterprise) --> For this client, we have a pro solution...
So the best way (and I can say, the only one possible) is to have an enterprise account so you can use servelss functions, haven't it? Tell me if I undertanded all that you said and I put your answer like the solution of the post!
How can access URL parameters and set cookies using Hubl?
SOLVE
Hi Piersg! Thanks again, but I need to create the cookie in Hubspot, it's a priority, setting all the flags. Can I create the cookie using Javascript and then access it with Hubl and modify the flags in Hubl too? I suposse if I can't create de cookie in Hubl also I can't change any ot its properties... Regards.
Oct 16, 20206:39 AM - edited Oct 16, 20206:46 AM
Contributor
How can access URL parameters and set cookies using Hubl?
SOLVE
Hi Piersg!
Thanks a lot for the answer. Sorry, but it has to be a cookie (can't be a session storage), and we need to activate the flags. I have done the same code in PHP, maybe it will help us:
But I take note about {{request.query}} and {{request.cookies.myCookieName}}, thanks again for that. I assume you can access to this"myCookieName" only if it have been created before (out of hubl)..., is that?
How can access URL parameters and set cookies using Hubl?
SOLVE
You can access "myCookieName" via request.cookies if it exists on the site, it doesn't matter how it was set (but yes it has to have been created before you access it, otherwise it will return null/be empty). So if you manage to set it via PHP on the server, you'll be able to access it in HubL.
How can access URL parameters and set cookies using Hubl?
SOLVE
Hi Dennisedson!
Thanks for the answer! I'll try to show you the problem: We have this URL for example (landing.superpage.com?abc=randomvaluewewanttokeepinacookie). Our customer wants to store the bold parameter in a cookie, but we can't use Javascript because with Javascript cookies creation intructions we can't set the flags, you have to use server-side code. We need HTTP Only Flag, Secure Flag and main domain we use (superpage.com). Here an example of the cookie we want:
You can get the URL parameter in HubL with {{request.query}}. You can also access cookies via {{request.cookies}} which is a dict, so you can do {{request.cookies.myCookieName}}.
Setting an HTTP cookie, however, I'm not sure about. I know you can do this in PHP but of course you'd need access to the server for that. You could use session storage instead?