Skip to content

Instantly share code, notes, and snippets.

@bluantinoo
Forked from jloosli/gf_analytics.php
Created February 4, 2013 18:34
Show Gist options
  • Save bluantinoo/4708595 to your computer and use it in GitHub Desktop.
Save bluantinoo/4708595 to your computer and use it in GitHub Desktop.
<?php
function analytics_confirmation($confirmation, $form, $entry, $ajax = 0)
{
$isProduct = false;
foreach ($form['fields'] as $field) {
if ($field['type'] == 'product') {
$isProduct = true;
$fieldID = $field['id'];
$productSKU = $form['id'] . '-' . str_replace(" ", "_", $field['label']);
break;
}
}
if ($isProduct) {
if (in_array($entry['payment_status'], array('Approved', 'Processing'))) {
$id = $entry['id'];
$amt = ($entry['payment_amount'] != '') ? $entry['payment_amount'] : floatval($entry["$fieldID.2"]);
$js = <<<HTML
<script>
var _gaq = _gaq || [];
_gaq.push(['_trackPageview','/checkedout']);
_gaq.push(['_addTrans'
'{$id}',
'Store',
'{$amt}',
'',
'',
'',
'',
'',
''
]);
_gaq.push(['_addItem',
'{$id}',
'{$productSKU}',
'{$productSKU}',
'',
'{$amt}',
'1'
]);
_gaq.push(['_trackTrans']);
</script>
HTML;
if (is_array($confirmation)) {
$redirect = $confirmation['redirect'];
$confirmation = $js;
$confirmation .= "\n<script>window.location='$redirect'</script>";
} else {
$confirmation .= $js;
}
}
}
return $confirmation;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment