Login

Tag "analytics"

Snippet List

Strip Google Analytics cookies for caching middleware purposes

You may notice that using Google Analytics's 'urchin' with the CacheMiddleware and SessionMiddleware or AuthenticationMiddleware middleware classes means that nothing is ever cached. Google Analytics updates its cookies with every page view, and the Auth/Session middlewares add cookies to the caching engine's 'Vary' list. This means every page view is given a unique cache key. This middleware class will remove urchin's '__utmX' cookies from the request object before it hits the caching middleware. Put it at the top of your MIDDLEWARE_CLASSES in settings.py. nf / [email protected]

  • middleware
  • cache
  • google
  • analytics
Read More
Author: nf
  • 7
  • 13

Google Analytics Template Tag

Includes the Javascript for Google Analytics. Will not show Google Analytics code when DEBUG is on or to staff users. Use {% googleanalyticsjs %} in your templates. You must set something like GOOGLE_ANALYTICS_CODE = "UA-1234567-1" in your settings file. Assumes 'user' in your template variables is request.user, which it will be if you use: return render_to_response('template.html',{ }, context_instance=RequestContext(request)) (Assuming django.core.context_processors.auth is in TEMPLATE_CONTEXT_PROCESSORS, which it is by default)

  • google
  • urchin
  • analytics
Read More

3 snippets posted so far.