function ga_push_method_datalayer_push in GA Push 8
Same name and namespace in other branches
- 7 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_attachments in ./
ga_push.module  - Implements hook_page_attachments().
 
File
- inc/
ga_push.datalayer.inc, line 22  - Datalayer js: method and functions.
 
Code
function ga_push_method_datalayer_push() {
  $session_key = 'ga_push_' . GA_PUSH_METHOD_DATALAYER_JS;
  $script = NULL;
  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);
    }
    unset($_SESSION[$session_key]);
  }
  return $script;
}