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
- Go to analytics.google.com
- Click "Start measuring" or "Sign in to Analytics"
- Sign in with your Google account
- Click "Create Account"
- Enter an account name (e.g., your business name)
- Configure data sharing settings according to your preferences
- Click "Next"
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:
- Enter a property name (usually your website name)
- Select your reporting time zone and currency
- Click "Show advanced options" if you want to create a Universal Analytics property alongside GA4 (not typically necessary for new websites)
- Click "Next"
- Enter business information as requested (industry, business size, etc.)
- Select how you intend to use Google Analytics
- Click "Create"
Step 3: Set Up a Data Stream
A data stream is the source of your analytics data - in this case, your website:
- Select "Web" as your platform
- Enter your website URL (e.g., https://www.yourdomain.com)
- Enter a stream name (usually your website name)
- Toggle Enhanced Measurement on (this automatically tracks page views, scrolls, outbound clicks, etc.)
- 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:
- In the Web stream details, find "Tagging Instructions"
- Click "Global site tag (gtag.js)"
- 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
- Copy the entire tracking code
- Open the HTML file(s) for your website
- Paste the code right before the closing
</head>
tag
- 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
- Install and activate a plugin like "Site Kit by Google" or "Google Analytics Dashboard for WP"
- Follow the plugin's setup wizard to connect your Google Analytics account
- The plugin will automatically add the tracking code to all pages
Option 2: Manual Installation in Theme
- Go to Appearance > Theme Editor in your WordPress dashboard
- Select your theme's header.php file
- Paste the tracking code right before the closing
</head>
tag
- 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
- In your Wix dashboard, go to Marketing Integrations
- Click "Google Analytics"
- Enter your Measurement ID (the "G-XXXXXXXXXX" code)
- Click "Save"
Squarespace
- In your Squarespace dashboard, go to Settings > Advanced > External API Keys
- Scroll to "Google Analytics Account Number"
- Enter your Measurement ID
- Click "Save"
Shopify
- In your Shopify admin, go to Online Store > Preferences
- Scroll to "Google Analytics"
- Enter your Measurement ID
- Click "Save"
Step 6: Verify Your Installation
To make sure your tracking code is working correctly:
- Wait about 24 hours after installing the code
- Log in to Google Analytics
- Go to Reports > Realtime
- Open your website in another browser tab or on your phone
- 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:
- In GA4, go to "Configure > Events"
- Click "Create Event"
- Name your event
- Define the conditions that trigger the event
- 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:
- In GA4, go to "Configure > Conversions"
- Click "New Conversion Event"
- Enter the event name you want to count as a conversion
- Click "Save"
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