Contact creation via the Events Javascript API


#1

Hi,

The javascript API documentation says the “identify” method will create a new contact if one doesn’t already exist.
However, when I call it from our application, no contact gets created. I’ve verified that the analytics tracking code is loaded and the _hsq queue exists. I’m calling the identify method as follows:

_hsq.push(["identify", {
    email: "my-email@example.com",
    firstname: "MyFirstName",
    lastname: "MyLastname"
}]);

Is there anything I’m missing to get this working?


#2

I’m also having a similar issue. Did you have any luck getting this working @emile?


#3

Hi @emile,

I suspect that there is an issue with the order in which items are added to the _hsq array here. As mentioned within the docs for the Events JS API ::

Note: Identities should be pushed as soon as possible, to make sure that the identities are pushed to HubSpot, since identities will only be passed to HubSpot with an event or when the tracking code loads on the page. Simply calling the identify method will not push the identities to HubSpot.

One of two things needs to happen here; either a) the user identity element is pushed to the _hsq array before the HS tracking code is loaded, or a HS event has to fire after the identity is pushed to the array. Please try either of these and let me know how you go.


#4

I never managed to get this working and ended up using the Contacts API instead.

I can’t remember if I fired an event after the identity was pushed as @kfischmann suggests below. Have you tried that?


#5

Thanks for the help. I’ll try out the approach @kfischmann suggested and see how I go.


#6

This is working for me now. I think it was related to my previous issue where the “Clicked Element” tracking events with jquery selectors weren’t firing on a single page app. It’s working after switching to use the “trackEvent” method instead.
Thanks.