Description
Allows the HubSpot submission data to be filtered before being sent to HubSpot.
Usage
The following would apply to all forms:
add_filter( 'gform_hubspot_submission_data', 'your_function_name', 10, 4 );
To target a specific form, append the form id to the hook name. (format: gform_hubspot_submission_data_FORMID):
add_filter( 'gform_hubspot_submission_data_1', 'your_function_name', 10, 4 );
Parameters
- $submission_data array
The HubSpot submission data to be filtered. For more information about the data in this array, see HubSpot’s documentation.
- $feed Feed Object
The current feed.
- $entry Entry Object
The current entry.
- $form Form Object
The current form.
Example
Change value for pageName (Conversion Page)
Use this code to send the title of the WordPress page where the form is embedded to HubSpot as the “Conversion Page”, rather than the default Form Title.
add_filter( 'gform_hubspot_submission_data', 'change_hubspot_submission_data', 10, 4 );
function change_hubspot_submission_data( $submission_data, $feed, $entry, $form ){
global $post;
$title = get_the_title( $post->ID );
$submission_data['context']['pageName'] = $title;
return $submission_data;
}
Remove cookie value
Using the following example a new contact will be created for each form submission, no matter if a cookie was set by the HubSpot tracking script in the visitor’s browser.
add_filter( 'gform_hubspot_submission_data', 'remove_cookie_value', 10, 4 );
function remove_cookie_value( $submission_data, $feed, $entry, $form ){
GFCommon::log_debug( __METHOD__ . '(): running.' );
unset( $submission_data['context']['hutk'] );
return $submission_data;
}
Custom cookie value
This example shows how you can replace the default cookie created by the HubSpot tracking script with your own custom cookie to define the hutk property.
add_filter( 'gform_hubspot_submission_data', 'custom_cookie_value', 10, 4 );
function custom_cookie_value( $submission_data, $feed, $entry, $form ){
$submission_data['context']['hutk'] = rgar( $_COOKIE, 'your-cookie-name' );
return $submission_data;
}
Change pageUri
The following example shows how you can change the context pageUri property, in this case removing the query string.
add_filter( 'gform_hubspot_submission_data', function ( $submission_data ) {
$submission_data['context']['pageUri'] = strtok( $submission_data['context']['pageUri'], '?' );
return $submission_data;
} );
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 filter was added in HubSpot version 1.0.
Source Code
This filter is located in GF_HubSpot::generate_form_submission_object() in class-gf-hubspot.php.