repos
/ analytics-django master

analytics-django

mirror archived upstream

Self-hostable website analytics on Django: a straightforward collector API, dashboards, a world map, and PDF reports.

analyticsdjangodockerhandcodedpythonself-hostedsqliteviteweb-analytics

777 B · 30 lines · Python Raw History
 1from django.conf import settings
 2
 3from properties.models import Property
 4
 5
 6def collector(request):
 7    """
 8    Gets the id of our "Proprium" property and sets it as a context variable
 9    to be used to collect metrics from ourselves.
10    """
11    try:
12        prop = Property.objects.get(name='Proprium') or Property.objects.get(name='analytics.bythewood.me')
13        return {'collector_server': settings.BASE_URL, 'collector_id': prop.id}
14    except Property.DoesNotExist:
15        return {}
16
17
18def canonical(request):
19    """
20    Gets the canonical URL for the current request.
21    """
22    return {'canonical': request.build_absolute_uri(request.path)}
23
24
25def base_url(request):
26    """
27    Provides the BASE_URL from settings.
28    """
29    return {'BASE_URL': settings.BASE_URL}