Form API not setting page views data in new contacts


#1

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,


#2

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


#3

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


#4

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


#5

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.


#6

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


#7

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.


#8

@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


#9

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.


#10

Hello @pmanca

Have you got any chance to look into this?


#11

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


#12

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


#13

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


#14

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


#15

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

Thank you very much for your help


#16

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