Warm tip: This article is reproduced from stackoverflow.com, please click
django google-analytics python google-analytics-api

Using Django to install Google Analytics tracking code

发布于 2020-04-13 10:39:54

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.

Questioner
Joehat
Viewed
63
Arun Nalla 2020-02-04 00:49

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.