Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Created September 15, 2016 20:37
Show Gist options
  • Select an option

  • Save ronalfy/210fe1e3d60e5358d616662e23d879ea to your computer and use it in GitHub Desktop.

Select an option

Save ronalfy/210fe1e3d60e5358d616662e23d879ea to your computer and use it in GitHub Desktop.
Google Tag Manager for Gravity Forms
<?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