Skip to content
Browse files

[swToolboxPlugin] add Google Analytics Asynchronous Tracking Code + u…

…pdate doc

git-svn-id: http://svn.symfony-project.com/plugins/swToolboxPlugin/sf1.2/trunk@25518 ee427ae8-e902-0410-961c-c3ed070cd9f9
  • Loading branch information...
1 parent 86abf96 commit 8ebd604481b1c8ae7a224f03a94b2ca3e49bd739 @rande committed Dec 17, 2009
Showing with 32 additions and 5 deletions.
  1. +11 −1 README
  2. +21 −4 lib/helper/swToolboxHelper.php
View
12 README
@@ -37,7 +37,17 @@ The plugin have been splitted into many plugins :
google_map_version: 2.x
google_map_url: http://maps.google.com/maps
google_analytics: [ UA-KEY-ONE, UA-KEY-TWO]
-
+
+ * include google analytics to your web page, edit the layout.php file
+
+ [php]
+ <?php echo sw_google_analytics('aga') ?>
+
+ argument values :
+ * `urchin` : orginal urchin tracker
+ * `ga` : new version of Google Analytics Tracking Code (late 2007)
+ * `aga` : load Google Analytics Asynchronous Tracking Code (late 2009)
+
# swUserContextCacheFilter
View
25 lib/helper/swToolboxHelper.php
@@ -272,19 +272,36 @@ function sw_google_analytics($version = 'ga')
$html .= sprintf('<script type="text/javascript">_uacct = "%s"; urchinTracker();</script>', $key);
}
}
-
- if($version == 'ga')
+ else if($version == 'ga')
{
$html .= '<script type="text/javascript">';
- $html .= 'var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");';
- $html .= 'document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));';
+ $html .= ' var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");';
+ $html .= ' document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));';
$html .= '</script>';
foreach($keys as $key)
{
$html .= sprintf('<script type="text/javascript">var pageTracker = _gat._getTracker("%s"); pageTracker._trackPageview();</script>', $key);
}
}
+ else if($version == 'aga') // Asynchronous Tracking
+ {
+ $html .= '<script type="text/javascript">';
+ $html .= ' var _gaq = _gaq || [];';
+
+ foreach($keys as $pos => $key)
+ {
+ $html .= sprintf(' _gaq.push([\'%s_setAccount\', \'%s\']);', $pos == 0 ? '' : 't'.($pos + 1).'.', $key);
+ $html .= sprintf(' _gaq.push([\'%s_trackPageview\']);', $pos == 0 ? '' : 't'.($pos + 1).'.');
+ }
+
+ $html .= ' (function() {';
+ $html .= ' var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;';
+ $html .= ' ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';';
+ $html .= ' (document.getElementsByTagName(\'head\')[0] || document.getElementsByTagName(\'body\')[0]).appendChild(ga);';
+ $html .= ' })();';
+ $html .= '</script>';
+ }
return $html;
}

0 comments on commit 8ebd604

Please sign in to comment.
Something went wrong with that request. Please try again.