APIs & Integrations

bcx
Participant

Associating visitor IP Address from events with Contact

We are creating contacts via the API, by making an identify call, followed by an event. We'd like to ensure that the IP address of the event is associated with the contact when it is created.

How can we ensure this happens?

From what we can tell, hubspot is not recording the IP address of the visitor when they fire events.

0 Upvotes
14 Replies 14
cbarley
HubSpot Alumni
HubSpot Alumni

Associating visitor IP Address from events with Contact

hi @bcx, are you also making a trackPageView or trackEvent call after the identify method? Since the identify method only stores the data in the tracker, the data must be passed by tracking a pageview or an event. You mentioned that you're using an event, but I want to make sure that it was a JavaScript Event and not an HTTP event. The IP address should be recorded if our tracking code is able to identify one.

So that I have a full picture can you reply with a link to a contact in HubSpot that was created by your event, as well as the page that your event appears on? Thanks!

0 Upvotes
hughejc
Participant | Partner
Participant | Partner

Associating visitor IP Address from events with Contact

Hi @cbarley I'm trying to achieve the same, and we're using the built in trackPageView which the docs make clear is run automatically every time the tracking code runs.

 

However, I have users with hundreds of sessions and thousands of page views who have the IP fields be empty. I had a chat with L1 support and they mentioned that the IP info is only filled in via a Form Submission or someone clicking on an email link, but I really want it to be triggered based on a pageview (since we're dealing with a predominantly logged in user, and it seem silly not to track this value since it is known to the HubSpot servers on load). I've also tried trackEvent without success.

 

Can you advise if there's a way via JavaScript to tell HubSpot's servers to populate the IP address value (and geo-info related to it)?

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Associating visitor IP Address from events with Contact

Hi @hughejc , I'm reaching out internally to see if this information is available on the trackPageView function. The identify call and tracking the page or event would tie the cookie to a contact, but I’m not sure if analytics data by itself is enough to populate the IP. I'll get clarification on this and get back to you as soon as I can.

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Associating visitor IP Address from events with Contact

Hi @hughejc , I verified that we do capture the IP information on all analytics tracking requests, and do use it to look up location information where we can, but IP location information can be unreliable, so if we aren't certain and cannot verify where the request came from, we don't store that in HubSpot. Are you seeing that the location data is always missing? Can you link some example contacts you mentioned that have hundreds of page views but no IP info?

0 Upvotes
hughejc
Participant | Partner
Participant | Partner

Associating visitor IP Address from events with Contact

Thanks for checking in, @cbarley  Have a look at https://app.hubspot.com/contacts/3966505/contact/5968751?interaction=note - you'll see there's a bunch of web visits in the stream, but when you look at the contact properties you'll see that there isn't an IP address anywhere to be seen. 

 

I don't know that the IP address from a JavaScript call is any less reliable than someone filling in a form or clicking on an email link - it is running in the browser of the user, so it is going to be as good a guess as anything else.

 

Appreicate you might not want to be doing the processing/setting out of the box for every web analytic pageview as part of the library default, but if there was a way to tell the JS that we do want to do it, that would work too.

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Associating visitor IP Address from events with Contact

Hi @hughejc , thanks for that example. I'll dig in to see what's happening here. To confirm, is this the case with all contacts that visit your site and are identified via the tracking code api?

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Associating visitor IP Address from events with Contact

Hi @hughejc , I looked more specifically into how the contact properties are set, and it turns out that those do only take email interactions and form submissions into account. 

 

I think using some sort of client-side web service to get the IP address of the visitor, then including it in the identify function is the best workaround I can think of. Something like this article talks about:

https://stackoverflow.com/questions/391979/how-to-get-clients-ip-address-using-javascript

 

Example:

_hsq.push(['setPath', '/secret_page']);
_hsq.push(["identify", {
    email: getParameterByName("email");
    ipaddress: whatever_returned_from_web_service
}]);
_hsq.push(['trackPageView']);`
0 Upvotes
hughejc
Participant | Partner
Participant | Partner

Associating visitor IP Address from events with Contact

Given the user is trigging the JS and the IP address of that user is known when the payload of the pageview is sent to HubSpot, it seems crazy to have to use an additional third party to find the IP address and set it. Even if we set it, the IP Address field is set to be read-only (can't include it as part of an upload - tried that), so it seems like the only real vector to make HubSpot do something that is should do out of the box is to "fake" a form submission (since the support people told me that is a case where it *will* set the email address.

 

Any ideas how to do that given we've turned off the HubSpot auto-form feature (and thus need to do it manually) since the Form feature was too greedy and corrupted our data?

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Associating visitor IP Address from events with Contact

Hey @hughejc , I feel your pain here. I'm not sure the rationale behind not including this info. 

 

I know that the IP address isn't a writeable field via the UI, but I just tested in my own account and was able to successfully write a dummy IP address to it using the identify function with the IP set to a string:

_hsq.push(['setPath', '/secret_page']);
_hsq.push(["identify", {
    email: getParameterByName("email"),
    ipaddress: "1.1.1.1"
}]);

Screenshot 2019-02-13 15.37.28.png

 

I was also able to update to 1.1.1.2.

 

If you did want to go the forms route, you could use our Forms API: 

https://developers.hubspot.com/docs/methods/forms/submit_form_v3

0 Upvotes
hughejc
Participant | Partner
Participant | Partner

Associating visitor IP Address from events with Contact

Passing the IP as an identify property works, but it doesn't result in the geo-ip information being populated.

 

The following code hacks a form submission (in jQuery) and things then work. Painful to need to work around for something like this.

$.post('https://api.hsforms.com/submissions/v3/integration/submit/HUBID/FORMID',JSON.stringify({"fields":[{"name":"email",value:"email@domain.com"}]}),function(data,status){console.log('Data is ${data} and status is ${status}')})
0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Associating visitor IP Address from events with Contact

Ah yeah fair enough, the location data isn't all set, just that particular IP field, so I see what you mean. Glad you got a workaround of sorts to work. I'm bringing this issue up internally with our team to see if this might be on the radar to include IP info in the tracking code and not just through form submissions/email clicks.

 

I'd just like to point out that for each individual form in Hubspot, you'll get up to 1,000 form submission events. Since after 1000 submissions, the oldest data points get dropped, I'd really recommend if you're using this on login, to try working out if the person has ever logged in before, then on subsequent logins, use the identify call.

 

Otherwise, the third party script might actually be the best bet if it returns IP country, state etc. as you could use those fields as well in the identify call. 

 

I absolutely see how this would be a blocker to your processes so I really apologize for the inconvenience here. Again, I'll be reaching out to my team to discuss and can let you know if we plan on developing this feature. 

0 Upvotes
hughejc
Participant | Partner
Participant | Partner

Associating visitor IP Address from events with Contact

Yeah, is pretty painful @cbarley - I appreciate that the load to update the geo-ip info every time might be why the backend team decided not to do this, but then it shouldn't be *too hard* to trigger is only when the IP address changes. Because of the shortcomings, we're having to do something much more jackhammering - running a pretend form submit each time we see a logged in user who's last login date was >1 day ago, which for our user group means probably every single day (they're very very active folks). 

 

If you can get the team to apply the geoip pipeline to the identify command only if the IP has changed (and set the IP) then we won't need to do this and the product will be more valuable for folks out of the box.

 

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Associating visitor IP Address from events with Contact

Hi @hughejc , I appreciate your candor with me, and I agree that the identify function would be far more useful out of the box if it were to include this. I've raised this issue with the team and it doesn't appear to be on the docket for the first half of this year, but I'm pushing to see if we can get this on our roadmap. Thanks for bringing this up!

0 Upvotes
hughejc
Participant | Partner
Participant | Partner

Associating visitor IP Address from events with Contact

^ to be clear that example code was with jQuery and a hack

0 Upvotes