A contact is not create using with javascript API


#1

Hi,

I have a form to submit a new contact. On submit event JS, I use the javascript API to identify a contact.

I noticed :

The data will only be passed when tracking a pageview or an event

So I make the following script

var _hsq = window._hsq = window._hsq || [];
$('#form').submit(function (event) {
    event.preventDefault();
    _hsq.push(['identify',{
        email: $('#email').val()
    }]);
    _hsq.push(['trackEvent', {
        id: 'Captation'
    }]);

});

But the contact is not created on HubSpot.

I try with the trackPageView

var _hsq = window._hsq = window._hsq || [];
$('#form').submit(function (event) {
    event.preventDefault();
    _hsq.push(['identify',{
        email: "'"+$('#email').val()+"'"
    }]);
    _hsq.push(['setPath', window.location.pathname]);
    _hsq.push(['trackPageView']);
    _hsq.push(['trackEvent', {
        id: 'Captation'
    }]);

});

The contact is not created on HubSpot.

What is wrong ?


#2

Hi @laupifrpar,

Is there a reason you’re calling the identify method on a form submit? It sounds like the identify method isn’t being called before the page redirects after the form submission. Can you give me some more details on this setup?


#3

Hi @Derek_Gervais,

When a visitor wants to order, we want get his name, email and phone first.

We want create the contact on HubSpot with origin before to update with extra data with the API. The updating of extra data is the after the form submission.


#4

Hi @laupifrpar,

Is the form a custom HTML form? You might consider passing the form values to HubSpot using the forms API instead, or maybe using the tracking code API on the subsequent thank you page?


#5

Thanks,

I finally use the tracking code API on the next page.