Google Analytics for WordPress: A Step-by-Step Setup Guide
Published on June 15, 2024
6 min readIntroduction: Why You Need Analytics - From Guesswork to Insight
Running a website without analytics is like driving a car at night with the headlights off. You might be moving, but you don't know where you're going, how fast you're getting there, or what obstacles are in your way. You are operating on pure guesswork. Google Analytics is a free, incredibly powerful tool that acts as your website's dashboard, providing invaluable data about your visitors. It answers critical business questions:
- Who are my visitors? (Demographics: age, gender, location)
- How did they find my site? (Acquisition: Google search, social media, direct link)
- What content are they engaging with? (Behavior: which pages are most popular, how long do they stay)
- Are they achieving my goals? (Conversions: are they filling out my contact form, signing up for my newsletter)
This data is essential for making informed, strategic decisions about your content strategy, marketing efforts, and website design. This guide will walk you through setting up the latest version, Google Analytics 4 (GA4), on your WordPress site.
Step 1: Create a Google Analytics Account & Property
First, you need to create the structure within Google Analytics to hold your website's data.
- Go to the Google Analytics website and sign in with your Google account. If you don't have one, you'll need to create one.
- Click 'Start measuring'.
- Account Setup: This is the highest level of the hierarchy. Give your account a name, typically your business or organization name (e.g., 'Ajaya BK Digital Services'). Under 'Account Data Sharing Settings,' you can leave the recommended options checked.
- Property Setup: A property represents your website or app. Give your property a name (e.g., 'ajayabk.com.np'), and critically, select your correct reporting time zone and currency. This ensures your reports make sense in your local context.
- Business Details: On the next screen, fill out the information about your industry and business size. This helps Google provide you with benchmark data against similar businesses.
- Business Objectives: This is a step new to GA4. It helps tailor the reports you see by default. For a freelance portfolio site, good objectives to choose would be 'Generate leads' and 'Examine user behavior'.
- Accept the Google Analytics Terms of Service after selecting your country.
Step 2: Create a Web Data Stream
After creating your account and property, you need to create a 'Data Stream'. This is the specific source of data for your property. Since you're tracking a website, you'll create a Web stream.
- After accepting the terms, you'll be prompted to 'Choose a platform'. Click 'Web'.
- Set up your web stream:
- Enter your website's URL (e.g.,
https://ajayabk.com.np). Make sure you have the correct protocol (http vs. https). - Give the stream a name (e.g., 'My Website Stream').
- Leave 'Enhanced measurement' enabled. This is a powerful feature of GA4 that automatically tracks key user interactions like page views, scrolls, outbound clicks, and file downloads without any extra configuration.
- Enter your website's URL (e.g.,
- Click 'Create stream'.
Step 3: Get Your Measurement ID
Once you create the data stream, you will be taken to a page with your stream details. The most important piece of information here is the 'MEASUREMENT ID'. It will be in the format G-XXXXXXXXXX. This ID is the unique identifier that connects your website to this specific data stream.
Copy this Measurement ID. You will need it in the next step.
Step 4: Add the Google Analytics Code to Your WordPress Site
You now need to place the GA4 tracking code onto every page of your WordPress site. There are several ways to do this. For simplicity and safety, using a plugin is the highly recommended method.
Method 1: Using a Simple Code Snippet Plugin (Recommended for Beginners)
Using a dedicated plugin is the easiest and safest method because it prevents you from having to edit your theme's files directly, which can break your site or be overwritten during theme updates.
- In your WordPress dashboard, go to Plugins > Add New.
- Search for 'WPCode - Insert Headers and Footers'. This is a simple, lightweight, and very popular plugin for this exact purpose.
- Install and activate the plugin.
- In your WordPress dashboard, navigate to Code Snippets > Header & Footer.
- Now, go back to your Google Analytics 'Web stream details' page. Under 'Installation instructions', click on the 'Install manually' tab. You will see a 'Global Site Tag' (
gtag.js) code snippet that looks something 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> - Copy this entire code snippet.
- Go back to your WordPress tab and paste the snippet into the 'Header' box in the WPCode settings.
- Click 'Save Changes'.
Method 2: Using Google's Official Site Kit Plugin
Google's own Site Kit plugin is another excellent option. It's more heavyweight than WPCode, but it offers a huge advantage: it not only adds the Analytics code but also integrates data from Google Search Console, AdSense, and PageSpeed Insights directly into your WordPress dashboard, giving you a single place to see all your key metrics.
- Install and activate the 'Site Kit by Google' plugin.
- Follow the on-screen setup wizard to connect your Google account.
- Site Kit will automatically detect that you have an Analytics account for this site and allow you to connect it with a single click. It handles all the code placement for you.
Step 5: Verify the Installation
After adding the code, you need to make sure it's working correctly.
- Go back to your Google Analytics dashboard.
- In the left-hand navigation, navigate to Reports > Realtime.
- Open your website in a new incognito browser tab and click around a few pages.
- You should see yourself appear as an active user in the Realtime report within a minute or two. You'll see a '1' in the 'Users in last 30 minutes' card and a blue dot on the world map in your location. If you do, congratulations! Google Analytics is now successfully installed and collecting data.
It can take 24-48 hours for the standard reports (like demographics and acquisition) to start populating, but the Realtime view gives you immediate confirmation that the connection is working.
Written by
Ajaya BK
Ajaya is a WordPress Virtual Assistant specializing in helping businesses set up, fix, and optimize their websites for speed, reliability, and clarity.
More about me