0

AIM

Using Django to install Google Analytics.

PROBLEM

It isn't clear to me if I need to apply the following lines to ALL the templates I am interested in tracking or just to index.html.

{% load google_analytics_tags %}
<div style="display:none">
    <img src="{% google_analytics %}" width="0" height="0" />
</div>

If the answer is that by simply pasting it into index.html would add it to all my existing templates, how can I exclude the pages I don't want any tracking from?

I am following the steps from: https://pypi.org/project/django-google-analytics-app/

Thanks in advance for your help.

1 Answer 1

1

The best way would be to create a seperate template called analytics.html and put your analytics code in this file then add the line

{% include "analytics.html" %}

to the files you want to track analytics for.

Sign up to request clarification or add additional context in comments.

4 Comments

In that template called analytics.html I would paste the code exactly as it is in my question right? Including {% load google_analytics_tags %} ?
@Joehat I see that you are using pypi.org/project/django-google-analytics-app I have not personally used this library but according to their documentation seems like it should work.
I forgot to include the link to the question. I've just edited it. From that same link, in step 3. would I paste (r'^djga/', include('google_analytics.urls')), as it is in urls.py or should I paste it inside something else and in step 4. where would GOOGLE_ANALYTICS = { 'google_analytics_id': 'xxx', } go? Is it in settings.py ? Thanks you for help!
yes, you are right, the first part goes in urls.py and second in settings.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.