You are here

function ga_push_method_datalayer_push in GA Push 7

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

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

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

File

inc/ga_push.datalayer.inc, line 22
Universal Datalayer js: method and functions.

Code

function ga_push_method_datalayer_push() {
  $session_key = 'ga_push_' . GA_PUSH_METHOD_DATALAYER_JS;
  if (isset($_SESSION[$session_key])) {
    $script = "var dataLayer = dataLayer || [];\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_datalayer_js_push_script($push, $type);
    }
    _ga_push_method_datalayer_js_add_script($script);
    unset($_SESSION[$session_key]);
  }
}