Configuring Google Analytics: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
(Created page with "== Overview == Notes about configuring Google Analytics. It seems like every time I research this topic, Google has implemented a totally different approach, so it's quite...")
 
No edit summary
 
(14 intermediate revisions by the same user not shown)
Line 3: Line 3:
Notes about configuring Google Analytics.  
Notes about configuring Google Analytics.  


It seems like every time I research this topic, Google has implemented a totally different approach, so it's quite likely that some or all of this page will be outdated before too long.
<div class="alert alert-warning">It seems like every time I research this topic, Google has implemented a totally different approach. It's likely that some or all of this page could be outdated.</div>


== Google Tag Manager ==
== Google Tag Manager ==


[https://tagmanager.google.com Google Tag Manager]
[https://tagmanager.google.com Google Tag Manager]
Create a new '''Account''' for each client.
Create a new '''Container''' for each of the client's platforms.
The container id's for each container can be found on the '''Accounts''' page in the '''Container ID''' column.
The tag code that gets inserted into the pages of the site can be found through '''Accounts''' tab > ''select a container'' > '''Admin''' tab > '''Container''' column > '''Install Google Tag Manager'''
=== Creating a tag ===
The simplest tag is a '''Page View'''.
'''Google Tag Manager''' > '''Container''' tab > '''Right Column''' > '''Tags''' > '''New''' button.
* '''Product:''' Google Analytics
* '''Tag Type:''' Universal Analytics
* '''Configure Tag:'''
** '''Tracking ID:''' ''enter the Google Analytics Tracking ID for the site''
** '''Track Type:''' Page View
* '''Fire On:''' All Pages
* Click '''Create''' button
* '''Important!''' On the next page click the '''Publish''' button in the upper right.
What this will do is link the tag manager to Google Analytics. The Tag Manager fires off page view events to Google Analytics as they happen. With this configuration, any legacy Google Analytics tracking code is unnecessary on the site.
=== Troubleshooting ===
==== 404 error for googletagmanager.com ====
'''Use case'''
# Load page in browser
# Open Chrome Developer Tools console
# Error in the console: "Failed to load resource: the server responded with a status of 404 (Not Found)" for url <nowiki>http://www.googletagmanager.com/gtm.js?id=[tag_id]</nowiki>
'''Cause'''
The tag has not been published.
'''Fix'''
Go to Google Tag Manager, locate the container, view its tags, and publish.
== Inserting GTM code into Django templates ==
=== Django templating system ===
There is an existing Django package named `django-google-tag-manager`. This package works with Django templates, but '''does not''' work with Jinja2 templates.
=== Jinja2 ===
Created a package named `[https://github.com/dbarchowsky/django-jinja2-gtm django-jinja2-gtm]` to support Jinja2 templates.
Documentation on installation and usage is found in the README in the GitHub repo.
== Alternatives to Google Analytics ==
* [https://umami.is/ Umami]
* [https://matomo.org/ Matomo]
* [https://plausible.io/ plausible.io]
* [https://usefathom.com Fathom]
* [https://simpleanalytics.com Simple Analytics]
* [https://statcounter.com/ statcounter]
[[Category:SEO]][[Category:Django]][[Category:Analytics]][[Category:Web Development]]

Latest revision as of 16:59, 29 December 2024

Overview[edit]

Notes about configuring Google Analytics.

It seems like every time I research this topic, Google has implemented a totally different approach. It's likely that some or all of this page could be outdated.

Google Tag Manager[edit]

Google Tag Manager

Create a new Account for each client.

Create a new Container for each of the client's platforms.

The container id's for each container can be found on the Accounts page in the Container ID column.

The tag code that gets inserted into the pages of the site can be found through Accounts tab > select a container > Admin tab > Container column > Install Google Tag Manager

Creating a tag[edit]

The simplest tag is a Page View.

Google Tag Manager > Container tab > Right Column > Tags > New button.

  • Product: Google Analytics
  • Tag Type: Universal Analytics
  • Configure Tag:
    • Tracking ID: enter the Google Analytics Tracking ID for the site
    • Track Type: Page View
  • Fire On: All Pages
  • Click Create button
  • Important! On the next page click the Publish button in the upper right.

What this will do is link the tag manager to Google Analytics. The Tag Manager fires off page view events to Google Analytics as they happen. With this configuration, any legacy Google Analytics tracking code is unnecessary on the site.

Troubleshooting[edit]

404 error for googletagmanager.com[edit]

Use case

  1. Load page in browser
  2. Open Chrome Developer Tools console
  3. Error in the console: "Failed to load resource: the server responded with a status of 404 (Not Found)" for url http://www.googletagmanager.com/gtm.js?id=[tag_id]

Cause

The tag has not been published.

Fix

Go to Google Tag Manager, locate the container, view its tags, and publish.

Inserting GTM code into Django templates[edit]

Django templating system[edit]

There is an existing Django package named django-google-tag-manager. This package works with Django templates, but does not work with Jinja2 templates.

Jinja2[edit]

Created a package named django-jinja2-gtm to support Jinja2 templates.

Documentation on installation and usage is found in the README in the GitHub repo.

Alternatives to Google Analytics[edit]