Created
August 6, 2020 11:38
-
-
Save techjewel/0c8fc643b914a35d093217f966dde112 to your computer and use it in GitHub Desktop.
This file contains 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 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