
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.
- Log in to Google Analytics.
- Click on the Admin (gear icon) in the lower-left sidebar.
- In the “Account” column, select the relevant account or create a new one if needed.
- In the “Property” column, click Create Property and follow the prompts to set the property name, time zone, and currency.
- 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:
- Go to Data Streams and choose Web.
- Enter your website’s URL and assign a name to the stream.
- Click Create Stream. The tracking code (in the format G-XXXXXXXXXX) will be displayed.
- 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:
- Create a new Tag of the type “GA4 Configuration.”
- Enter your Measurement ID from Google Analytics (G-XXXXXXXXXX format).
- 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!