Permalink
Browse files

initialising google analytics after DOM ready

  • Loading branch information...
1 parent 913652c commit 6ca87e04b8f3eb75218de60b9d9d9c2de6d9d3c3 @stevenwilkin committed Sep 1, 2009
Showing with 16 additions and 7 deletions.
  1. +16 −0 public/js/trends.js
  2. +0 −7 views/layout.haml
View
@@ -9,6 +9,21 @@ function localiseTimestamp(){
/**
+ * initialse Google Analytics
+ * don't force the browser to wait until ga script loaded before running the rest of th js
+ */
+function initAnalytics(){
+ var accountId = 'UA-2764682-9';
+ jQuery.getScript('http://www.google-analytics.com/ga.js', function(){
+ try {
+ var pageTracker = _gat._getTracker(accountId);
+ pageTracker._trackPageview();
+ } catch(err) {}
+ });
+}
+
+
+/**
* jCarousel
*/
function itemVisibleIn(carousel, item, i, state, evt){
@@ -40,4 +55,5 @@ function initCarousel(){
$(document).ready(function(){
localiseTimestamp();
initCarousel();
+ initAnalytics();
});
View
@@ -25,10 +25,3 @@
#footer
© 2009
%a{:href => 'http://stevenwilkin.com'} Steven Wilkin
-
- %script{:type => 'text/javascript'}
- var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
- document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
- %script{:type => 'text/javascript'}
- var pageTracker = _gat._getTracker("UA-2764682-9");
- pageTracker._trackPageview();

0 comments on commit 6ca87e0

Please sign in to comment.