Form API not setting page views data in new contacts



I am using the form API for submits in my page and I am not getting the page views data and original source for new contacts. On already existing contacts I do get the contact’s activity on my page.

I don’t know if there is any restriction related to new contacts. But when using directly the HubSpot form I do get the info.

I have read related forums and checked all the issues named: cookie tracking enabled, proper encoding, etc. I don’t know what could be the problem, specially because it is working fine with already existing contacts.



@claudvilla Are you including both the page name and page url inside the hs_context object?

    "hutk": "60c2ccdfe4892f0fa0593940b12c11aa", 
    "ipAddress": "", 
    "pageUrl": "", 
    "pageName": "Contact Us", 
    "redirectUrl": ""     

Here is a link to the docs just in case.


Yes, I am including [using PHP]:

$hs_context = [
‘hutk’ => $data[‘hubspotutk’],
‘ipAddress’ => $data[‘ip’],
‘pageUrl’ => $data[‘url’],
‘pageName’ => $data[‘title’],

$hs_context = urlencode(json_encode($hs_context));

I am not using the redirectUrl field, not sure if it is also required


@claudvilla Do you have the tracking code on that page?


Yes, the tracking code is included. Is not working only for new contacts. On already existing contacts, I can see the page visits before the form submit.

Also, I can see the new contact’s activity after the form submission.


@claudvilla Something seems off then for sure. Have you tested with a HubSpot Form? That could ensure that the tracking code is set up everywhere properly. Do you have an example contact you could share with me? Do you know if that contact visited other pages before the landing page with your form on it?


Yes, I have checked with HubSpot forms and they work fine.

This is a test contact:

I search our website on google, visit differente pages and then submit a form.


@claudvilla Can you link me the page as well?

the form submission doesn’t seem to be linking to a page. The page should be clickable and it is odd that is has the same name as your form. Is that correct?



Yes, the form is the one called Form Wordpress. This is the page where the form is:

I am including both the page URL and page name on the submit.


Hello @pmanca

Have you got any chance to look into this?


@claudvilla My apologies for not getting back to this sooner. I don’t see an issue on the page with the tracking code or the form. Can you paste to me the actual API call you make to HubSpot? I would like to see after your code how the actual body of the HTTP call is formatted.


Its ok @pmanca Here are the API call details:

This is the curl request

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postStr);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
$res = json_decode(curl_exec($ch));

And the variable values are:


$postStr: dataOrigin=wordpress&firstname=Claudia&lastname=Villamizar&


@claudvilla It looks like some where along the way it is getting double encoded.

Can you post the full code on how postStr is constructed please?


Yes, this is how it is encoded:

$hs_context = [
‘hutk’ => $data[‘hubspotutk’],
‘ipAddress’ => $data[‘ip’],
‘pageUrl’ => $data[‘url’],
‘pageName’ => $data[‘title’],

$hs_context = urlencode(json_encode($hs_context));

$fields = [
‘dataOrigin’ => $data[‘dataOrigin’] ? $data[‘dataOrigin’] : ‘’,
‘firstname’ => $data[‘nombre’] ? $data[‘nombre’] : ‘’,
‘lastname’ => $data[‘lastname’] ? $data[‘lastname’] : ‘’,
‘email’ => $data[‘email’] ? $data[‘email’] : ‘’,
‘phone’ => $data[‘telefono’] ? $data[‘telefono’] : ‘’,
‘hs_context’ => $hs_context,
‘country_custom’ => $data[‘country’] ? $data[‘country’] : ‘’,
‘jobtitle_custom’ => $data[‘profesion’] ? $data[‘profesion’] : ‘’,
‘message’ => $data[‘comentario’] ? $data[‘comentario’] : ‘’,
$data[‘naturaleza’] => $data[‘interes’] ? $data[‘interes’] : ‘LOST’,

$postStr = http_build_query($fields);


Deleting the urlencode() in the hs_context the problem is solved!

Thank you very much for your help


I’m glad we got to a solution, nicely done!