Skip to Content

ga_send_data()

Send data to Google Analytics from the server-side.

PHP June 11, 2017

Usage

PHP
nebula()->ga_send_data($data)

Parameters

$data
(Required) (Array) An array of data
Default: None

Parameter Notes

Refer to this Google Analytics documentation for available parameters.

Request or provide clarification »

Source File

Located in /libs/Utilities/Analytics.php on line 252.

1 Hook

Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

Filters
"pre_ga_send_data"
Need a new filter hook? Request one here.

Actions
This function has no action hooks available. Request one?

PHP
        public function ga_send_data($data, $force=false){
            $override = apply_filters('pre_ga_send_data', null, $data);
            if ( isset($override) ){return;}

            if ( $force || $this->get_option('ga_server_side_fallback') ){
                $response = wp_remote_get('https://www.google-analytics.com/collect?payload_data&' . http_build_query($data)); //https://ga-dev-tools.appspot.com/hit-builder/
                return $response;
            }

            return false;
        }

Override

To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):

PHP
add_filter('pre_ga_send_data', 'my_custom_ga_send_data', 10, 2); //The last integer must be 1 more than the actual parameters
function my_custom_ga_send_data($null, $data){ //$null is required, but can be ignored
    //Write your own code here

    return true; //Return true to prevent the original function from running afterwords
}

You can completely disable this PHP function with a single line actions:

PHP
 add_filter('pre_ga_send_data', '__return_false');