User actions tracking and analytics for Django sites.
Project description
User actions tracking and analytics for Django sites
Requirements
Django 1.9 or later.
Django Countries 3.4.1 or later.
Django IPWare 1.1.5 or later.
Django User Agents 0.3.0 or later.
GeoIP2 2.3.0 or later.
Installation
Install Django Tracking Analyzer from PyPI by using pip:
pip install django-tracking-analyzer
Add 'django_user_agents' and 'tracking_analyzer' entries to Django INSTALLED_APPS setting.
Run the migrations to load the Tracker model in your database:
python manage.py migrate tracking_analyzer
- Install the MaxMind® GeoIP2 datasets. You can do this in two ways:
4.1. By running the provided management command for this:
python manage.py install_geoip_dataset
4.2. Or manually, by following the instructions in GeoIP2 Django documentation.
After following those steps, you should be ready to go.
Explanation - Quickstart
Django Tracking Analyzer is a Django application that aims to help you know in a simple and user-friendly way who the visitors of your site are, where they come from, what devices are they using to browse your site, what resources of your site they access, when and how many times.
In order to do this, DTA implements a database model Tracker, which will be created each time a user access certain resource, like a blog post, or performs certain action, like buying a product in your web shop.
Then, using the Django admin interface, you can check the “Trackers” changelist in the “Django Tracking Analyzer” app admin, and you will see a changelist of all the user accesses with details about the requests, like the IP address, the country and city (if available), the device type, browser and system information.
And also, heading the traditional changelist page, you will be provided with some nice interactive graphics made in D3.js, to actually see all the data gathered in a visual fancy way.
Now let’s see how can you start collecting users data. Imagine the most basic example: you have a web blog and you want to check the visits to your posts, having a resume of who accessed the posts, when and from where. In such a Django site, you might have a view PostDetailView, where a blog post will be served by passing its slug in the URL. Something like this:
class PostDetailView(DetailView):
model = Post
Okay, so you can track the users who access blog posts by their instances with DTA, just like this:
class PostDetailView(DetailView):
model = Post
def get_object(self, queryset=None):
# Retrieve the blog post just using `get_object` functionality.
obj = super(PostDetailView, self).get_object(queryset)
# Track the users access to the blog by post!
Tracker.objects.create_from_request(self.request, obj)
return obj
And you are now on your way to collect users data! Now give it a time (or better access the resource yourself several times) and go check your Django admin in the “Django Tracking Analyzer” - “Trackers” section. Enjoy!
Contribution
All contributions or fixes are welcome. Just make sure to follow this rules:
Always include some unit tests for the new code you write or the bugs you fix. Or, update the existent unit tests, if necessary.
Stick to PEP-8 styling.
Make your pull requests to development branch.
Testing
Run tests:
python setup.py test
Run tests with coverage:
python setup.py test --pytest-args "--cov-report xml --cov tracking_analyzer tests/ --verbose --junit-xml=junit.xml --color=yes"
Run tests with coverage and Pylint/PEP8 checking:
python setup.py test --pytest-args "--cov-report xml --cov tracking_analyzer tests/ --verbose --junit-xml=junit.xml --color=yes --pylint --pylint-rcfile=pylint.rc --pep8"
Acknowledgements
Django Tracking Analyzer makes use of this technologies and apps, without which it wouldn’t be possible:
Django Countries, by Chris Beaven.
Django IPWare, by Val Neekman.
Django User Agents, by Selwin Ong.
Datamaps, by Marc DiMarco.
TopoJSON, by Mike Bostock.
D3 bar chart w/tooltips, original code by Justin Palmer.
D3 area chart, by Mike Bostock.
Of course, the D3.js library.
And MaxMind, the company behind all the geographical datasets that made them publicly available.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-tracking-analyzer-0.1b5.tar.gz
.
File metadata
- Download URL: django-tracking-analyzer-0.1b5.tar.gz
- Upload date:
- Size: 108.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e991d816c832462a44cfc4ff49aa2aac6863e54795d6b1cd8f6102df60c8bdf |
|
MD5 | ab0d5fca1845c338147d231032873cb8 |
|
BLAKE2b-256 | aef9e707199fb3675261bc4a4492c09df16dda749e4c2ede67f27b18535bdf8b |
File details
Details for the file django_tracking_analyzer-0.1b5-py2.py3-none-any.whl
.
File metadata
- Download URL: django_tracking_analyzer-0.1b5-py2.py3-none-any.whl
- Upload date:
- Size: 115.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 163ca4a63373afcf6189c1305939ef1b968766aeebfb8ab7fda54a9e223adc86 |
|
MD5 | 287baf1ed43830c89c82083ea8a83cd3 |
|
BLAKE2b-256 | ac192857aa1fbd679e4c7cf5c309e5e33b58bfd868cd424f6f8a3b8d69370555 |