Created
March 15, 2018 16:45
-
-
Save RitwikGA/9146e1914789dd919828b418550f5643 to your computer and use it in GitHub Desktop.
Track Gravity Forms in Google Tag Manager
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 | |
add_action( 'gform_after_submission', 'access_entry_via_field', 10, 2 ); | |
function access_entry_via_field( $entry, $form ) { | |
echo "<script>var entryField = ". json_encode($entry) .";", | |
"var formData = ". json_encode($form) .";", | |
"var dataLayer = window.dataLayer || [];", | |
"dataLayer.push({'event':'formSubmit','formTitle': formData['title'] + ' ('+formData['id']+')','submissionID':entryField['id'],'formFields':entryField });", | |
"console.log(dataLayer)</script>"; | |
}; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment