I am setting up an affiliate link area for my site and need to be able to store a URL query string into a cookie that expires in a 7 days and pull it out into HTML later down the road.
Users will click on a link like: http://examplesite.com?afil=randomvalue.
I want to pull the key ‘afil’ and the value ‘randomvalue’ and put it in a cookie in the browser.
This cookie will be used later (on another page) in a link from one of examplesite.com to order.examplesite.com but I can’t keep the parameter (query string) in the URL.
I can do this on another site using PHP but HubSpot doesn’t let me use PHP. I saw other posts mentioning the use of HUBL.
My PHP code is:
<body>
<?php
$value=$_GET[‘afil’]; //the value from the url
setcookie(“afilCookie”, $value, strtotime( ‘+7 days’ )); /* expire in 7 days */
?>
…
And to create a link I would then add this code to any page:
if (isset($_COOKIE[‘afilCookie’])) {
$cookie = $_COOKIE[‘afilCookie’];
echo ‘<a href="http://order.examplesite.com?afil=’ . $cookie . ‘" class=“button”>Order Now</a>’;
}
Can anyone help me with creating the correct code in HUBL to do all of this?
1. Add a cookie with the key/value from the URL query string (parameter).
2. Pull the cookie value to use as a variable in a link.
I am very unfamiliar with it and haven’t been able to find any posts that match this request.