Skip to content

Commit

Permalink
google analytics added
Browse files Browse the repository at this point in the history
google analytics added
  • Loading branch information
Anjaneyulu authored and ashwin31 committed Jul 20, 2016
1 parent 8243be8 commit 8752016
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
14 changes: 13 additions & 1 deletion django_blog_it/django_blog_it/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.smartmenus/1.0.0/jquery.smartmenus.js"></script>

{% google_analytics_id as GOOGLE_ANALYTICS_ID %}
{% if GOOGLE_ANALYTICS_ID %}
<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_ID}}', 'auto');
ga('send', 'pageview');

</script>
{% endif %}
<script type="text/javascript">

// for pagination
Expand Down
14 changes: 13 additions & 1 deletion django_blog_it/django_blog_it/templates/new_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,19 @@
}

</script>

{% google_analytics_id as GOOGLE_ANALYTICS_ID %}
{% if GOOGLE_ANALYTICS_ID %}
<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_ID}}', 'auto');
ga('send', 'pageview');

</script>
{% endif %}
<script type="text/javascript">
$(document).ready(function() {
setTimeout(function() {
Expand Down
6 changes: 6 additions & 0 deletions django_blog_it/django_blog_it/templatetags/blog_tags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import os
from django import template
from django_blog_it.django_blog_it.models import Post, Tags, Menu
from django_blog_it.django_blog_it.views import get_user_role
Expand Down Expand Up @@ -82,3 +83,8 @@ def blog_title():
@register.filter
def category_posts(category):
return Post.objects.filter(category=category).count()


@register.assignment_tag
def google_analytics_id():
return os.getenv("GOOGLE_ANALYTICS_ID")

0 comments on commit 8752016

Please sign in to comment.