function ga_push_method_analytics_js_push in GA Push 8
Same name and namespace in other branches
- 7 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.
Return value
string Analytics script.
1 call to ga_push_method_analytics_js_push()
- ga_push_page_attachments in ./
ga_push.module - Implements hook_page_attachments().
File
- inc/
ga_push.analytics_js.inc, line 25 - Universal Analytics js: method and functions.
Code
function ga_push_method_analytics_js_push() {
$session_key = 'ga_push_' . GA_PUSH_METHOD_ANALYTICS_JS;
$script = NULL;
if (isset($_SESSION[$session_key])) {
$id = \Drupal::service('ga_push.google_analytics_id')
->getAnalyticsId();
if (!empty($id)) {
$script = "var ga = ga || [];\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);
}
unset($_SESSION[$session_key]);
}
}
return $script;
}