Google Analytics Setup

How to install and use Google Analytics to track website visitors.

Introduction

Google Analytics is a powerful free tool that lets you track and analyze your website traffic. It provides valuable insights about your visitors - where they come from, what pages they view, how long they stay, and much more. This guide will walk you through setting up Google Analytics for your website, even if you're a complete beginner.

What You'll Need

  • A Google account (Gmail)
  • An active website where you can add code
  • Access to your website's HTML or content management system (CMS)
  • 15-30 minutes to complete the setup

Understanding Google Analytics 4

In 2020, Google introduced Google Analytics 4 (GA4), which is now the standard version. GA4 is different from the previous Universal Analytics in several ways:

Feature Google Analytics 4
Data Model Event-based (focuses on user interactions)
Privacy More privacy-focused, works with or without cookies
AI Capabilities Enhanced predictive insights and analysis
Interface Streamlined, more customizable reports
Cross-Platform Better tracking across websites and apps

This guide focuses on setting up Google Analytics 4, which is the current version you'll be using for new websites.

Step 1: Create a Google Analytics Account

  1. Go to analytics.google.com
  2. Click "Start measuring" or "Sign in to Analytics"
  3. Sign in with your Google account
  4. Click "Create Account"
  5. Enter an account name (e.g., your business name)
  6. Configure data sharing settings according to your preferences
  7. Click "Next"
Screenshot of Google Analytics account creation page

The Google Analytics account creation screen

Step 2: Set Up a Property

A property in Google Analytics represents your website. Here's how to set it up:

  1. Enter a property name (usually your website name)
  2. Select your reporting time zone and currency
  3. Click "Show advanced options" if you want to create a Universal Analytics property alongside GA4 (not typically necessary for new websites)
  4. Click "Next"
  5. Enter business information as requested (industry, business size, etc.)
  6. Select how you intend to use Google Analytics
  7. Click "Create"

Step 3: Set Up a Data Stream

A data stream is the source of your analytics data - in this case, your website:

  1. Select "Web" as your platform
  2. Enter your website URL (e.g., https://www.yourdomain.com)
  3. Enter a stream name (usually your website name)
  4. Toggle Enhanced Measurement on (this automatically tracks page views, scrolls, outbound clicks, etc.)
  5. Click "Create stream"

URL Format Tip

Make sure to include "https://" or "http://" at the beginning of your URL and don't forget the "www" if your site uses it.

Step 4: Get Your Tracking Code

After creating your data stream, you'll get your Google Analytics tracking code:

  1. In the Web stream details, find "Tagging Instructions"
  2. Click "Global site tag (gtag.js)"
  3. You'll see a code snippet that looks like this:
<!-- 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>

Note: "G-XXXXXXXXXX" will be replaced with your actual Measurement ID

Step 5: Add the Tracking Code to Your Website

How you add the tracking code depends on what platform your website uses:

For HTML Websites

  1. Copy the entire tracking code
  2. Open the HTML file(s) for your website
  3. Paste the code right before the closing </head> tag
  4. Save the file(s) and upload to your web server

Multiple Pages?

If your website has multiple pages, you'll need to add the tracking code to every page. Consider using a header include file if your site uses PHP or another templating system.

For WordPress

Option 1: Using a Plugin

  1. Install and activate a plugin like "Site Kit by Google" or "Google Analytics Dashboard for WP"
  2. Follow the plugin's setup wizard to connect your Google Analytics account
  3. The plugin will automatically add the tracking code to all pages

Option 2: Manual Installation in Theme

  1. Go to Appearance > Theme Editor in your WordPress dashboard
  2. Select your theme's header.php file
  3. Paste the tracking code right before the closing </head> tag
  4. Click "Update File"

Theme Editor Warning

Be very careful when editing theme files directly. A small mistake can break your site. Consider using a child theme or plugin instead.

For Website Builders

Wix

  1. In your Wix dashboard, go to Marketing Integrations
  2. Click "Google Analytics"
  3. Enter your Measurement ID (the "G-XXXXXXXXXX" code)
  4. Click "Save"

Squarespace

  1. In your Squarespace dashboard, go to Settings > Advanced > External API Keys
  2. Scroll to "Google Analytics Account Number"
  3. Enter your Measurement ID
  4. Click "Save"

Shopify

  1. In your Shopify admin, go to Online Store > Preferences
  2. Scroll to "Google Analytics"
  3. Enter your Measurement ID
  4. Click "Save"

Step 6: Verify Your Installation

To make sure your tracking code is working correctly:

  1. Wait about 24 hours after installing the code
  2. Log in to Google Analytics
  3. Go to Reports > Realtime
  4. Open your website in another browser tab or on your phone
  5. Check if your activity appears in the Realtime report

Testing Tip

Use an "incognito" or "private" browser window to test your tracking. This prevents your own ad blockers or privacy extensions from interfering with the test.

Using Google Analytics: Key Reports

Now that you've set up Google Analytics, here are the most important reports to check regularly:

1. Realtime

Shows what's happening on your site right now. Useful for seeing immediate effects of campaigns or social media posts.

2. Acquisition

Reveals where your visitors come from (search engines, social media, direct, etc.). Find this under "Reports > Acquisition".

3. Engagement

Shows which pages visitors view, how long they stay, and what actions they take. Find this under "Reports > Engagement".

4. Demographics

Provides information about your visitors' age, gender, interests, and geographic location. Find this under "Reports > User > Demographics".

5. Conversions

Tracks when visitors complete important actions on your site (after you set up conversion events).

Report Customization

Google Analytics lets you create custom reports and dashboards. As you become more familiar with the platform, experiment with customizing reports to show the metrics that matter most to your website goals.

Advanced Setup: Setting Up Events and Conversions

Events and conversions help you track specific user actions on your website.

Setting Up Events

GA4 automatically tracks many events like page views and scrolling, but you can set up custom events:

  1. In GA4, go to "Configure > Events"
  2. Click "Create Event"
  3. Name your event
  4. Define the conditions that trigger the event
  5. Click "Save"

Tracking Form Submissions

To track when visitors submit your contact form:

// Add this code after your form's submit handling
gtag('event', 'form_submit', {
  'form_name': 'contact'
});

Setting Up Conversions

Conversions (previously called "Goals") track successful completions of important actions:

  1. In GA4, go to "Configure > Conversions"
  2. Click "New Conversion Event"
  3. Enter the event name you want to count as a conversion
  4. Click "Save"
Screenshot of Google Analytics conversion setup page

The Google Analytics conversion setup page

Privacy Considerations

When using Google Analytics, you need to consider privacy regulations and best practices:

Update Your Privacy Policy

Your website's privacy policy should disclose:

  • That you use Google Analytics
  • What data is collected
  • How that data is used
  • That users can opt out using browser settings or extensions

Cookie Consent Banner

For GDPR compliance (European visitors), consider adding a cookie consent banner that:

  • Informs visitors about cookies and tracking
  • Allows visitors to accept or decline non-essential cookies
  • Only loads Google Analytics after consent is given
// Example of loading analytics only after consent
function loadAnalytics() {
  // Google Analytics code here
}

// Call this function when user accepts cookies
document.getElementById('cookie-accept').addEventListener('click', loadAnalytics);

IP Anonymization

GA4 anonymizes IP addresses by default, which helps with privacy compliance.

Troubleshooting Common Issues

No data appearing in reports

  • Verify the tracking code is correctly installed
  • Check if you have an ad blocker or privacy extension active
  • Wait 24-48 hours for data to appear
  • Use the Realtime report to verify tracking
  • Check if your website has consent requirements that block tracking

Self-referrals appearing in reports

  • Add your domain to the Referral Exclusion List
  • Go to Admin > Property Settings > Data Streams > [Your Web Stream] > Configure tag settings > Define internal traffic
  • Add your domain to exclude it from referral traffic

Tracking code conflicts with website

  • Make sure the tracking code is placed before the closing </head> tag
  • Check for duplicate tracking codes
  • Verify there are no JavaScript errors on your page
  • Try using Google Tag Manager instead of direct implementation

Next Steps

After setting up basic Google Analytics tracking, consider these next steps:

  • Connect Google Search Console: For insights about your site's search performance
  • Set up conversion tracking: To measure important user actions
  • Create custom dashboards: For easier monitoring of key metrics
  • Implement enhanced e-commerce tracking: If you run an online store
  • Set up automated reports: To receive regular email updates
  • Learn more about SEO: Check our SEO Basics guide to improve your search visibility

Need Help With Analytics?

Contact us for personalized assistance with setting up and using Google Analytics.

Get in Touch