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
- Serializer factory with Django Rest Framework by julio 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 6 months, 2 weeks ago
- Help text hyperlinks by sa2812 7 months, 2 weeks ago
- Stuff by NixonDash 9 months, 3 weeks ago
- Add custom fields to the built-in Group model by jmoppel 11 months, 3 weeks ago