2017-06-27 20:47:30 +00:00
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
|
|
|
|
def google_analytics(request):
|
|
|
|
"""
|
|
|
|
Use the variables returned in this function to
|
|
|
|
render your Google Analytics tracking code template.
|
|
|
|
"""
|
2017-06-29 22:23:35 +00:00
|
|
|
host = request.get_host()
|
2017-08-24 14:04:37 +00:00
|
|
|
ga_prop_id = getattr(settings, 'GOOGLE_ANALYTICS_PROPERTY_IDS', False).get(
|
|
|
|
host)
|
|
|
|
if ga_prop_id is None:
|
|
|
|
# Try checking if we have a www in host, if yes we remove
|
|
|
|
# that and check in the dict again
|
|
|
|
if host.startswith('www.'):
|
2017-08-24 14:10:53 +00:00
|
|
|
ga_prop_id = getattr(settings, 'GOOGLE_ANALYTICS_PROPERTY_IDS',
|
|
|
|
False).get(host[4:])
|
2017-06-29 22:33:12 +00:00
|
|
|
if not settings.DEBUG and ga_prop_id:
|
2017-06-27 20:47:30 +00:00
|
|
|
return {
|
2017-06-29 22:23:35 +00:00
|
|
|
'GOOGLE_ANALYTICS_PROPERTY_ID': ga_prop_id
|
2017-06-27 20:47:30 +00:00
|
|
|
}
|
2017-06-29 22:33:12 +00:00
|
|
|
return {}
|