Commits

Branko Vukelic committed 5360c21 Merge

Comments (0)

Files changed (6)

 
     GA_TRACKING_ID = os.environ.get('GA_TRACKING_ID')
 
+Customizing the tracking call
+-----------------------------
+
+Tracking call itself can be customized. The default tacking calls are::
+
+    // For old API
+    _gaq.push(['_trackPageview']);
+
+    // For new API
+    ga('send', 'pageview');
+
+These calls are separated out into their own templates:
+``ga_tracking/ga_track.js`` and ``ga_tracking/ga_new_track.js`` respectively.
+By overriding these templates, you can customize the calls. For more
+information on respective APIs, check out the Google Developers documentation
+for `ga.js`_ and `analytics.js`_. 
+
+It should be reiterated that the two partial templates are standard Django
+templates, so they have full access to template context should you need to
+access any of the context variables for the purpose of customization.
+
 Reporting bugs
 ==============
 
 .. _django-google-analytics: http://code.google.com/p/django-google-analytics/
 .. _Django Analytics Middleware: http://lethain.com/a-django-middleware-for-google-analytics-repost/
 .. _issue tracker: https://bitbucket.org/monwara/django-ga-tracking/issues
+.. _ga.js: https://developers.google.com/analytics/devguides/collection/gajs/
+.. _analytics.js: https://developers.google.com/analytics/devguides/collection/analyticsjs/

ga_tracking/templates/ga_tracking/ga.html

 
     var _gaq = _gaq || [];
     _gaq.push(['_setAccount', '{{GA_TRACKING_ID}}']);
-    _gaq.push(['_trackPageview']);
+    {% include 'ga_tracking/ga_track.js' %}
 
     (function() {
     var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

ga_tracking/templates/ga_tracking/ga_new.html

     })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
 
     ga('create', '{{ GA_TRACKING_ID }}', '{{ GA_DOMAIN }}');
-    ga('send', 'pageview');
+    {% include 'ga_tracking/ga_new_track.js' %}
 </script>
 {% endif %}

ga_tracking/templates/ga_tracking/ga_new_track.js

+ga('send', 'pageview');

ga_tracking/templates/ga_tracking/ga_track.js

+_gaq.push(['_trackPageview']);
     name='django-ga-tracking',
     description='Simple Google Analytics integration for Django projects',
     long_description=open('README.rst').read(),
-    version='0.0.3',
+    version='0.0.4',
     packages=['ga_tracking'],
     package_data={
-        'ga_tracking': ['templates/ga_tracking/*.html'],
+        'ga_tracking': [
+            'templates/ga_tracking/*.html',
+            'templates/ga_tracking/*.js'
+        ],
     },
     include_package_data=True,
     author='Monwara LLC',