Hi everyone!
We’re trying to connect a custom sign-up form on our website to the Hubspot Forms API and running into some issues.
We’re pushing page views to window._hsq on page transition via https://developers.hubspot.com/docs/methods/tracking_code_api/identify_visitor. Think this is working.
// init
var isInit = true;
// on $state transition
$transitions.onSuccess({}, function (transition) {
// define hub spot object
$window._hsq = $window._hsq || [];
// send $state to hubspot
$window._hsq.push([ 'setPath', transition.to().url ]);
// if not init -> tell hubspot to track this page view
// not required on init https://developers.hubspot.com/docs/methods/tracking_code_api/tracking_code_overview#spa
if (!isInit) $window._hsq.push([ 'trackPageView' ]);
// tip isInit
isInit = false;
});
Then we’re sending user data to Hubspot via https://developers.hubspot.com/docs/methods/forms/submit_form_v3.
// define data
var data = {
"portalId": "1229789",
"formGuid": "e651236b-4d20-453e-a0d6-76f7330e1238",
"submittedAt": 1542718668884,
"fields":[
{
"name": "firstname",
"value": "a"
},
{
"name": "lastname",
"value": "b"
},
{
"name": "email",
"value": "a@c.com"
}
],
"context":{
"hutk": "5ed4d4eec89b95727d50742cb49507bb",
"pageName": "un-auth-signup",
"pageUri": "/signup?iframe&email"
}
};
return $http.post('https://api.hsforms.com/submissions/v3/integration/submit/4920989/f561b96b-4d20-453e-a0d6-76f7456e2438', data);
The response is erroring out for us in Angular:
- status: -1
- xhrStatus: “error”
Any idea what we need to do differently? Much appreciated!
Abby
