- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Capture cookie info with hidden form fields
SOLVEMar 7, 2019 5:57 AM - edited Mar 7, 2019 6:34 AM
Hi guys,
I'm trying to capture cookie info from these cookies:
- STYXKEY-huddleReferer
- STYXKEY-huddleSource
- STYXKEY-huddleTracker
I've insersted each of the below as hidden form fields:
- where_hear_about_huddle__c
- search_cookie_source__c
- search_cookie_medium__c
I've udpated the Hubspot embed code as below but I'm unable to pull through the cookie data...
<!--[if lte IE 8]> <script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script> <![endif]--><script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script><script> hbspt.forms.create({ portalId: "MY-HUBSPOT-ID-XXXX", formId: "MY-FORM-ID-XXXX", onFormSubmit: function($form) { jQuery('input[name="web_activity_most_recent__c"]').val('Request_a_Demo_Generic').change(); jQuery('input[name="search_cookie_source__c"]').val(readCookie('STYXKEY-huddleSource')).change(); jQuery('input[name="search_cookie_medium__c"]').val(readCookie('STYXKEY-huddleReferer')).change(); jQuery('input[name="where_hear_about_huddle__c"]').val(readCookie('STYXKEY-huddleTracker')).change(); }, redirectUrl: "/get-started/confirmation/" }); </script>
The cookies are being created and capturing info - snapshot below:
Any help with be much appreciated.
Thanks,
Marc
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Accepted Solutions
Mar 8, 2019 11:16 AM
Hi @marclosper , this seems fine to me. How are you getting the cookies from the page? I'm using this function on my page to get the Cookies by name:
window.getCookie = function(name) { var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); if (match) return match[2]; }
Then, I change the value of the hidden field on submit:
hbspt.forms.create({
portalId: "3430672",
formId: "983fd305-bdd3-40be-bc25-59be5f5650a8",
css: "",
onFormSubmit: function($form){
$("input[name='cookie']").val(getCookie("hubspotutk")).change(); }, redirectUrl: "http://www.playtimepottery.net/redirect" });
This worked for me as you can see on my contact: http://prntscr.com/mv4b7n
If you check out this page and inspect it with Chrome Dev Tools you can see the code for yourself: https://www.playtimepottery.net/on-form-submit
That said, the issue is definitely with how you're grabbing the cookies. When I plug readCookie('STYXKEY-huddleTracker') into the console, I get undefined. I'd go ahead and use the code I wrote above, which works, instead of the readCookie function as it doesn't appear to be behaving as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content