Skip to content

Commit

Permalink
Initial integration of the new page-load tracker
Browse files Browse the repository at this point in the history
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
acdha committed May 5, 2011
1 parent e835a1e commit 45a1282
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.mdown
Expand Up @@ -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 Adding the asynchronous tracking to existing code would cause backwards
incompatiblity. 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 ## ## Supporting other tracking methods ##


Sometimes, the built-in code snippets are not sufficient for what you want to Sometimes, the built-in code snippets are not sufficient for what you want to
Expand Down
Expand Up @@ -3,6 +3,10 @@
_gaq.push(['_setAccount', '{{ analytics_code }}']); _gaq.push(['_setAccount', '{{ analytics_code }}']);
_gaq.push(['_trackPageview']); _gaq.push(['_trackPageview']);


{% if track_page_load_time %}
_gaq.push(['_trackPageLoadTime']);
{% endif %}

(function() { (function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 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'; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
Expand Down
Expand Up @@ -6,4 +6,7 @@
var pageTracker = _gat._getTracker("{{ analytics_code }}"); var pageTracker = _gat._getTracker("{{ analytics_code }}");
pageTracker._initData(); pageTracker._initData();
pageTracker._trackPageview(); pageTracker._trackPageview();
{% if track_page_load_time %}
pageTracker._trackPageLoadTime();
{% endif %}
</script> </script>
4 changes: 4 additions & 0 deletions google_analytics/templatetags/analytics.py
@@ -1,4 +1,5 @@
from django import template from django import template
from django.conf import settings
from django.db import models from django.db import models
from django.contrib.sites.models import Site from django.contrib.sites.models import Site


Expand Down Expand Up @@ -53,6 +54,9 @@ def render(self, context):
t = loader.get_template(self.template_name) t = loader.get_template(self.template_name)
c = Context({ c = Context({
'analytics_code': code, 'analytics_code': code,
'track_page_load_time': getattr(settings,
"GOOGLE_ANALYTICS_TRACK_PAGE_LOAD_TIME",
False),
}) })
return t.render(c) return t.render(c)
else: else:
Expand Down

0 comments on commit 45a1282

Please sign in to comment.