Installation and configuration

Integration of your analytics service is very simple. There are four steps: installing the package, adding it to the list of installed Django applications, adding the template tags to your base template, and configuring the services you use in the project settings.

  1. Installing the Python package
  2. Installing the Django application
  3. Adding the template tags to the base template
  4. Enabling the services

Installing the Python package

To install django-analytical the analytical package must be added to the Python path. You can install it directly from PyPI using easy_install:

$ easy_install django-analytical

You can also install directly from source. Download either the latest stable version from PyPI or any release from GitHub, or use Git to get the development code:

$ git clone https://github.com/jcassee/django-analytical.git

Then install the package by running the setup script:

$ cd django-analytical
$ python setup.py install

Installing the Django application

After you installed django-analytical, add the analytical Django application to the list of installed applications in the settings.py file of your project:

INSTALLED_APPS = [
    ...
    'analytical',
    ...
]

Adding the template tags to the base template

Because every analytics service uses own specific Javascript code that should be added to the top or bottom of either the head or body of the HTML page, django-analytical provides four general-purpose template tags that will render the code needed for the services you are using. Your base template should look like this:

{% load analytical %}
<!DOCTYPE ... >
<html>
    <head>
        {% analytical_head_top %}

        ...

        {% analytical_head_bottom %}
    </head>
    <body>
        {% analytical_body_top %}

        ...

        {% analytical_body_bottom %}
    </body>
</html>

Instead of using the generic tags, you can also just use tags specific for the analytics service(s) you are using. See Services for documentation on using individual services.

Enabling the services

Without configuration, the template tags all render the empty string. Services are configured in the project settings.py file. The settings required to enable each service are listed here:

  • Chartbeat:

    CHARTBEAT_USER_ID = '12345'
    
  • Clickmap:

    CLICKMAP_TRACKER_CODE = '12345678....912'
    
  • Clicky:

    CLICKY_SITE_ID = '12345678'
    
  • Crazy Egg:

    CRAZY_EGG_ACCOUNT_NUMBER = '12345678'
    
  • Gaug.es:

    GAUGES_SITE_ID = '0123456789abcdef0123456789abcdef'
    
  • Google Analytics:

    GOOGLE_ANALYTICS_PROPERTY_ID = 'UA-1234567-8'
    
  • HubSpot:

    HUBSPOT_PORTAL_ID = '1234'
    HUBSPOT_DOMAIN = 'somedomain.web101.hubspot.com'
    
  • Intercom:

    INTERCOM_APP_ID = '0123456789abcdef0123456789abcdef01234567'
    
  • KISSinsights:

    KISS_INSIGHTS_ACCOUNT_NUMBER = '12345'
    KISS_INSIGHTS_SITE_CODE = 'abc'
    
  • KISSmetrics:

    KISS_METRICS_API_KEY = '0123456789abcdef0123456789abcdef01234567'
    
  • Mixpanel:

    MIXPANEL_API_TOKEN = '0123456789abcdef0123456789abcdef'
    
  • Olark:

    OLARK_SITE_ID = '1234-567-89-0123'
    
  • Optimizely:

    OPTIMIZELY_ACCOUNT_NUMBER = '1234567'
    
  • Performable:

    PERFORMABLE_API_KEY = '123abc'
    
  • Piwik:

    PIWIK_DOMAIN_PATH = 'your.piwik.server/optional/path'
    PIWIK_SITE_ID = '123'
    
  • Rating@Mail.ru:

    RATING_MAILRU_COUNTER_ID = '1234567'
    
  • Woopra:

    WOOPRA_DOMAIN = 'abcde.com'
    
  • Yandex.Metrica:

    YANDEX_METRICA_COUNTER_ID = '12345678'
    

The django-analytical application is now set-up to track visitors. For information about identifying users, further configuration and customization, see Features and customization.