Analytics

Understanding how users interact with your application is crucial for making informed decisions about features, content, and user experience. PyBoilerplate integrates Google Analytics 4 through Google Tag Manager (GTM), providing robust analytics that only activate when users explicitly accept analytics cookies through the consent banner.

 

google analytics interface

Google Analytics Interface

Google Analytics

Google Analytics is a web analytics service that tracks and reports website traffic, providing essential insights into user behavior and application performance.

Analytics tracking can be configured to trigger only after obtaining user cookie consent, or implemented directly across all pages via Google Tag Manager if consent is not required. The configuration to trigger based on user consent will be described in the following section.

 

Create a Google Analytics Account

  • Go to Google Analytics' plateform
  • Create an account & a Property
  • You will get a GA measurement ID (it will be needed for the GA tag)

Trigger via Google Tag Manager

Cookie Consent & Analytics Flow

The sequence diagram outlines how cookie consent and tracking work together in the boilerplate. When users first accept cookies on the homepage, GTM initializes GA4 tracking via a 'cookieConsentUpdate' event. As users browse other pages, GTM checks their consent before sending page views to GA4, all managed through a single configuration tag that handles both initial consent and ongoing tracking.

 

 

Create a Google Analytics Tag in GTM

1. Go to Tags > New

2. Configure the tag

Name: Google Analytics GA4 Event
Type: Google Tag
Tag ID: refers to your Google Analytics measurement ID
Firing Triggers: All Page Views with Cookie Consent Accepted OR All Page Views with Updated Consent

 

GA4 tag in GTM

3. Submit & Publish changes

Note: For cookie consent triggers setup, see: Docs > Cookie Banner > Google Tag Manager

More Analytics & Marketing Tools

The Cookie Consent triggers (set up in Docs > Cookie Banner > GTM) can be used when implementing tags for other tracking tools such as:

- Analytics (Matomo, Amplitude, Mixpanel)

- Ads/Marketing (Google Ads, Meta Pixel)

- Behavior/Heat maps (HotJar, Microsoft Clarity)

- CRM/Marketing (Hubspot)