# Setup custom Cookie at User's browser

**URL:** <https://community.hubspot.com/t/setup-custom-cookie-at-users-browser/120802>\
**Category:** CMS Development\
**Tags:** design-manager, javascript\
**Created:** [November 19, 2024, 6:09am UTC](https://community.hubspot.com/t/setup-custom-cookie-at-users-browser/120802 "2024-11-19T06:09:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DProdigitas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dprodigitas/32/14727_2.png) [@DProdigitas](https://community.hubspot.com/u/DProdigitas)\
**Post date:** [November 19, 2024, 6:09am UTC](https://community.hubspot.com/t/setup-custom-cookie-at-users-browser/120802/1 "2024-11-19T06:09:34Z")

</div>

Hi,

I want to set Custom Cookie Variable with it’s value and expire date. My main goal is to set Cookie variable is depend upon the login user, Once the user is log into website the cookie variable at user’s browser is set with email address and it wll remove once the user is logged out.

I am trying to use Javascript code for this functionality.

**Here is my Javascript code:**

_function setCookie(name, value, days) {_  
_var d = new Date;_  
_d.setTime(d.getTime() + 24\*60\*60\*1000\*days);_  
_document.cookie = name + “=” + value + “;path=/;expires=” + d.toGMTString();_

_}_

_-----------------------------------------------------------------------_

Unfortunately the code is not working at Hubspot platform. Can you please help me this? How we can set, get and remove the custom cookie variable at HubSpot either using Javascript or HubL.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Berangere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/berangere/32/220784_2.png) [@Berangere](https://community.hubspot.com/u/Berangere)\
**Post date:** [November 19, 2024, 5:06pm UTC](https://community.hubspot.com/t/setup-custom-cookie-at-users-browser/120802/2 "2024-11-19T17:06:36Z")

</div>

Hi @DProdigitas, I hope that you are well!  
Thanks for asking the Community!  
I’d love to put you in touch with some of our Top Experts: Hi @stefen, @alysamwilie and [@Syeda\_Fatima](https://community.hubspot.com/t5/user/viewprofilepage/user-id/114957) do you have suggestions to help @DProdigitas, please?  
Thanks so much and have a beautiful day!  
Best,  
Bérangère

---

<div class="post-metadata">

**Author:** ![GRajput](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/grajput/32/102020_2.png) [@GRajput](https://community.hubspot.com/u/GRajput)\
**Post date:** [November 20, 2024, 6:45am UTC](https://community.hubspot.com/t/setup-custom-cookie-at-users-browser/120802/3 "2024-11-20T06:45:41Z")

</div>

Hi @DProdigitas

Hey, Here is a slightly modified version of your code.

```lia-code-sample
 function setCookie(name, value, days) {
 var d = new Date();
 d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
 var expires = "expires=" + d.toUTCString();
 document.cookie = name + "=" + value + ";path=/;" + expires;
}

// Example usage
setCookie("userEmail", "example@email.com", 7);

```

Also please check your cookie settings in HubSpot and make sure it’s enabled.

I hope this will help you out. Please mark it as **Solution Accepted and upvote** to help another Community member.  
Thanks!

---

<div class="post-metadata">

**Author:** ![DProdigitas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dprodigitas/32/14727_2.png) [@DProdigitas](https://community.hubspot.com/u/DProdigitas)\
**Post date:** [November 24, 2024, 2:08pm UTC](https://community.hubspot.com/t/setup-custom-cookie-at-users-browser/120802/4 "2024-11-24T14:08:17Z")

</div>

Hi @GRajput Thanks for your response,

I tried the same code but it was not working, unable to set cookie value at user’s browser. Can you please provide us better option using JavaScript or HubL code.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Berangere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/berangere/32/220784_2.png) [@Berangere](https://community.hubspot.com/u/Berangere)\
**Post date:** [January 21, 2025, 12:33pm UTC](https://community.hubspot.com/t/setup-custom-cookie-at-users-browser/120802/5 "2025-01-21T12:33:03Z")

</div>

Hi @DProdigitas, I hope that you are well!  
I have found similar threads that might guide you in the right direction:  
- The solution from @bpotter on this post “[Javascript Cookie Values passed into Hubspot Form](https://community.hubspot.com/t5/CMS-Development/Javascript-Cookie-Values-passed-into-Hubspot-Form/m-p/219014)”  
- The solution from @stefen on this post “[Set Cookie from URL Parameter and using it in HTML on a different page.](https://community.hubspot.com/t5/CMS-Development/Set-Cookie-from-URL-Parameter-and-using-it-in-HTML-on-a/m-p/4067)”  
- The solution from @Teun on this post “[Utilizing cookie data in a form id](https://community.hubspot.com/t5/CMS-Development/Utilizing-cookie-data-in-a-form-id/m-p/493197)”  
- The solution from @tjoyce on this post “[Javascript Cookie Values passed into Hubspot Form](https://community.hubspot.com/t5/CMS-Development/Javascript-Cookie-Values-passed-into-Hubspot-Form/m-p/201458)”  
Also, I’d love to put you in touch with some of our Top Experts and Community Members: Hi @gweaver, @thompsonsj, @MTicudean, @REVEALiO, @DevM, [@zach\_threadint](https://community.hubspot.com/t5/user/viewprofilepage/user-id/324811), @Kevin-C and @jeremymandle do you have suggestions to help @DProdigitas, please?  
Have a wonderful day and thanks so much!  
Best,  
Bérangère
