How to Integrate Google Analytics 4
Setting up Google Analytics 4 on your website is the first critical step towards understanding how visitors find you and what they do once they arrive. This tutorial will guide you through the most common and effective ways to integrate GA4, ensuring you can start collecting valuable data today.
First Things First: Grab Your GA4 Measurement ID
No matter which installation method you choose, you'll need a unique code from Google that connects your website to your GA4 property. This is called your "Measurement ID." Finding it is quick and easy.
Here's how to get it:
- Log in to your Google Analytics account.
- Click the Admin gear icon in the bottom-left corner.
- In the Property column, make sure your desired GA4 property is selected. If not, use the dropdown to find it.
- Click on Data Streams.
- You'll see a list of your data streams. Click on the one for your website.
- On the top right, you'll see your Measurement ID, which looks like
G-XXXXXXXXXX. Click the copy icon next to it.
Keep this ID handy. You're going to need it in the next steps.
Method 1: The Recommended Way - Google Tag Manager (GTM)
Using Google Tag Manager is the most flexible and scalable way to manage GA4 and other marketing tags (like a Facebook Pixel or Google Ads tag). It acts as a central control panel for all the code snippets you need to add to your site, so you don’t have to keep a developer on speed dial every time you need to add or change something.
Why Use GTM?
- Future-Proofing: Adding new tracking events or other marketing tags is done within GTM's interface, not by editing your site's code.
- Control & Safety: GTM's "Preview Mode" lets you test your changes before making them live, reducing the risk of breaking your website.
- Reduces Bloat: Instead of adding ten different scripts to your site's code, you just add the GTM script once. Everything else is managed through GTM.
Step-by-Step GTM Integration
If you don't have a GTM container set up for your site yet, you'll need to do that first. Head to Google Tag Manager, create an account and container, and follow the instructions to add the two GTM code snippets to your website code.
Once GTM is installed on your site, follow these steps to add GA4:
- In your GTM Workspace, click on Tags > New.
- Give your tag a clear name, something like "GA4 - Configuration Tag".
- Click inside the Tag Configuration box and select Google Analytics: GA4 Configuration from the list.
- In the Measurement ID field, paste the
G-XXXXXXXXXXID you copied earlier. - Make sure the "Send a page view event when this configuration loads" box is checked. This enables automatic tracking of page views.
- Next, click inside the Triggering box.
- Select the trigger named All Pages - Page View. This tells GTM to fire your GA4 tag on every page of your website.
- Click Save in the top-right corner.
- This is an important step! To test your setup, click the Preview button. This opens a new tab where you can enter your website's URL. Your site will open with a GTM debug panel. Check the summary on the left, you should see your "GA4 - Configuration Tag" listed under "Tags Fired".
- Once you've confirmed it's working, go back to your GTM workspace and click the Submit button. Give your changes a name (like "Added GA4 Config Tag") and click Publish. Your GA4 integration is now live!
Method 2: Using Website Builder Plugins & Integrations
If you use a popular CMS like WordPress, Shopify, Squarespace, or Wix, there's a good chance they offer a simple, code-free way to add your GA4 Measurement ID.
For WordPress Users
For WordPress, the easiest path is to use a plugin that handles the integration for you. This avoids the technical and risky process of editing your theme files directly.
- Site Kit by Google: This is Google’s official plugin. It's a great option because it simplifies connecting GA4, Search Console, and AdSense. Once installed and activated, you just follow the on-screen instructions to sign in with your Google account and select the correct property.
- Other Plugins (e.g., MonsterInsights, GA Google Analytics): Many plugins are built specifically for adding analytics. The process is generally the same: install and activate the plugin, find its setting page, and look for a field where you can paste your GA4 Measurement ID.
To get started, simply go to your WordPress dashboard, navigate to Plugins > Add New, and search for your preferred option.
For Shopify Stores
Shopify makes this extremely simple with a built-in integration.
- From your Shopify admin, go to Online Store > Preferences.
- Scroll down to the Google Analytics section.
- An older Universal Analytics (UA) code might already be there. Remove it if so.
- In the "Google Analytics 4" section, click Manage pixel here.
- If this is your first time, click Connect your Google account and follow the sign-in and permission prompts.
- Select your GA4 property from the list and click Connect.
Shopify automatically adds the necessary page view tracking and even includes e-commerce events like add_to_cart and purchase, giving you rich sales data right out of the box.
Method 3: The Manual Way - Adding Code Directly to Your Website
This method involves editing your website's HTML code. Only use this method if you are comfortable editing code and have a backup of your site. This is common for custom-built websites or when you don't have access to plugins or a tag manager.
Here’s how to do it:
- In your GA4 property, go back to Admin > Data Streams and click on your web stream.
- Under the "Event" section at the bottom, look for a box on the left called Tag Instructions. Click 'View tag Instructions'.
- A new screen will pop up. Choose Install Manually.
- GA4 provides you with the Global Site Tag (gtag.js) tracking code. It will look like this, but with your specific Measurement ID:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [],
function gtag(){dataLayer.push(arguments),}
gtag('js', new Date()),
gtag('config', 'G-XXXXXXXXXX'),
</script>- Copy this entire code block.
- You need to paste this code into the
<head>section of your website’s HTML on every single page. If your site uses a template file (like aheader.phpfile in WordPress), you can place it there to have it load automatically on all pages.
Warning: Pasting this code in the wrong place can break your site's layout or functionality. Additionally, theme updates can sometimes overwrite these changes, so the GTM or plugin methods are usually more stable.
How to Verify Your GA4 Installation Is Working
Once you've completed one of the methods above, you need to confirm that Google is receiving data. Here are two easy ways to check:
1. Use the Realtime Report
This is the simplest verification method.
- Go to your GA4 property.
- In the left-hand navigation, click Reports > Realtime.
- In a separate browser tab, open your website.
- Within a minute or two, you should see yourself appear as a visitor in the Realtime report. You'll see cards populate with data like "Users in the last 30 minutes" and your geographic location. If you see activity, it's working!
2. Use the Tag Assistant Browser Extension
For a more detailed check, you can use the Tag Assistant Companion browser extension.
- Install the extension from the Chrome Web Store.
- Go to your website and enable the extension by clicking its icon in your browser toolbar.
- After the page loads, the Tag Assistant will show all the tags found on the page.
- Look for your GA4 tag. If it's working correctly, you should see a green tag indicating that data is being sent to Google Analytics.
Final Thoughts
Integrating Google Analytics 4 is a foundational task for any website owner, marketer, or business. Whether you use the robust controls of Google Tag Manager, a simple CMS plugin, or go the manual route, a proper setup ensures you are collecting the clean, reliable data necessary for making smart decisions.
Getting your data pipeline set up is the first step, but the real power comes from turning that data into clear, actionable insights - without getting lost in endless reports. This is precisely why we built Graphed. After connecting Google Analytics, you can skip the manual report building and simply ask questions in plain English, like "show me our top 5 landing pages from organic search" or "compare user traffic from the US to Canada last month," and get a live dashboard instantly. It’s all about getting you answers, faster.
Related Articles
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.
How to Create a Photo Album in Meta Business Suite
How to create a photo album in Meta Business Suite — step-by-step guide to organizing Facebook and Instagram photos into albums for your business page.