Add google analytics.
parent
ddfc260f99
commit
121a3ba31b
|
@ -0,0 +1,18 @@
|
|||
from django.conf import settings
|
||||
|
||||
|
||||
def google_analytics(request):
|
||||
"""
|
||||
Use the variables returned in this function to
|
||||
render your Google Analytics tracking code template.
|
||||
"""
|
||||
ga_prop_id = getattr(settings, 'GOOGLE_ANALYTICS_PROPERTY_ID', False)
|
||||
ga_domain = getattr(settings, 'GOOGLE_ANALYTICS_DOMAIN', False)
|
||||
|
||||
if not settings.DEBUG and ga_prop_id and ga_domain:
|
||||
return {
|
||||
'GOOGLE_ANALYTICS_PROPERTY_ID': ga_prop_id,
|
||||
'GOOGLE_ANALYTICS_DOMAIN': ga_domain,
|
||||
}
|
||||
|
||||
return {}
|
|
@ -157,7 +157,9 @@ class Common(Configuration):
|
|||
'django.core.context_processors.tz',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'django.core.context_processors.request',
|
||||
|
||||
# Your stuff: custom template context processers go here
|
||||
'base.context_processors.google_analytics'
|
||||
)
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
|
||||
|
|
|
@ -43,3 +43,7 @@ class Production(Common):
|
|||
)),
|
||||
)
|
||||
# END TEMPLATE CONFIGURATION
|
||||
|
||||
# GA configuration
|
||||
GOOGLE_ANALYTICS_PROPERTY_ID = values.Value()
|
||||
GOOGLE_ANALYTICS_DOMAIN = values.Value()
|
||||
|
|
|
@ -16,6 +16,11 @@
|
|||
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
{% if GOOGLE_ANALYTICS_PROPERTY_ID %}
|
||||
<!-- GA code -->
|
||||
{% include "includes/google_analytics.html" %}
|
||||
{% endif %}
|
||||
|
||||
<!-- Latest compiled and minified CSS -->
|
||||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
||||
|
||||
|
@ -62,8 +67,8 @@
|
|||
<ul class="nav navbar-nav navbar-right">
|
||||
{% if request.user.is_authenticated %}
|
||||
<li class="dropdown">
|
||||
<a href="#"
|
||||
class="dropdown-toggle"
|
||||
<a href="#"
|
||||
class="dropdown-toggle"
|
||||
data-toggle="dropdown">{% avatar user 35 %} {{ request.user.username }}
|
||||
<span class="caret"></span>
|
||||
</a>
|
||||
|
@ -83,7 +88,7 @@
|
|||
</div>
|
||||
|
||||
<div class="container">
|
||||
|
||||
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
<div class="alert {% if message.tags %}alert-{{ message.tags }}"{% endif %}>{{ message }}</div>
|
||||
|
@ -93,7 +98,7 @@
|
|||
{% block content %}{% endblock content %}
|
||||
|
||||
</div> <!-- /container -->
|
||||
|
||||
|
||||
{% block modal %}{% endblock modal %}
|
||||
|
||||
<footer>
|
||||
|
@ -124,4 +129,3 @@
|
|||
{% endblock javascript %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<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', '{{ GOOGLE_ANALYTICS_PROPERTY_ID }}', '{{ GOOGLE_ANALYTICS_DOMAIN }}');
|
||||
ga('send', 'pageview');
|
||||
</script>
|
Loading…
Reference in New Issue