Skip to main content
Glarify Docs

Documentation

Complete guide to Glarify SEO Analytics — set up, learn the workflow, and ship faster.

How to Add Google Analytics to Your Website

How to Add Google Analytics to Your Website

Complete guide to setting up Google Analytics 4 on your website

Updated 2024-12-21

How to Add Google Analytics to Your Website

Google Analytics 4 (GA4) is essential for understanding your website's traffic, user behavior, and conversions. This guide walks you through adding GA4 to your website from scratch.

Prerequisites

Before you begin, you'll need:

  • A Google account
  • Access to your website's code or CMS
  • Admin access to add tracking scripts

Step 1: Create a Google Analytics Account

  1. Go to analytics.google.com
  2. Click "Start measuring" or "Create Account"
  3. Enter your Account Name (e.g., your business name)
  4. Configure data sharing settings (recommended: keep defaults)
  5. Click "Next"

Step 2: Set Up a GA4 Property

  1. Enter your Property Name (e.g., "My Website")
  2. Select your Reporting Time Zone and Currency
  3. Click "Next"
  4. Choose your Industry Category and Business Size
  5. Click "Create"

Step 3: Create a Data Stream

  1. Select "Web" as your platform
  2. Enter your Website URL (e.g., https://example.com)
  3. Enter a Stream Name (e.g., "Main Website")
  4. Click "Create Stream"

Step 4: Get Your Measurement ID

After creating your data stream, you'll see:

  • Measurement ID: Format G-XXXXXXXXXX
  • Stream URL: Your website URL
  • Stream ID: Internal identifier

Important: Copy your Measurement ID - you'll need this for the next step.

Step 5: Add the Tracking Code

Add this code to the <head> section of every page:

<!-- 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

Option B: Google Tag Manager

If you're using GTM:

  1. Open your GTM container
  2. Create a new Tag → Select "Google Analytics: GA4 Configuration"
  3. Enter your Measurement ID
  4. Set trigger to "All Pages"
  5. Publish the container

Option C: CMS-Specific Setup

PlatformMethod
WordPressInstall "Site Kit by Google" or "GA Google Analytics" plugin
ShopifySettings → Online Store → Preferences → Google Analytics
WixMarketing Integrations → Google Analytics
SquarespaceSettings → Advanced → External Services
WebflowProject Settings → Integrations → Google Analytics

Step 6: Verify Installation

Method 1: Real-Time Reports

  1. Open your website in a new tab
  2. In GA4, go to Reports → Realtime
  3. You should see your visit appear within 30 seconds

Method 2: Google Tag Assistant

  1. Install the Tag Assistant Chrome extension
  2. Visit your website
  3. Check that GA4 tag shows as "connected"

Method 3: Browser Developer Tools

  1. Open DevTools (F12)
  2. Go to Network tab
  3. Filter by collect or google-analytics
  4. Refresh the page and check for requests

Step 7: Configure Essential Settings

Once installed, configure these important settings:

Enable Enhanced Measurement

  1. Go to Admin → Data Streams → Your Stream
  2. Click Enhanced Measurement
  3. Enable:
    • ✅ Page views
    • ✅ Scrolls
    • ✅ Outbound clicks
    • ✅ Site search
    • ✅ Video engagement
    • ✅ File downloads

Set Up Conversions

  1. Go to Admin → Conversions
  2. Click "New Conversion Event"
  3. Enter event names like:
    • purchase
    • generate_lead
    • sign_up
    • contact_form_submit

Configure Data Retention

  1. Go to Admin → Data Settings → Data Retention
  2. Set retention to 14 months (maximum free)
  3. Enable "Reset user data on new activity"

Connecting GA4 to Glarify

Once GA4 is installed and collecting data:

  1. Go to Settings → Integrations in Glarify
  2. Click "Sync Properties from Google"
  3. Select your GA4 property from the list
  4. Click "Connect"

Your GA4 data will now appear in:

  • Analytics Dashboard - Full GA4 reports
  • All-in-One View - Combined with GSC data
  • AI Insights - AI-powered analysis of your traffic

Troubleshooting

IssueSolution
No data appearingWait 24-48 hours for data to populate
Realtime works but reports emptyCheck date range includes today
Double-counting pageviewsRemove duplicate gtag code snippets
Bot traffic inflating numbersEnable bot filtering in Admin → Data Settings
GA4 not showing in GlarifyEnsure your Google account has Viewer access

Best Practices

  1. Don't install multiple GA4 codes - This causes double-counting
  2. Use Google Tag Manager for complex setups - Easier to manage
  3. Set up cross-domain tracking if you have multiple domains
  4. Create custom events for important user actions
  5. Link to Google Search Console for SEO insights