APIs & Integrations

claudvilla
Member

Form API not setting page views data in new contacts

Hello,

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.

Thanks,

0 Upvotes
15 Replies 15
claudvilla
Member

Form API not setting page views data in new contacts

Hello @pmanca

Have you got any chance to look into this?

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Form API not setting page views data in new contacts

@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.

0 Upvotes
claudvilla
Member

Form API not setting page views data in new contacts

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:

$url: https://forms.hubspot.com/uploads/form/v2/XXXXX/YYYYYYYYYY

$postStr: dataOrigin=wordpress&firstname=Claudia&lastname=Villamizar&email=claudia.villamizar%40e-zigurat.com&phone=49653872986&hs_context=%257B%2522hutk%2522%253A%25229d4e3e817e763af63eb2002f3f95ff78%2522%252C%2522ipAddress%2522%253A%252284.78.18.19%2522%252C%2522pageUrl%2522%253A%2522https%253A%255C%252F%255C%252Fwww.e-zigurat.com%255C%252Fstructural%255C%252Fmaster-internacional-estructuras-concreto%255C%252F%2522%252C%2522pageName%2522%253A%2522M%255Cu00e1ster%2BInternacional%2Ben%2BProyectos%2BSismorresistentes%2Bde%2BEstructuras%2Bde%2BConcreto%2BArmado%2By%2BPrecomprimido%2522%257D&country_custom=DE&jobtitle_custom=1&message=Test&Explotacion=MCA

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Form API not setting page views data in new contacts

@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?

0 Upvotes
claudvilla
Member

Form API not setting page views data in new contacts

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);

0 Upvotes
claudvilla
Member

Form API not setting page views data in new contacts

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

Thank you very much for your help

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Form API not setting page views data in new contacts

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

3PETE
HubSpot Employee
HubSpot Employee

Form API not setting page views data in new contacts

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

{
    "hutk": "60c2ccdfe4892f0fa0593940b12c11aa", 
    "ipAddress": "192.168.1.12", 
    "pageUrl": "http://demo.hubapi.com/contact/", 
    "pageName": "Contact Us", 
    "redirectUrl": "http://demo.hubapi.com/thank-you/"     
}

Here is a link to the docs just in case.

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...

0 Upvotes
claudvilla
Member

Form API not setting page views data in new contacts

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

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Form API not setting page views data in new contacts

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

0 Upvotes
claudvilla
Member

Form API not setting page views data in new contacts

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.

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Form API not setting page views data in new contacts

@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?

0 Upvotes
claudvilla
Member

Form API not setting page views data in new contacts

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

This is a test contact:

https://app.hubspot.com/contacts/2908376/contact/15731451/

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

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Form API not setting page views data in new contacts

@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?

Gracias

0 Upvotes
claudvilla
Member

Form API not setting page views data in new contacts

Yes, the form is the one called Form Wordpress. This is the page where the form is: https://www.e-zigurat.com/structural/master-internacional-en-estructuras-de-edificacion-con-cype/

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

0 Upvotes