Commit 831a1532798bc8545570bb91167b126d8fa022a4
1 parent
e8020673
Exists in
master
and in
39 other branches
Added google analytics tracking option
Showing
4 changed files
with
26 additions
and
1 deletions
Show diff stats
colab/home/context_processors.py
| ... | ... | @@ -6,6 +6,11 @@ def robots(request): |
| 6 | 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 | 14 | def ribbon(request): |
| 10 | 15 | enabled = getattr(settings, 'RIBBON_ENABLED', True) |
| 11 | 16 | if not enabled: |
| ... | ... | @@ -15,7 +20,7 @@ def ribbon(request): |
| 15 | 20 | text = _('Fork me!') |
| 16 | 21 | |
| 17 | 22 | return { |
| 18 | - 'ribbon': { | |
| 23 | + 'ribbon': { | |
| 19 | 24 | 'text': getattr(settings, 'RIBBON_TEXT', text), |
| 20 | 25 | 'url': getattr(settings, 'RIBBON_URL', url), |
| 21 | 26 | } | ... | ... |
colab/settings.py
| ... | ... | @@ -198,6 +198,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( |
| 198 | 198 | 'colab.proxy.context_processors.proxied_apps', |
| 199 | 199 | 'colab.home.context_processors.robots', |
| 200 | 200 | 'colab.home.context_processors.ribbon', |
| 201 | + 'colab.home.context_processors.google_analytics', | |
| 201 | 202 | 'colab.planet.context_processors.feedzilla', |
| 202 | 203 | ) |
| 203 | 204 | ... | ... |
colab/templates/base.html
| ... | ... | @@ -38,6 +38,8 @@ |
| 38 | 38 | <script type="text/javascript" src="{% static 'third-party/jquery.cookie.js' %}"></script> |
| 39 | 39 | <script src="{% static 'third-party/bootstrap/js/bootstrap.min.js' %}"></script> |
| 40 | 40 | |
| 41 | + {% include "includes/google_analytics.html" %} | |
| 42 | + | |
| 41 | 43 | {% block head_js %}{% endblock %} |
| 42 | 44 | {% block head_css %}{% endblock %} |
| 43 | 45 | ... | ... |
| ... | ... | @@ -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 %} | ... | ... |