Description
The gform_googleanalytics_submission_event_name
filter hook can be used to filter the name of the submission event to be sent to Google Analytics. This filter only applies to Google Analytics or Measurement Protocol (not Tag Manager).
Note: For more information about restrictions on resetting the event name, refer to [GA4] Event naming rules – Analytics Help.
Usage
Applies to all forms:
add_action( 'gform_googleanalytics_submission_event_name', 'your_function_name', 10, 5 );
Parameters
- $event_name string
The event name sent to Google Analytics. Default isgforms_submission
. - $feed Feed Object
The feed currently being processed. - $entry Entry Object
The entry currently being processed. - $form Form Object
The form currently being processed.
Examples
1. Append form ID to event name
add_filter( 'gform_googleanalytics_submission_event_name', function( $event_name, $mode, $feed, $entry, $form ) {
return "{$event_name}_{$form['id']}";
}, 10, 5 );
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Since
This action hook was added in Google Analytics v2.0.0
Source Code
This action hook is located in class GF_Google_Analytics
in /class-gf-google-analytics.php.