How to install Google Analytics in accordance with GDPR

Google Analytics 4 (GA4) is Google’s next-generation analytics platform, essential for monitoring traffic and conversions on your website. GA4 provides valuable insights into user behavior, helps you measure the performance of your marketing campaigns, and ensures you stay compliant with privacy regulations such as the GDPR.

This tutorial will guide you through installing Google Analytics 4 on your website and configuring it to comply with privacy rules.


Step 1: Create a Google Analytics 4 Property

To begin, make sure you have a Google account and admin access to the website where you want to install analytics.

  1. Log in to Google Analytics.
  2. Click on the Admin (gear icon) in the lower-left sidebar.
  3. In the “Account” column, select the relevant account or create a new one if needed.
  4. In the “Property” column, click Create Property and follow the prompts to set the property name, time zone, and currency.
  5. Complete the setup by answering questions about your business type, then click Next and Create.

Step 2: Get the GA4 Tracking Code

After setting up the property:

  1. Go to Data Streams and choose Web.
  2. Enter your website’s URL and assign a name to the stream.
  3. Click Create Stream. The tracking code (in the format G-XXXXXXXXXX) will be displayed.
  4. Copy the provided Global Site Tag (gtag.js) code snippet.

Step 3: Insert the GA4 Code into Your WordPress Site

  • You can manually insert the code into your theme’s header.php file (before the closing </head> tag), or use a plugin like “Insert Headers and Footers” to add the script safely, without editing theme files directly.

If You’re Using Google Tag Manager:

  1. Create a new Tag of the type “GA4 Configuration.”
  2. Enter your Measurement ID from Google Analytics (G-XXXXXXXXXX format).
  3. Set the trigger to “All Pages” and publish the tag.

Step 4: Ensure GDPR Compliance

Activate the "Cookie Shield" feature in My Agile Privacy: this mode can automatically detect cookies and third-party software. Set the Shield to "Learning" mode, browse your site’s pages, and your configuration will be ready.
Tip: Ensure your consent settings are compatible with Google Consent Mode v2.


Step 5: Verify the Installation

Once everything is configured, return to Google Analytics, go to Real Time, and browse your site in a private (incognito) window. You should see your visit appear.
Note: Sometimes, it takes a few minutes for data to show up in your reports.


Bonus: Advanced & Server-Side Solutions

If you want optimized performance, maximum privacy compliance, and to avoid blocking from iOS or AdBlockers, solutions like My Agile Pixel let you send Google Analytics 4 data server-side, improving data quality and accuracy.
See here for details on integrating GA4 with My Agile Pixel for a GDPR-compliant, future-proof solution.


With these steps, you can install Google Analytics 4 easily, securely, and in full compliance with current regulations—so you can start collecting quality data to help your online project grow!

Download the free guide

Fill out the form and get immediate access to the guide in PDF format.
Mockup del pdf della guida
Loading in Progress...
Request successfully sent. You will be redirected to the download page shortly
By submitting this form I declare that I have read the privacy policy and authorize the Owner to respond to me for what is expressed in point a of the privacy policy
Warning: Your Cookie choices may not allow the form to be submitted.
Click here to review your preferences.
buy now My Agile Privacy - compliant in less than 3 minutes
a Formula Agile SRL project
COE / TAX ID 31366
Via Tre Settembre, 99 - 47891 Dogana - San Marino - RSM
Share capital 26'000€
For assistance: info[at]myagileprivacy.com
GDPR and privacy present complexities that extend beyond achieving website compliance. Compliance obligations span across all business aspects and necessitate expert analysis.
When it comes to implementing Banners and Policies, trust My Agile Privacy—the only solution that excludes unnecessary implementations not mandated by regulations.
Logo CMP partner GoogleLogo CMP partner GoogleLogo CMP partner GoogleLogo IAB Europe approvedLogo IAB Europe approved