Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techjewel/0c8fc643b914a35d093217f966dde112 to your computer and use it in GitHub Desktop.
Save techjewel/0c8fc643b914a35d093217f966dde112 to your computer and use it in GitHub Desktop.
<?php
/*
* Add the folliwing code to your theme's functions.php file.
* This code will only load if a page has fluent forms.
*/
add_action('fluentform_before_form_render', function () {
static $isloaded = false;
if($isloaded) {
return;
}
$isloaded = true;
add_action('wp_footer', function () {
?>
<script>
(function($){
if(typeof gtag != 'function') {
return;
}
var fluentForms = $('form.frm-fluent-form');
fluentForms.each(function() {
var $form = $(this);
var formId = $form.attr('data-form_id');
gtag('event', 'ViewForm', {
'event_category': 'FluentForms',
'event_label': 'View Form',
'form_id': formId
});
$form.on('fluentform_submission_success', function() {
gtag('event', 'FormSubmission', {
'event_category': 'FluentForms',
'event_label': 'Form Submitted',
'form_id': formId
});
});
});
}(jQuery));
</script>
<?php
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment