Created
March 2, 2012 22:52
-
-
Save jloosli/1962059 to your computer and use it in GitHub Desktop.
Google Analytics Ecommerce notification for Gravity Forms
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
<?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; | |
} |
@jg314 have found your answer? I am dealing with the same. Thx
@honzapav, What did you end up doing? I can't seem to find anything, and Gravity Forms just plays stupid about it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is exactly what we're looking for. Where are you calling this function from? What hook are you using in Gravity Forms?