I want to save everything that can be used for statistics, such as referrer, os, browser etc. What is available and what's the best way to store it?
This is only important for 1 application (1 page) in the project, the other pages some standard analytics product will be used such as google analytics.
I had a look at django-tracking, but it seems this is overkill as I only want to use it on 1 view. The ideal situation would be, passing the whole request object to a TaskQue and do the processing later. So the user is redirected first and the analytics processing will be done behind the scenes.
We use some simple middleware.. below is an excerpt. You can modify it to use directly within a view.
Just manually pull it from the request.
The docs outlines a lot of the info that can be pulled from the request object.
For example, headers are stored in
request.META
, GET params in request.GET, etc.http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.META
What's the best way to store it? Depends what you're doing. Log it, store it in a DB, send it somewhere else... You say for statistics, so a database sounds like a good place to put this as it's easy to query.
Extension to Josh answer, you could use JSONField for post data if you are using postgres as your backend. It will help in dealing with json directly rather than loading it manually.
read more: https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/fields/#jsonfield
you could do something like this