APIs & Integrations

CNguyen06
Member

Seding Cookies and IP Address to a custom form

SOLVE

Hi! 

 

I am looking for some help on sending cookies and Ip Addresses to a custom Form submission with Javascript. I am getting teh two warnings on the submission. I am having no problem sending all of the data with a custom form ( I am using my own markup as well, so not using the form embed). If I swapped to a form embed and styled out that way would the cookies and IP address be sent with relevant matching form fields? 

 

Best, 

Chris

0 Upvotes
1 Accepted solution
KhushbooP11
Solution
Participant

Seding Cookies and IP Address to a custom form

SOLVE

Hi @CNguyen06,

Yes, if you switch to using HubSpot’s embedded form, it will automatically capture and send the visitor’s cookies and IP address without any extra effort on your part.

HubSpot’s built-in forms come with tracking capabilities that capture user data like cookies, IP addresses, and more.


For custom forms,

If you’re sticking with your own markup and need to capture these details, you’ll need to do a few things.


1. Use window._hsq to get the user’s HubSpot tracking cookie (known as hubspotutk).
const hubspotCookie = document.cookie.split('; ').find(row => row.startsWith('hubspotutk')).split('=')[1];

2. You can use a third-party service like https://ipinfo.io or https://api.ipify.org to get the user’s IP address.
fetch('https://api.ipify.org?format=json')
.then(response => response.json())
.then(data => {
const ipAddress = data.ip;
// Add this IP to your form submission
});

3. Include hubspotutk and ipAddress as hidden fields in your form submission payload, e.g., hubspotutk: hubspotCookie and ip: ipAddress.

4. Use the HubSpot Forms Submission API to submit the form, including the cookie and IP data.

Recommendation:
If possible, switching to the HubSpot embedded form will make things easier, as it’ll handle all tracking automatically and ensure the data is accurate and synced properly. You can still customize the styles using CSS to make it match your design.

I hope it helps, let me know if you need to talk!

Khushboo Pokhriyal

Growth & Operations

GroRapid Labs

LinkedIn | 9315044754 | Email | Website

 

View solution in original post

0 Upvotes
2 Replies 2
KhushbooP11
Solution
Participant

Seding Cookies and IP Address to a custom form

SOLVE

Hi @CNguyen06,

Yes, if you switch to using HubSpot’s embedded form, it will automatically capture and send the visitor’s cookies and IP address without any extra effort on your part.

HubSpot’s built-in forms come with tracking capabilities that capture user data like cookies, IP addresses, and more.


For custom forms,

If you’re sticking with your own markup and need to capture these details, you’ll need to do a few things.


1. Use window._hsq to get the user’s HubSpot tracking cookie (known as hubspotutk).
const hubspotCookie = document.cookie.split('; ').find(row => row.startsWith('hubspotutk')).split('=')[1];

2. You can use a third-party service like https://ipinfo.io or https://api.ipify.org to get the user’s IP address.
fetch('https://api.ipify.org?format=json')
.then(response => response.json())
.then(data => {
const ipAddress = data.ip;
// Add this IP to your form submission
});

3. Include hubspotutk and ipAddress as hidden fields in your form submission payload, e.g., hubspotutk: hubspotCookie and ip: ipAddress.

4. Use the HubSpot Forms Submission API to submit the form, including the cookie and IP data.

Recommendation:
If possible, switching to the HubSpot embedded form will make things easier, as it’ll handle all tracking automatically and ensure the data is accurate and synced properly. You can still customize the styles using CSS to make it match your design.

I hope it helps, let me know if you need to talk!

Khushboo Pokhriyal

Growth & Operations

GroRapid Labs

LinkedIn | 9315044754 | Email | Website

 

0 Upvotes
CNguyen06
Member

Seding Cookies and IP Address to a custom form

SOLVE

Gotcha thanks so much for this response! This is very helpful and was what I was thinking. I am going to swap some of the forms to the embed and unfortunately will probably have to keep one of them as a custom form submit!

0 Upvotes