Last active
May 9, 2016 22:27
-
-
Save mohsinrasool/ced716814be01af8652a to your computer and use it in GitHub Desktop.
Track google analytics click event in in 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 | |
// track conversions in Gravity Forms | |
function add_conversion_tracking_code($button, $form) { | |
$dom = new DOMDocument(); | |
$dom->loadHTML($button); | |
$input = $dom->getElementsByTagName('input')->item(0); | |
if ($input->hasAttribute('onclick')) { | |
$input->setAttribute("onclick","ga('send', 'click', 'submit');".$input->getAttribute("onclick")); | |
} else { | |
$input->setAttribute("onclick","ga('send', 'click', 'submit');"); | |
} | |
return $dom->saveHtml(); | |
} | |
add_filter( 'gform_submit_button_1', 'add_conversion_tracking_code', 10, 2); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment