APIs & Integrations

laupifrpar
Member

A contact is not create using with javascript API

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 ?

0 Upvotes
4 Replies 4
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

A contact is not create using with javascript API

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?

Submit data to a form | HubSpot Forms API

POST https://forms.hubspot.com/uploads/form/v2/:portal_id/:form_guid - Send form submission data to HubSpot. Form submissions from external sources can be made to any registered HubSpot form. You can see a list of forms on your portal by going to...

laupifrpar
Member

A contact is not create using with javascript API

Thanks,

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

Derek_Gervais
HubSpot Alumni
HubSpot Alumni

A contact is not create using with javascript API

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?

0 Upvotes
laupifrpar
Member

A contact is not create using with javascript API

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.

0 Upvotes