Permalink
Browse files

Initial integration of the new page-load tracker

To avoid needing a model migration, this uses the meaningful but long
GOOGLE_ANALYTICS_TRACK_PAGE_LOAD_TIME setting to enable page-load tracking.
  • Loading branch information...
1 parent e835a1e commit 45a1282cf319fb5d1bbd4f96efc1a54860530c74 @acdha acdha committed May 5, 2011
View
@@ -49,6 +49,13 @@ This is being added as an option rather than a replacement for two reasons:
Adding the asynchronous tracking to existing code would cause backwards
incompatiblity.
+## Tracking Page-Load Time ##
+
+Google has added [page-load tracking](http://www.google.com/support/analyticshelp/bin/answer.py?hl=en&answer=1205784&topic=1120718).
+To use this feature add the following to your settings file:
+
+ GOOGLE_ANALYTICS_TRACK_PAGE_LOAD_TIME = True
+
## Supporting other tracking methods ##
Sometimes, the built-in code snippets are not sufficient for what you want to
@@ -3,6 +3,10 @@
_gaq.push(['_setAccount', '{{ analytics_code }}']);
_gaq.push(['_trackPageview']);
+ {% if track_page_load_time %}
+ _gaq.push(['_trackPageLoadTime']);
+ {% endif %}
+
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
@@ -6,4 +6,7 @@
var pageTracker = _gat._getTracker("{{ analytics_code }}");
pageTracker._initData();
pageTracker._trackPageview();
+{% if track_page_load_time %}
+ pageTracker._trackPageLoadTime();
+{% endif %}
</script>
@@ -1,4 +1,5 @@
from django import template
+from django.conf import settings
from django.db import models
from django.contrib.sites.models import Site
@@ -53,6 +54,9 @@ def render(self, context):
t = loader.get_template(self.template_name)
c = Context({
'analytics_code': code,
+ 'track_page_load_time': getattr(settings,
+ "GOOGLE_ANALYTICS_TRACK_PAGE_LOAD_TIME",
+ False),
})
return t.render(c)
else:

0 comments on commit 45a1282

Please sign in to comment.