Using the documentation provided here: https://developers.hubspot.com/docs/methods/forms/submit_form
I managed to send data to a hubspot form, with the only issue that the original source it’s incorrect.
I cleared cookies, simulated a visitor coming from another website, even added tracking URL like ?utm_source=facebook&utm_medium=social&utm_campaign=xyz but every time the original source is set as Direct Traffic and Original source drill-down 1 is set to the page added in the $hs_context ( ‘pageUrl’ ) Also First page seen is set to the same URL
I expect that URL to be the URL the form is submitted on and not the Original Source.
What am I doing wrong?
//Process a new form submission in HubSpot in order to create a new Contact.
$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’ => ‘https://random.url’,
‘pageName’ => ‘Lead Form’
$hs_context_json = json_encode($hs_context);
//Need to populate these variable with values from the form.
$str_post = “firstname=” . urlencode($full_name)
. “&lastname=” . urlencode($full_name)
. “&email=” . urlencode($email_address)
. “&phone=” . urlencode($phone_number)
. “&hs_context=” . urlencode($hs_context_json); //Leave this one be
//replace the values in this URL with your portal ID and your form GUID
$endpoint = ‘removed for privacy’;
$ch = #curl_init();
#curl_setopt($ch, CURLOPT_POST, true);
#curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post);
#curl_setopt($ch, CURLOPT_URL, $endpoint);
#curl_setopt($ch, CURLOPT_HTTPHEADER, array(
#curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
#curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = #curl_exec($ch); //Log the response from HubSpot as needed.
$status_code = #curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code
$curlerror = #curl_error($ch);
I had to replace @ with # for this topic so I can post the message (new user limitations)