Traffic source not set for API form


#1

Hello,

The source for all contacts being created via a form submission is set to “Direct Traffic”. Looking at other topics on this issue has been helpful, but I’m still not sure why that’s the case in our app.

We have cross-domain tracking enabled on our marketing site domain and app domain, with the tracking code installed on both. I can see that the value for the hutk cookie is being set correctly to the same value in my browser on both domains.

For my test, I did the following:

  • Deleted all cookies for both the marking site domain and app domain
  • Performed a search on Google for the name of our app. Google showed our marketing site in the results
  • Clicked on the marketing site in the Google search result
  • From the marketing page, clicked on the link to start a trial, which redirects the user to the app
  • Completed the trial workflow in the app, which submits a form request to Hubspot on the last step of the workflow.

Looking over the form submission, I can see that the value for hutk, pageName, and pageUrl were all submitted correctly. I’ve attached a screenshot showing this.

However, the source for this test contact is still showing as “Direct Traffic”.

Here’s a link to the contact:
https://app.hubspot.com/contacts/2593467/contact/177451/

I have a feeling that the contacts weren’t merged properly, because when looking up the associated contacts by utk in the Hubspot API by email addresses, I see what looks like two different contacts with different vid’s.

Any help with this would be appreciated.

Thanks,
Manny


#2

Here is a screenshot from the Hubspot site, showing the form submission for this contact:


#3

Hi @MannyR

The data in the hs_context field is treated as metadata for the submission, so it should not show up in the form submission data in HubSpot. If you’re seeing entries for those items in HubSpot, there’s likely an issue with how the hs_context data is formatted in the POST request, so the data isn’t actually being processed.

Do you have an example of the POST body from one of the submissions?


#4

@dadams, thanks for the help. I was able to resolve my issue – the problem was that I was not encoding the params as JSON properly. I’m seeing the analytics data come through now.


#5

Manny - I’m having the same issue. Would you mind sharing your script/code? What we’re using looks right, but it’s not picking up the cookie for some reason. Everything is showing “direct traffic.” Our PHP code is here:
(note: the “@” symbol has been replaced with the text “[at]” because this forum thinks those “at symbols” are mentions of other users and there’s a limit to the number of users you can “at mention.” LOL!)

if(isset($_POST[‘firstname’])) $firstname = $_POST[‘firstname’];
if(isset($_POST[‘lastname’])) $lastname = $_POST[‘lastname’];
if(isset($_POST[‘email’])) $email = $_POST[‘email’];
if(isset($_POST[‘hs_persona’])) $hs_persona = $_POST[‘hs_persona’];
if(isset($_POST[‘company_size’])) $company_size = $_POST[‘company_size’];
if(isset($_POST[‘phone’])) $sms_number = $_POST[‘phone’];
if(isset($_POST[‘MERGE1’])) $MERGE1= htmlentities($_POST[‘MERGE1’]);
if(isset($_POST[‘MERGE2’])) $MERGE2= htmlentities($_POST[‘MERGE2’]);
if(isset($_POST[‘MERGE3’])) $MERGE3= htmlentities($_POST[‘MERGE3’]);
if(isset($_POST[‘MERGE5’])) $MERGE5= htmlentities($_POST[‘MERGE5’]);
$hubspotutk = $_COOKIE[‘hubspotutk’]; //grab the cookie from the visitors browser.
$ip_addr = $_SERVER[‘REMOTE_ADDR’]; //IP address too.
$hs_context = array(
‘hutk’ => $hubspotutk,
‘ipAddress’ => $ip_addr,
‘pageUrl’ => ‘http://www.ourdomaingoeshere.com/register/?id=n35hsmwj8z’,
‘pageName’ => $MERGE2
);
$hs_context_json = json_encode($hs_context);

//Need to populate these variable with values from the form.
$str_post = “firstname=” . urlencode($firstname)
. “&lastname=” . urlencode($lastname)
. “&email=” . urlencode($email)
. “&phone=” . urlencode($sms_number)
. “&hs_persona=” . urlencode($hs_persona)
. “&company_size=” . urlencode($company_size)
. “&event_date=” . urlencode($MERGE1)
. “&event_title=” . urlencode($MERGE2)
. “&event_id=” . urlencode($MERGE3)
. “&event_time=” . urlencode($MERGE5)
. “&hs_context=” . urlencode($hs_context_json);

//replace the values in this URL with your portal ID and your form GUID
$endpoint = ‘https://forms.hubspot.com/uploads/form/v2/[our portal id]/[our form id]’;

$ch = [at]curl_init();
[at]curl_setopt($ch, CURLOPT_POST, true);
[at]curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post);
[at]curl_setopt($ch, CURLOPT_URL, $endpoint);
[at]curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/x-www-form-urlencoded’
));
[at]curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = [at]curl_exec($ch); //Log the response from HubSpot as needed.
$status_code = [at]curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code
[at]curl_close($ch);
//echo $status_code . " " . $response;
header(“Location:http://www.ourdomaingoeshere.com/seminar/?id=$MERGE3&email=$email&name=$firstname”);


#6

@MannyR - didn’t at mention you on the comment above… wondering if you could help a brother out. Thanks!