Step-by-Step Guide to Adding GA4 Without Google Tag Manager
Step 1: Create a Google Analytics 4 Property
- Go to Google Analytics.
- Click Admin (gear icon in the bottom left).
- Under the Account column, select your account or create a new one.
- Under the Property column, click Create Property.
- Enter a property name (e.g., YourWebsite GA4) and set your reporting time zone and currency.
- Click Next, select your industry category and business size, then click Create.
Step 2: Get Your GA4 Measurement ID
- In Google Analytics, navigate to Admin > Data Streams.
- Click on your website’s data stream.
- Copy the Measurement ID (it looks like
G-XXXXXXXXXX
).
Step 3: Add GA4 Tracking Code to Your Website
For HTML Websites:
- Open your website’s HTML file (typically
index.html
orheader.php
). - Add the following GA4 tracking code inside the
<head>
section:
<!-- Google tag (gtag.js) -->
<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>
- Replace
G-XXXXXXXXXX
with your actual Measurement ID. - Save and upload the file.
For WordPress Websites:
Option 1: Using a Plugin
- Install a plugin like Insert Headers and Footers.
- Paste the GA4 script in the Header section.
- Save changes.
Option 2: Editing Theme Files
- Navigate to Appearance > Theme Editor.
- Open the
header.php
file. - Insert the GA4 script before the closing
<head>
tag. - Save the file.
For Shopify:
- Go to Shopify Admin > Online Store > Themes.
- Click Actions > Edit Code.
- Open
theme.liquid
. - Paste the GA4 script inside the
<head>
section. - Save the changes.
For Wix, Squarespace, or Webflow:
- Use their built-in Custom Code or Tracking & Analytics section.
- Paste the GA4 script into the Header section.
- Save and publish.
Step 4: Verify That GA4 is Tracking
- Open Google Analytics > Reports > Real-Time.
- Open your website in a new tab and navigate around.
- If tracking is working, you should see active users in real-time reports.
- Alternatively, use Google Tag Assistant or GA Debugger Chrome Extension to check if GA4 is firing correctly.
Step 5: Troubleshooting Common Issues
- Tracking isn’t working? Clear your site’s cache and check for script conflicts.
- Seeing duplicate data? Ensure GA4 isn’t already installed via a plugin or another method.
- Events aren’t registering? Set up additional custom events in GA4.
Alternative: Adding GA4 with Google Tag Manager
If you prefer to use Google Tag Manager, follow these steps:
Step 1: Create a GA4 Configuration Tag
- Log in to Google Tag Manager.
- Select your container and go to Tags.
- Click New, then Tag Configuration > Google Analytics: GA4 Configuration.
- Enter your GA4 Measurement ID.
- Set Triggering to All Pages.
- Save and publish the tag.
Step 2: Verify GTM Setup
- Open Preview Mode in GTM and test events.
- Check GA4 real-time reports to confirm tracking.
Final Thoughts: The Best Approach for Your Website
If you’re looking for a straightforward and reliable GA4 setup, manually adding the tracking code is the best approach. It provides faster load times, less complexity, and direct control over your analytics data.
However, if you need to manage multiple tracking scripts, Google Tag Manager remains a powerful tool.