Merge branch 'master' of https://github.com/ungleich/dynamicweb
This commit is contained in:
		
				commit
				
					
						e17792badb
					
				
			
		
					 7 changed files with 68 additions and 22 deletions
				
			
		|  | @ -33,6 +33,9 @@ | |||
|         <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> | ||||
|         <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> | ||||
|     <![endif]--> | ||||
|     <!-- Google analytics --> | ||||
|     {% include "google_analytics.html" %} | ||||
|     <!-- End Google Analytics --> | ||||
| </head> | ||||
| 
 | ||||
| <body> | ||||
|  |  | |||
|  | @ -43,23 +43,9 @@ | |||
|         <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> | ||||
|     <![endif]--> | ||||
| 
 | ||||
|     <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', 'UA-62285904-2', 'auto'); | ||||
|         ga('send', 'pageview'); | ||||
| 
 | ||||
|     </script> | ||||
|     <!-- Google analytics --> | ||||
|     {% include 'google_analytics.html' %} | ||||
|     <!-- End Google Analytics --> | ||||
| </head> | ||||
| 
 | ||||
| <body> | ||||
|  |  | |||
|  | @ -118,6 +118,7 @@ INSTALLED_APPS = ( | |||
| 
 | ||||
| MIDDLEWARE_CLASSES = ( | ||||
|     'django.contrib.sessions.middleware.SessionMiddleware', | ||||
|     'utils.middleware.MultipleProxyMiddleware', | ||||
|     'django.middleware.common.CommonMiddleware', | ||||
|     'django.middleware.csrf.CsrfViewMiddleware', | ||||
|     'django.contrib.auth.middleware.AuthenticationMiddleware', | ||||
|  | @ -138,6 +139,7 @@ TEMPLATES = [ | |||
|     { | ||||
|         'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||||
|         'DIRS': [os.path.join(PROJECT_DIR, 'cms_templates/'), | ||||
|                  os.path.join(PROJECT_DIR, 'templates'), | ||||
|                  os.path.join(PROJECT_DIR, 'cms_templates/djangocms_blog/'), | ||||
|                  os.path.join(PROJECT_DIR, 'membership'), | ||||
|                  os.path.join(PROJECT_DIR, 'hosting/templates/'), | ||||
|  | @ -161,6 +163,7 @@ TEMPLATES = [ | |||
|                 "django.contrib.messages.context_processors.messages", | ||||
|                 'sekizai.context_processors.sekizai', | ||||
|                 'cms.context_processors.cms_settings', | ||||
|                 'utils.context_processor.google_analytics', | ||||
|             ], | ||||
|         }, | ||||
|     }, | ||||
|  | @ -509,3 +512,12 @@ OPENNEBULA_ENDPOINT = env('OPENNEBULA_ENDPOINT') | |||
| # dcl email configurations | ||||
| DCL_TEXT = env('DCL_TEXT') | ||||
| DCL_SUPPORT_FROM_ADDRESS = env('DCL_SUPPORT_FROM_ADDRESS') | ||||
| 
 | ||||
| # Settings for Google analytics | ||||
| GOOGLE_ANALYTICS_PROPERTY_IDS = { | ||||
|     'datacenterlight.ch': 'UA-62285904-9', | ||||
|     'digitalglarus.ch': 'UA-62285904-2', | ||||
|     '127.0.0.1:8000': 'localhost', | ||||
|     'dynamicweb-development.ungleich.ch': 'development', | ||||
|     'dynamicweb-staging.ungleich.ch': 'staging' | ||||
| } | ||||
|  |  | |||
							
								
								
									
										13
									
								
								templates/google_analytics.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								templates/google_analytics.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| {% 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 }}', 'auto'); | ||||
|         ga('send', 'pageview'); | ||||
|     </script> | ||||
| {% else %} | ||||
|     <!-- Empty analytics --> | ||||
| {% endif %} | ||||
							
								
								
									
										15
									
								
								utils/context_processor.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								utils/context_processor.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| from django.conf import settings | ||||
| 
 | ||||
| 
 | ||||
| def google_analytics(request): | ||||
|     """ | ||||
|     Use the variables returned in this function to | ||||
|     render your Google Analytics tracking code template. | ||||
|     """ | ||||
|     host = request.get_host() | ||||
|     ga_prop_id = getattr(settings, 'GOOGLE_ANALYTICS_PROPERTY_IDS', False).get(host) | ||||
|     if not settings.DEBUG and ga_prop_id: | ||||
|         return { | ||||
|             'GOOGLE_ANALYTICS_PROPERTY_ID': ga_prop_id | ||||
|         } | ||||
|     return {} | ||||
							
								
								
									
										17
									
								
								utils/middleware.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								utils/middleware.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,17 @@ | |||
| class MultipleProxyMiddleware(object): | ||||
|     FORWARDED_FOR_FIELDS = [ | ||||
|         'HTTP_X_FORWARDED_FOR', | ||||
|         'HTTP_X_FORWARDED_HOST', | ||||
|         'HTTP_X_FORWARDED_SERVER', | ||||
|     ] | ||||
| 
 | ||||
|     def process_request(self, request): | ||||
|         """ | ||||
|         Rewrites the proxy headers so that only the most | ||||
|         recent proxy is used. | ||||
|         """ | ||||
|         for field in self.FORWARDED_FOR_FIELDS: | ||||
|             if field in request.META: | ||||
|                 if ',' in request.META[field]: | ||||
|                     parts = request.META[field].split(',') | ||||
|                     request.META[field] = parts[-1].strip() | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue