Django helper application around pypiwik
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

23 lines
711 B

# -*- coding: utf-8 -*-
from django.conf import settings
from django.core.urlresolvers import reverse, NoReverseMatch
from django_pypiwik.tracker import DjangoPiwikTracker
class PiwikTrackingMiddleware(object):
def process_response(self, request, response):
exclude_admin = getattr(settings, 'PIWIK_TRACKING_MIDDLEWARE_EXCLUDE_ADMIN', True) == True
admin_url = reverse('admin:index')
except NoReverseMatch:
admin_url = None
if exclude_admin and admin_url and request.path.startswith(admin_url):
return response
tracker = DjangoPiwikTracker.for_current_site(request=request)
tracker.track_page_view(**getattr(settings, 'PIWIK_TRACKING_MIDDLEWARE_PARAMS', {}))
return response