You are here

function ga_push_add in GA Push 7

Same name and namespace in other branches
  1. 8 ga_push.module \ga_push_add()

Add a new google analytics tracking push.

The behavior of this function depends on the parameters it is called with. The following actions can be performed using this function:

  • Event tracking
  • Ecommerce tracking
  • Social tracking
  • Pageview tracking
  • ...

For better documentation understanding this function has been splited in to several functions and should not be called directly.

Parameters

array $push: The push parameters. The value depends on the $type parameter.

string $type: (optional) The GA Push type:

string $method_key: (optional) The method identificator

array $options: (optional) An associative array of additional options, with the following elements:

Only for server-side methods:

  • 'tid': Override Tracking ID / Web Property ID (Classic User account aka UA) of the google analytics module config. Universal and Classic GA Methods.
  • 'cid': Override Universal Client ID of the current user cookie. Only for Universal GA methods.
  • 'utma': Force Classic GA __utma cookie of the current user cookie Only for Classic GA methods.
  • 'utmb': Force Classic GA __utmb cookie of the current user cookie Only for Classic GA methods.
  • 'ua': Override User Agent of the current user. Only for Universal GA methods.
  • 'uip': Override User IP of the current user. Only for Universal GA methods.

All methods:

  • 'context': An array of aditional info to be passed to drupal_alter implementations.

See also

ga_push_add_ecommerce()

ga_push_add_event()

ga_push_add_pageview()

ga_push_add_social()

5 calls to ga_push_add()
ga_push_add_ecommerce in ./ga_push.module
Push a GA ecommerce.
ga_push_add_event in ./ga_push.module
Push a GA event.
ga_push_add_exception in ./ga_push.module
Push a GA exception.
ga_push_add_pageview in ./ga_push.module
Push a GA pageview.
ga_push_add_social in ./ga_push.module
Push a GA social.

File

./ga_push.module, line 175
Drupal Module: GA Push.

Code

function ga_push_add($push, $type = GA_PUSH_TYPE_EVENT, $method_key = NULL, $options = array()) {
  global $user;

  // Legacy compatibility:
  // Map old method keys to the new ones.
  // @NOTE: this feature will be remove in future realeases.
  $push = ga_push_add_legacy_params($push, $type);

  // Let other modules alter the current push data:
  drupal_alter('ga_push_add', $push, $type, $method_key, $options);
  if (is_array($push) && count($push)) {
    if (_googleanalytics_visibility_user($user)) {

      // If the select method is not available or is not defined:
      if (is_null($method_key) || $method_key == GA_PUSH_METHOD_DEFAULT || !is_null($method_key) && !ga_push_method_available($method_key, $type)) {
        $default_method_key = variable_get('ga_push_default_method', GA_PUSH_METHOD_ANALYTICS_JS);
        $method_key = $default_method_key;
      }
      if (!is_null($method_key)) {
        $method = ga_push_get_method($method_key);
        if (isset($method['file'])) {
          require_once $method['file'];
        }

        // Excecute the push method callback function.
        try {
          call_user_func($method['callback'], $push, $type, $options);
        } catch (Exception $e) {

          // Catch the errors to prevent a 500 error, which would prevent the
          // other form validate/submit functions from executing.
          watchdog_exception('ga_push', $e);
        }
      }
      else {

        // @TODO: watchdog there's no method available.
      }
    }
  }
}