Add google analytics to data center light
This commit is contained in:
		
					parent
					
						
							
								ed9e5c591c
							
						
					
				
			
			
				commit
				
					
						007fc794c3
					
				
			
		
					 5 changed files with 40 additions and 1 deletions
				
			
		
							
								
								
									
										16
									
								
								datacenterlight/context_processor.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								datacenterlight/context_processor.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | ||||||
|  | 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 {} | ||||||
|  | @ -47,6 +47,9 @@ | ||||||
| 	{% include "datacenterlight/includes/_footer.html" %} | 	{% include "datacenterlight/includes/_footer.html" %} | ||||||
|     <!-- Footer --> |     <!-- Footer --> | ||||||
| 
 | 
 | ||||||
|  |     <!-- Google analytics --> | ||||||
|  |     {% include "datacenterlight/includes/_google_analytics.html" %} | ||||||
|  | 
 | ||||||
|     <!-- jQuery --> |     <!-- jQuery --> | ||||||
|     <script src="{% static 'datacenterlight/js/jquery.js' %}"></script> |     <script src="{% static 'datacenterlight/js/jquery.js' %}"></script> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -0,0 +1,15 @@ | ||||||
|  | <!-- Google Analytics --> | ||||||
|  | {% if GOOGLE_ANALYTICS_PROPERTY_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','https://www.google-analytics.com/analytics.js','ga'); | ||||||
|  | 
 | ||||||
|  |         ga('create', '{{ GOOGLE_ANALYTICS_PROPERTY_ID }}', '{{ GOOGLE_ANALYTICS_DOMAIN }}'); | ||||||
|  |         ga('send', 'pageview'); | ||||||
|  |     </script> | ||||||
|  | {% else %} | ||||||
|  |     <!-- Empty analytics --> | ||||||
|  | {% endif %} | ||||||
|  | <!-- End Google Analytics --> | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| {% load staticfiles bootstrap3 %} | {% load staticfiles bootstrap3 %} | ||||||
| {% load i18n %} | {% load i18n %} | ||||||
| {% block content %}  | {% block content %}  | ||||||
| 
 | {% include 'datacenterlight/includes/_google_analytics.html' %} | ||||||
| <div class="order-detail-container"> | <div class="order-detail-container"> | ||||||
|    {% if messages %} |    {% if messages %} | ||||||
|     <div class="row"> |     <div class="row"> | ||||||
|  |  | ||||||
|  | @ -161,6 +161,7 @@ TEMPLATES = [ | ||||||
|                 "django.contrib.messages.context_processors.messages", |                 "django.contrib.messages.context_processors.messages", | ||||||
|                 'sekizai.context_processors.sekizai', |                 'sekizai.context_processors.sekizai', | ||||||
|                 'cms.context_processors.cms_settings', |                 'cms.context_processors.cms_settings', | ||||||
|  |                 'datacenterlight.context_processor.google_analytics', | ||||||
|             ], |             ], | ||||||
|         }, |         }, | ||||||
|     }, |     }, | ||||||
|  | @ -509,3 +510,7 @@ OPENNEBULA_ENDPOINT = env('OPENNEBULA_ENDPOINT') | ||||||
| # dcl email configurations | # dcl email configurations | ||||||
| DCL_TEXT = env('DCL_TEXT') | DCL_TEXT = env('DCL_TEXT') | ||||||
| DCL_SUPPORT_FROM_ADDRESS = env('DCL_SUPPORT_FROM_ADDRESS') | DCL_SUPPORT_FROM_ADDRESS = env('DCL_SUPPORT_FROM_ADDRESS') | ||||||
|  | 
 | ||||||
|  | # Settings for Google analytics | ||||||
|  | GOOGLE_ANALYTICS_PROPERTY_ID = 'UA-62285904-9' | ||||||
|  | GOOGLE_ANALYTICS_DOMAIN = 'auto' | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue