analytics_google.theme.inc in Analytics 7
File
analytics_google/analytics_google.theme.inc
View source
<?php
function theme_analytics_google_universal_js(array &$variables) {
$output = '';
static $added = FALSE;
if (!$added) {
$url = analytics_url('https://www.google-analytics.com/analytics.js');
$output .= "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\nm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n})(window,document,'script','" . $url . "','ga');\n";
$added = TRUE;
}
foreach ($variables['actions'] as $action) {
if (!is_array($action)) {
$output .= $action . "\n";
}
else {
$line = 'ga(';
foreach ($action as $parameter) {
$line .= drupal_json_encode($parameter) . ',';
}
$line = rtrim($line, ',');
$line .= ');';
$output .= $line . "\n";
}
}
return theme('analytics_js', array(
'js' => $output,
));
}
function theme_analytics_google_ga_js(array &$variables) {
$output = '';
static $added = FALSE;
if (!$added) {
$url = analytics_url('https://ssl.google-analytics.com/ga.js');
$output .= "(function() {\n var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n ga.src = '" . $url . "';\n var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n })();\n";
$added = TRUE;
}
return theme('analytics_js', array(
'js' => $output,
));
}
function theme_analytics_google_ga_actions_js(array &$variables) {
$output = 'var _gaq = _gaq || [];' . "\n";
foreach ($variables['actions'] as $action) {
if (!is_array($action)) {
$output .= $action . "\n";
}
else {
$line = '_gaq.push([';
foreach ($action as $parameter) {
$line .= drupal_json_encode($parameter) . ',';
}
$line = rtrim($line, ',');
$line .= ']);';
$output .= $line . "\n";
}
}
return $output;
}