Using Gravity Forms ‘gform_hubspot_submission_data’ PHP filter

The gform_hubspot_submission_data Gravity Forms PHP filter allows you to modify the HubSpot submission data before it’s sent to HubSpot.

Usage

A generic example to apply the filter 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. See HubSpot’s documentation for more information about the data in this array.
  • $feed (Feed Object): The current feed.
  • $entry (Entry Object): The current entry.
  • $form (Form Object): The current form.

Examples

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;
}

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;
}

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;
}