The gform_hubspot_output_tracking_script filter allows you to remove the tracking script in Gravity Forms.
Usage
add_filter('gform_hubspot_output_tracking_script', 'your_function_name', 10, 1);
Parameters
- $add_tracking (bool) – Whether to output the tracking script. The default is true.
More information
See Gravity Forms Docs: gform_hubspot_output_tracking_script
This filter was added in HubSpot version 1.0.
Examples
Disable HubSpot tracking script
Disable the HubSpot tracking script globally.
function disable_hubspot_tracking($add_tracking) { // Set $add_tracking to false return false; }
add_filter(‘gform_hubspot_output_tracking_script’, ‘disable_hubspot_tracking’, 10, 1);
Enable tracking script only on specific pages
Enable HubSpot tracking script only on specific pages by checking the page ID.
function enable_tracking_on_specific_pages($add_tracking) { // Replace 2, 3, 4 with the desired page IDs $allowed_pages = array(2, 3, 4); if (in_array(get_the_ID(), $allowed_pages)) { return true; } return false; } add_filter('gform_hubspot_output_tracking_script', 'enable_tracking_on_specific_pages', 10, 1);
Enable tracking script for logged-in users only
Enable HubSpot tracking script only for logged-in users.
function enable_tracking_for_logged_in_users($add_tracking) { if (is_user_logged_in()) { return true; } return false; } add_filter('gform_hubspot_output_tracking_script', 'enable_tracking_for_logged_in_users', 10, 1);
Disable tracking script on a custom post type
Disable HubSpot tracking script on a specific custom post type.
function disable_tracking_on_custom_post_type($add_tracking) { // Replace 'your_custom_post_type' with the desired custom post type if (get_post_type() === 'your_custom_post_type') { return false; } return $add_tracking; } add_filter('gform_hubspot_output_tracking_script', 'disable_tracking_on_custom_post_type', 10, 1);
Enable tracking script based on user role
Enable HubSpot tracking script only for users with a specific role.
function enable_tracking_for_specific_role($add_tracking) { // Replace 'editor' with the desired user role if (current_user_can('editor')) { return true; } return false; } add_filter('gform_hubspot_output_tracking_script', 'enable_tracking_for_specific_role', 10, 1);