Track form events in Google Tag Manager for analytics and conversion tracking.
Push Form Events to the Data Layer
php
add_action( 'wp_footer', function() {
if ( ! class_exists( 'FORMFORGE_Core' ) ) return;
?>
<script>
window.dataLayer = window.dataLayer || [];
document.addEventListener( 'formforge:submitted', function( e ) {
window.dataLayer.push({
'event': 'formforge_submission',
'formId': e.detail.formId,
'formTitle': e.detail.formTitle,
'submissionId': e.detail.submissionId
});
} );
document.addEventListener( 'formforge:validation_error', function( e ) {
window.dataLayer.push({
'event': 'formforge_error',
'formId': e.detail.formId,
'errors': e.detail.errors
});
} );
document.addEventListener( 'formforge:step_change', function( e ) {
window.dataLayer.push({
'event': 'formforge_step',
'formId': e.detail.formId,
'step': e.detail.currentStep,
'totalSteps': e.detail.totalSteps
});
} );
</script>
<?php
} );GTM Trigger Configuration
Create a Custom Event trigger in GTM:
| Trigger Name | Event Name | Fires On |
|---|---|---|
| Form Forge Submission | formforge_submission | All Custom Events |
| Form Forge Step | formforge_step | All Custom Events |
| Form Forge Error | formforge_error | All Custom Events |
Google Analytics 4 Conversion Tag
Create a GA4 Event tag in GTM:
text
Tag Type: Google Analytics: GA4 Event
Event Name: form_submission
Parameters:
form_id: {{DLV - formId}}
form_title: {{DLV - formTitle}}
Trigger: Form Forge Submission—