We currently have a custom form that communicate with our backend server for users to download our software, since it is custom coded we are not accurately tracking where our users are coming from and the conversion rate of each traffic channel.
Looking at the form on our site, I see that it's calling a .php document with this code snippet:
// May 2016 - Post Free Downloads leads to HubSpot too
$hs_form_id = "317069ee-049f-4db1-9934-20311bef48a1";
// $hs_pageUrl = "http://www.rti.com/downloads/index.html";
$hs_pageUrl = "https://www.rti.com/free-trial";
$hs_pageName = "RTI Free Downloads Application";
...
$result = post_to_hubspot($hs_form_id, $clean_post, $hs_pageUrl,
$hs_pageName);
where post_to_hubspot is an additional .php form for additional code:
<?php
/**
* Submit form data to HubSpot
*
* Process a new form submission in HubSpot in order to create a new Contact.
* http://developers.hubspot.com/docs/methods/forms/submit_form
*/
function post_to_hubspot($formId, $params, $hs_pageUrl = null, $hs_pageName = null) {
//grab cookie from browser
if (isset($_COOKIE['hubspotutk'])) {
$hubspotutk = $_COOKIE['hubspotutk'];
} else {
$hubspotutk = "";
}
$ip_addr = $_SERVER['REMOTE_ADDR']; // log IP address too.
$hs_context = array(
'hutk' => $hubspotutk,
'ipAddress' => $ip_addr
);
// Two optional parameters
if (!empty($hs_pageUrl)) {
$hs_context['pageUrl'] = $hs_pageUrl;
}
if (!empty($hs_pageName)) {
$hs_context['pageName'] = $hs_pageName;
}
$hs_context_json = json_encode($hs_context);
//Need to populate these varilables with values from the form.
$str_post = http_build_query($params);
$str_post .= "&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 = 'https://forms.hubspot.com/uploads/form/v2/1754418/' . $formId;
// error_log("Posting to form $formId with added data " . print_r($hs_context, true), 0);
error_log("curl " . $endpoint . $formId . "?" . $str_post, 0);
$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(
'Content-Type: application/x-www-form-urlencoded'
));
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch); //Log the response from HubSpot as needed.
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code
@curl_close($ch);
return($status_code);
}
// vim: expandtab sw=4 tabstop=4 softtabstop=4
?>
As of right now, we are getting the # of downloads and contact information. However we are not getting conversion rate for all pageviews, or conversion rate for each of the traffic channel.
Any insights on what we are currently missing on the code snippets posted above is greatly appreciated.