Skip to main content

Simple Google Analytics integration for Django.

Project description

# django-ganalytics

Simple Google Analytics integration for Django.


## Meta

* author: Randall Degges
* email: r@rdegges.com
* status: maintained, in development

[![Build Status](https://secure.travis-ci.org/rdegges/django-ganalytics.png?branch=master)](http://travis-ci.org/rdegges/django-ganalytics)


## Purpose

Honestly, all the other Google Analytics Django apps suck. All I want to do is
put my Google Analytics code in my ``settings.py`` file, and use a simple
template tag to render the Google Analytics asynchronous javascript code,
damnet!

Unfortunately, all the existing solutions don't do this, and that pisses me
off!

![squint](https://github.com/rdegges/django-ganalytics/raw/master/assets/squint.png)


## Installation and Usage

Anyway, let's install this bitch! The first thing you'll want to do is run:

``` bash
$ pip install django-ganalytics
```

Next, modify your ``settings.py`` file, and add your Google Analytics code
(usually something like ``UA-XXXXXXXX-XX``), as well as put
``ganalytics`` in your ``INSTALLED_APPS``:

``` python
# settings.py

INSTALLED_APPS = (
# ...
'ganalytics',
)

GANALYTICS_TRACKING_CODE = 'UA-XXXXXXXX-XX'
```

Now, to actually render your Google Analytics asynchronous javascript code,
edit your desired Django template (I like to do this in my ``base.html``
template), and add the following:

``` html
{% load ganalytics %}
<!--- ... -->

<head>
{% ganalytics %}
</head>

<!--- ... -->
```

When Django processes your template, it'll replace ``{% ganalytics %}``
with:

``` html
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', '{{ GANALYTICS_TRACKING_CODE }}', 'auto');
ga('send', 'pageview');
</script>
```

Easy, right?

Project details


Download files

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

Source Distribution

django-ganalytics-0.6.0.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

django_ganalytics-0.6.0-py2.py3-none-any.whl (6.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-ganalytics-0.6.0.tar.gz.

File metadata

File hashes

Hashes for django-ganalytics-0.6.0.tar.gz
Algorithm Hash digest
SHA256 d05e946c4cd6fae7a0eefe2729ad5afca8ae0edec16157c8b89af19d0cf0d57d
MD5 68ebde8424438ce849e0b7e298230794
BLAKE2b-256 6ef9373ca2e3efbb4d5e18cae9cb2c96fcb2570cec937de86634e4453c99e6ae

See more details on using hashes here.

File details

Details for the file django_ganalytics-0.6.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_ganalytics-0.6.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 23f3373fd7e47088f336c4dfc8933cceb9c3826d4941f6d231ad3c1310645d32
MD5 5b2d499f9760db76554d54646c17d179
BLAKE2b-256 f2227d5c3f5d668ac9daec9f687eff86b33b669b9d067c4622de8edcfe7e6f0d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page