You are here

function ga_push_method_analytics_js_push in GA Push 7

Same name and namespace in other branches
  1. 8 inc/ga_push.analytics_js.inc \ga_push_method_analytics_js_push()

Send the ga push to JS on page load using Universal Analytics Event Tracking.

1 call to ga_push_method_analytics_js_push()
ga_push_page_alter in ./ga_push.module
Implements hook_page_alter().

File

inc/ga_push.analytics_js.inc, line 27
Universal Analytics js: method and functions.

Code

function ga_push_method_analytics_js_push() {
  $session_key = 'ga_push_' . GA_PUSH_METHOD_ANALYTICS_JS;
  if (isset($_SESSION[$session_key])) {
    $id = variable_get('googleanalytics_account', '');
    if (!empty($id)) {
      $script = "var ga = ga || function(){};\n";

      // Process each push data that needs to be sent to Google Analytics.
      foreach ($_SESSION[$session_key] as $queued) {
        $push = $queued['push'];
        $type = $queued['type'];
        $script .= ga_push_method_analytics_js_push_script($push, $type);
      }
      _ga_push_method_analytics_js_add_script($script);
      unset($_SESSION[$session_key]);
    }
  }
}