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]
1 2 3 4 5 6 7 8 9
import re class StripCookieMiddleware(object): strip_re = re.compile(r'(__utm.=.+?(?:; |$))') def process_request(self, request): try: cookie = self.strip_re.sub('', request.META['HTTP_COOKIE']) request.META['HTTP_COOKIE'] = cookie except: pass
More like this
- Django Settings Assignment Expressions aka Walrus Operator example by webology 2 weeks, 6 days ago
- codigo alto nivel by MrRocklion 2 months, 2 weeks ago
- Load template from specific app by Krzysiek555 3 months, 1 week ago
- PostgreSQL JSON subqueries by dolamroth 3 months, 1 week ago
- "Magic Link" Management Command by webology 8 months, 2 weeks ago