Last active
February 9, 2018 22:57
-
-
Save flowtwo/9adb8c3e2716dd80e78a97686783e17a to your computer and use it in GitHub Desktop.
ClickDimensions Programmatic Form Capture via PHP cURL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define constants | |
$cd_url = 'https://analytics-eu.clickdimensions.com/forms/h/foobar'; // copy from ClickDimensions | |
$cd_accountkey = 'foo'; // copy from ClickDimensions | |
$cd_domain = 'bar'; // copy from ClickDimensions | |
// Build fields (array) to ClickDimensions, matching keys and values | |
$fields = array( | |
'FirstName' => 'John', // retrieve from posted form | |
'LastName' => 'Doe', // retrieve from posted form | |
'Email' => '[email protected]', // retrieve from posted form | |
'cd_visitorkey' => 'foobar', // retrieve from the cookie: cuvid | |
); | |
// Define header | |
$headers = array( | |
'Content-Type: application/x-www-form-urlencoded;', | |
'Charset: UTF-8;', | |
'Referer: http://foobar.com/;' // ensure allowed domain is defined at ClickDimensions | |
); | |
// Setup cURL | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_URL => $cd_url, | |
CURLOPT_HTTPHEADER => $headers, | |
CURLOPT_POST => TRUE, | |
CURLOPT_POSTFIELDS => http_build_query( $fields ), | |
CURLOPT_RETURNTRANSFER => TRUE, | |
CURLOPT_VERBOSE => TRUE, | |
CURLINFO_HEADER_OUT => TRUE | |
)); | |
$request = curl_getinfo($curl); | |
// Handle response | |
$response = curl_exec($curl); | |
curl_close($curl); | |
// Print each segment for debugging | |
echo '<h3>CURL HEADERS</h3>'; | |
echo '<pre>'. print_r($headers, true ). '</pre>'; | |
echo '<h3>CURL POST FIELDS</h3>'; | |
echo '<pre>'. print_r($fields, true ). '</pre>'; | |
echo '<h3>CURL REQUEST</h3>'; | |
echo '<pre>'. print_r($request, true ). '</pre>'; | |
echo '<hr/>'; | |
echo '<h3>CD RESPONSE</h3>'; | |
echo '<pre>'. print_r($response, true ). '</pre>'; |
@Smus were you able to figure it out? For me, it's posting and a posted form is acknowledged, but no data is stored.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @flowtwo and @pamelalies
I managed to create new Contacts, but it only use the email address for the new Contact, it dosnt apply the FirstName and LastName aswell... any ideas?