<commit_before># django-google-analytics

Simple Google Analytics integration for Django.


## Meta

* author: <NAME>
* email:  <EMAIL>
* status: maintained, in development


## 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-google-analytics/raw/master/assets/squint.png)<commit_msg>Adding "Installation and Usage" section to the readme.<commit_after># django-google-analytics

Simple Google Analytics integration for Django.


## Meta

* author: <NAME>
* email:  <EMAIL>
* status: maintained, in development


## 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-google-analytics/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-google-analytics
```

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

``` python
# settings.py
GOOGLE_ANALYTICS_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 google_analytics %}
<!--- ... -->

<head>
  {% google_analytics %}
</head>

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

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

``` html
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '{{ GOOGLE_ANALYTICS_TRACKING_CODE }}']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
```

Easy, right?
{'fraction_non_alphanumeric': 0.13383637807783955, 'fraction_numerical': 0.0003971405877680699, 'mean_word_length': 4.548458149779735, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '999710', 'n_tokens_mistral': 824, 'n_tokens_neox': 746, 'n_words': 262}