Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

django-basic-stats is a simple traffic statistics application. It show latest referrer, google queried terms or overall hits count. It also provides optional logging and statistics for mobile devices.

Project description

django-basic-stats is a simple traffic statistics application. It show latest referrer, google queried terms or overall hits count.

It also provides optional logging and statistics for mobile devices (user agent, screen and window width/height, device pixel ratio).

Installation

  • Run pip install django-basic-stats
  • Add ‘stats’, to INSTALLED_APPS
  • Add ‘stats.middleware.StatsMiddleware’ to MIDDLEWARE_CLASSES
  • Add url(r’^stats/’, include(‘stats.urls’)) to your urlpatterns in urls.py
  • Run “python manage.py migrate” to sync the database

Enabling mobile device logging

Mobile devices are logged via JavaScript code sending AJAX requests if browser USER AGENT matches one of mobile devices.

Assuming you have jQuery available you will have to add such JavaScript code to you site:

var ismobile = (/iphone|ipod|android|blackberry|mini|palm|smartphone|ipad|xoom|playbook|tablet|mobile|kindle/i.test(navigator.userAgent.toLowerCase()));
if (ismobile) {
    $(document).ready(function(){
        $.ajax({
        url: '/stats/mobile/',
        cache: false,
        type: "GET",
        data: {"window_width": window.innerWidth,
        "window_height": window.innerHeight,
        "screen_width": screen.width,
        "screen_height": screen.height,
        "device_pixel_ratio": window.devicePixelRatio},
        });
    });
}

If you are using other JavaScript library you will have to redo the AJAX sending part. Note that /stats/mobile/ is a hardcoded URL.

Usage

Statistics are visible for site staff. Login to you site as such user and go to /stats/

In Django admin panel you will also get “Mobile” model with all logged mobile devices.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-basic-stats, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size django-basic-stats-0.2.0.tar.gz (7.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page