django-tracking
March 3, 2010 by Creart · Leave a Comment
I just finished intalling django-tracking in one of my clients projects in webfaction. Here are my steps.
This installed django-traking under the my project python path,
you could install it globally with:
The rest is quick, just follow the instructions as in django-tracking.
1) Add tracking to your list of INSTALLED_APPS in settings.py:
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'tracking',
)
2) django-tracking Options:
Visitor Tracking
Add tracking.middleware.VisitorTrackingMiddleware to your MIDDLEWARE_CLASSES in settings.py. It must be underneath the AuthenticationMiddleware, so that request.user exists.
Automatic Visitor Clean-Up
If you want to have Django automatically clean past visitor information out your database, put tracking.middleware.VisitorCleanUpMiddlewarein your MIDDLEWARE_CLASSES.
IP Banning
Add tracking.middleware.BannedIPMiddleware to your MIDDLEWARE_CLASSES in settings.py. I would recommend making this the very first item in MIDDLEWARE_CLASSES so your banned users do not have to drill through any other middleware before Django realizes they don’t belong on your site.
Visitors on Page (template tag)
Make sure that django.core.context_processors.request is somewhere in your TEMPLATE_CONTEXT_PROCESSORS tuple. This context processor makes the request object accessible to your templates. This application uses the request object to determine what page the user is looking at in a template tag.
Active Visitors Map
If you’re interested in seeing where your visitors are at a given point in time, you might enjoy the active visitor map feature. Be sure you have added a line to your main URLconf, as follows:
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^tracking/', include('tracking.urls')),
)
view all available django-tracking settings
Add the following to admin.py to view the data collected in django admin.
class VisitorAdmin(admin.ModelAdmin):
list_display = ('ip_address','referrer','url','page_views','last_update',)
ordering = ('last_update',)
admin.site.register(Visitor, VisitorAdmin)


