Commit 831a1532798bc8545570bb91167b126d8fa022a4

Authored by Sergio Oliveira
1 parent e8020673

Added google analytics tracking option

colab/home/context_processors.py
@@ -6,6 +6,11 @@ def robots(request): @@ -6,6 +6,11 @@ def robots(request):
6 return {'ROBOTS_NOINDEX': getattr(settings, 'ROBOTS_NOINDEX', False)} 6 return {'ROBOTS_NOINDEX': getattr(settings, 'ROBOTS_NOINDEX', False)}
7 7
8 8
  9 +def google_analytics(request):
  10 + key = 'GOOGLE_ANALYTICS_TRACKING_ID'
  11 + return {key: getattr(settings, key, False)}
  12 +
  13 +
9 def ribbon(request): 14 def ribbon(request):
10 enabled = getattr(settings, 'RIBBON_ENABLED', True) 15 enabled = getattr(settings, 'RIBBON_ENABLED', True)
11 if not enabled: 16 if not enabled:
@@ -15,7 +20,7 @@ def ribbon(request): @@ -15,7 +20,7 @@ def ribbon(request):
15 text = _('Fork me!') 20 text = _('Fork me!')
16 21
17 return { 22 return {
18 - 'ribbon': { 23 + 'ribbon': {
19 'text': getattr(settings, 'RIBBON_TEXT', text), 24 'text': getattr(settings, 'RIBBON_TEXT', text),
20 'url': getattr(settings, 'RIBBON_URL', url), 25 'url': getattr(settings, 'RIBBON_URL', url),
21 } 26 }
colab/settings.py
@@ -198,6 +198,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( @@ -198,6 +198,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
198 'colab.proxy.context_processors.proxied_apps', 198 'colab.proxy.context_processors.proxied_apps',
199 'colab.home.context_processors.robots', 199 'colab.home.context_processors.robots',
200 'colab.home.context_processors.ribbon', 200 'colab.home.context_processors.ribbon',
  201 + 'colab.home.context_processors.google_analytics',
201 'colab.planet.context_processors.feedzilla', 202 'colab.planet.context_processors.feedzilla',
202 ) 203 )
203 204
colab/templates/base.html
@@ -38,6 +38,8 @@ @@ -38,6 +38,8 @@
38 <script type="text/javascript" src="{% static 'third-party/jquery.cookie.js' %}"></script> 38 <script type="text/javascript" src="{% static 'third-party/jquery.cookie.js' %}"></script>
39 <script src="{% static 'third-party/bootstrap/js/bootstrap.min.js' %}"></script> 39 <script src="{% static 'third-party/bootstrap/js/bootstrap.min.js' %}"></script>
40 40
  41 + {% include "includes/google_analytics.html" %}
  42 +
41 {% block head_js %}{% endblock %} 43 {% block head_js %}{% endblock %}
42 {% block head_css %}{% endblock %} 44 {% block head_css %}{% endblock %}
43 45
colab/templates/includes/google_analytics.html 0 → 100644
@@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
  1 +
  2 +<h2>HEHEHE</h2>
  3 +{% if GOOGLE_ANALYTICS_TRACKING_ID %}
  4 +<h1>HAHAHA</h1>
  5 +<!-- Google Analytics Tracking Script -->
  6 +<script>
  7 + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  8 + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  9 + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  10 + })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  11 +
  12 + ga('create', '{{ GOOGLE_ANALYTICS_TRACKING_ID }}', 'auto');
  13 + ga('require', 'displayfeatures');
  14 + ga('send', 'pageview');
  15 +
  16 +</script>
  17 +{% endif %}