Understanding Events and Identities


We’re getting deeper into our Hubspot implementation and I’m wondering about custom events, specifically javascript API. We have uploaded our contacts into Hubspot and I want to create an event everytime someone makes a purchase in our user portal.

The documentation I’m reading states that email is the preferred identifier, but the .js where I need to include my custom event doesn’t have access to that. We could add it, but I’m not a developer and would prefer to use something like ‘userid’ which we do have and was also created as a contact property when we imported our list.

Would this work?

Something like this;

//Hubspot Custom Event
var _hsq = window._hsq = window._hsq || [];
_hsq.push(["identify", { userid: _userID }]);
_hsq.push(["trackEvent", { id: "Purchase", value: window._accountAmount }]);


Hi @Ron_Kinkade

You can update any writeable contact property with an event, using the identify data, but we’ll only associate the visitor to a contact record if you provide an email. If the visitor was previously associated with a contact (either through a form submission or another event that had the email), you would be able to update the userid property of the contact using an event, but we can’t make that association using a custom property.


Thanks for the response. I think I’m understanding that. So if I imported a
list of existing customers as contacts (email and our own userid), and I
create a custom event to fire in our portal when a customer makes a
purchase - just using userid to identify them won’t be enough?

I need to have the email.

My problem here is that our users don’t have unique email addresses, in
some cases we have multiple users on an account that have the same email…
which is why I was hoping to use userid.

Any ideas?


Want to know what we believe in? *Read about our values


You are correct that the userid would not be enough to identify the visitor as a specific imported contact, you would need the email address.

Email addresses in HubSpot are unique, so you could only have a single HubSpot contact with any specific email. Also, it’s not possible to change the usertoken (the cookie identifying a visitor) association, so once you identify a visitor as a contact, it wouldn’t be possible to move that association to a different contact record. One way to handle this with HubSpot would be to use the email address to ID the specific person, and the tie all visitor data to a contact by email so that you can see everything the person did in one place, and to store multiple userids in the contact record, so you can still see the different accounts they have.