We\'re about to deploy a new Django website, and we want to use Google Analytics to keep track of traffic on the site. However, we don\'t want all of the hits on developmen
Here's the dead simple way that I solved it:
Create an app in your project called 'utils' if you haven't already. See these directions.
However, follow this approach to include all global context processers in addition to the project settings. It's seems to be a better practice. Here are the instructions.
So, after you create your 'utils' app, create a a file called context_processors.py in /utils that looks like this:
from django.conf import settings
def googleanalytics(request):
return {
'google_tracking_id' : settings.GOOGLE_TRACKING_ID,
}
In you settings.py file, add this:
import django.conf.global_settings as DEFAULT_SETTINGS
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
'utils.context_processors.googleanalytics',
)
Hope this helps!