Pass HSContent cookie value to hidden form field


Hi guys, long story short

Im creating a survey with a custom form and I develop with CUSTOM MODULE in hubspot. I finished  the form with the opening like this:

<form id="msform" action="" method="post">

but when I tried to submit, it said my IP address cookie was not being passed so I have to add a hidden field :

<input type="hidden" id="something" name="hs_context" value="">

I follow this documentation:


and what I needed to do is pulling the cookie from this REQUEST BODY with the example like this:

Im gonna use javascript to do this task, can someone help me with a full functional code to help me achieve this?


1 Reply 1
HubSpot Employee

Hi @zendersto,


I hope all is well with you 😄


When looking to get the cookie from the hs_context, you can use something like this:

function hubspotCookie() {
  return document.cookie.replace(/(?:(?:^|.*;\s*)hubspotutk\s*\=\s*([^;]*).*$)|^.*$/, "$1");


As reference from this documentation: Integrating Hubspot with Inspectlet – Inspectlet.


Hope this helps to clarify!