-
-
Save dexit/a6bcf91aebe20bf844ec3a9a221e988f to your computer and use it in GitHub Desktop.
Google Tag Manager 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 | |
| add_action( 'gform_after_submission', 'braums_after_submission', 10, 2 ); | |
| function braums_after_submission( $entry, $form ) { | |
| ?> | |
| <script> | |
| function braums_datalayer_push() { | |
| var form_submission = sessionStorage.getItem('entry_<?php echo absint( $entry[ 'id' ] ); ?>'); | |
| if ( null == form_submission ) { | |
| if ( typeof( dataLayer ) != 'undefined' ) { | |
| dataLayer.push({'event': 'BWTrackEvent', | |
| 'BWTrackCategory':'Form Submit', | |
| 'BWTrackAction':'form-submit', | |
| 'BWTrackLabel':'{{<?php echo esc_js( $form['title'] ); ?>}}::{{<?php echo esc_js( $entry['id'] ); ?>}}', | |
| 'BWEntryData':<?php echo json_encode( $entry ); ?> | |
| }); | |
| sessionStorage.setItem("entry_<?php echo absint( $entry[ 'id' ] ); ?>", "true"); | |
| } | |
| } | |
| } | |
| braums_datalayer_push(); | |
| </script> | |
| <?php | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment