Blog

How to add analytics to WordPress — a simple guide

WordPress powers over 40% of the web. That is a staggering number, and it means millions of site owners share the same question: how do I know if my website is actually working? Are people visiting? Where are they coming from? Which pages do they care about? Are they buying anything?

The answer to all of those questions starts with analytics. Without analytics, you are guessing. You might spend weeks writing a blog post that nobody reads, or redesign a page that was already your best performer. Analytics gives you facts instead of hunches. It tells you what is happening on your site so you can make better decisions about what to do next.

The good news is that adding analytics to WordPress is straightforward. There are several approaches, and the right one depends on what you need, how technical you are, and how much you care about things like privacy and page speed. This guide walks through all of them — from the most popular options to the exact steps for installing them on your WordPress site.

Why you need analytics on your WordPress site

Every visitor to your WordPress site is a signal. They arrived from somewhere — a Google search, a social media link, a newsletter, a direct bookmark. They looked at something. They either stayed or left. Without analytics, all of those signals vanish the moment the visitor closes their browser tab.

Analytics answers the fundamental questions every site owner needs to know. How many people visited today? Which pages are the most popular? Where is your traffic coming from — organic search, social media, paid ads, or direct visits? What countries are your visitors in? Are they on mobile or desktop? How long do they stay? Do they visit more than one page, or do they bounce immediately?

If you run a blog, analytics tells you which posts attract readers and which ones fall flat. If you sell products with WooCommerce, analytics reveals your conversion rate, your best-selling product pages, and where customers drop off in the checkout flow. If you rely on contact form submissions, analytics shows you whether your traffic is actually converting into leads.

Without this data, you are making decisions based on instinct. Some people have good instincts. Most do not — and even the ones who do make better decisions when they have data to back up their gut feelings. Analytics is the foundation of every other marketing and optimization activity. Everything else — SEO, content marketing, paid advertising, conversion rate optimization — depends on having reliable data about what is happening on your site.

Option 1: Google Analytics (GA4)

Google Analytics is the most widely used analytics tool on the internet. The current version, GA4, replaced Universal Analytics in 2023 and brought a completely new data model, interface, and way of thinking about tracking. It is free, incredibly powerful, and backed by the largest search engine in the world.

How to add GA4 to WordPress. You have two main approaches. The first is using a plugin like MonsterInsights or Site Kit by Google. Install the plugin from your WordPress dashboard (Plugins → Add New), activate it, and follow the setup wizard to connect your Google Analytics account. The plugin handles injecting the tracking code on every page automatically. This is the easiest method and works well for beginners.

The second approach is adding the GA4 tracking code manually. Log into your Google Analytics account, go to Admin → Data Streams, select your web stream, and copy the gtag.js snippet. Then add it to your WordPress site's header — either by editing your theme's header.php file directly, using a child theme, or using a plugin like WPCode to inject the snippet into the head section of every page. The manual method gives you more control and avoids adding another plugin to your site.

Pros. GA4 is free and extraordinarily powerful. It tracks pageviews, events, user journeys, conversions, e-commerce transactions, and much more. It integrates natively with Google Ads, Google Search Console, and BigQuery. The depth of data available is unmatched by any other free tool. If you need advanced segmentation, custom reports, funnel analysis, or audience building for ad retargeting, GA4 is the standard.

Cons. GA4 is complex. The learning curve is steep, especially if you are coming from Universal Analytics or have never used an analytics tool before. The interface is cluttered and unintuitive for many users. Reports that used to be simple in Universal Analytics now require custom explorations. GA4 also uses cookies, which means you need a cookie consent banner in the EU under GDPR — and if visitors decline cookies, you lose their data entirely. The tracking script is relatively heavy (around 28 KB gzipped), and it makes multiple network requests on every page load, which can measurably slow down your site. Google also uses the data it collects to improve its advertising products, which raises privacy concerns for visitors who are increasingly wary of being tracked across the web.

Option 2: Lightweight analytics tools

In recent years, a category of analytics tools has emerged that takes a fundamentally different approach: instead of tracking everything about every visitor, they focus on the essential metrics — pageviews, referrers, top pages, countries, devices — without using cookies or collecting personal data. These tools include sourcebeam, Plausible, Fathom, and Simple Analytics.

How to add lightweight analytics to WordPress. The setup for all of these tools is similar: you get a small script tag from the provider and add it to the head section of your WordPress site. For example, with sourcebeam, you sign up, add your domain, and receive a single script tag that looks something like <script defer src="https://sourcebeam.io/sb.js" data-domain="yourdomain.com"></script>. You add this to your site using one of the methods described later in this guide (manual header edit, a plugin like WPCode, or Google Tag Manager). That is the entire setup. There is no configuration wizard, no account linking, no consent mode setup.

Pros. Lightweight analytics tools are simple to understand. Their dashboards show you the key metrics on a single page, without requiring you to build custom reports or navigate a complex interface. They are fast — most use a script under 1 KB that makes a single network request, adding virtually zero load time to your pages. They do not use cookies, which means you do not need a cookie consent banner for analytics purposes. They are privacy-friendly by design, which matters both ethically and legally. And they are usually much cheaper to run than a Google Analytics setup once you factor in the time spent learning, configuring, and maintaining GA4.

Cons. You get less granular data than GA4. There are no user-level session recordings, no advanced funnel analysis, no custom audience building for ad retargeting. If you need to know exactly which individual user clicked which button in which order over three sessions before converting, lightweight tools will not give you that. For most WordPress sites — blogs, small business sites, portfolios, WooCommerce stores — the data they provide is more than enough. But if you are running a large-scale e-commerce operation or spending serious money on paid advertising, you may need GA4 in addition to a lightweight tool.

Option 3: WordPress analytics plugins

WordPress has its own ecosystem of analytics plugins that display traffic data directly inside your WordPress dashboard. The most popular ones include Jetpack Stats (from Automattic, the company behind WordPress.com), MonsterInsights (which connects to Google Analytics and shows reports in your dashboard), and WP Statistics (which tracks visitors using server-side logging without external services).

Pros. These plugins are easy to install — you search for them in the WordPress plugin directory, click Install, click Activate, and you have analytics without leaving your WordPress admin panel. Jetpack Stats works out of the box with no external account needed. MonsterInsights makes GA4 data accessible to people who find the GA4 interface overwhelming. WP Statistics keeps all data on your own server, which is appealing from a privacy perspective. The convenience of seeing your analytics data right next to your posts and pages is genuinely nice.

Cons. Plugin bloat is the biggest concern. WordPress sites tend to accumulate plugins over time, and each one adds weight — more database queries, more PHP execution time, more potential security vulnerabilities, more things that can break during updates. Jetpack in particular is notorious for being a heavy plugin that does many things, analytics being just one of them. MonsterInsights adds a layer on top of GA4 but does not replace it — you still need a GA4 account, and the plugin can slow down your admin dashboard. WP Statistics stores tracking data in your WordPress database, which can grow very large over time and slow down your site. The data from these plugins is also generally less accurate and less detailed than what you get from dedicated analytics tools.

Method A: Adding a script tag manually

This method works for any analytics tool that gives you a JavaScript snippet to add to your site. It is the most direct approach and does not require any additional plugins.

Using a child theme. If you are editing theme files, you should always use a child theme. A child theme inherits everything from your parent theme but lets you override specific files without losing your changes when the parent theme updates. If you do not already have a child theme, you can create one by making a new folder in wp-content/themes/ with a style.css file that references the parent theme, and a functions.php file. In your child theme's functions.php, add your analytics script using the wp_head hook:

Open functions.php and add a function that hooks into wp_head. Inside that function, echo your analytics script tag. For example, you would write a function called add_analytics_script, and inside it you echo the script tag provided by your analytics tool. Then you call add_action('wp_head', 'add_analytics_script') to tell WordPress to run that function when it outputs the head section of every page.

Using Appearance → Theme Editor. WordPress has a built-in file editor at Appearance → Theme File Editor. You can select your theme's header.php file and paste your analytics script tag just before the closing </head> tag. This works, but it has a major downside: your changes will be overwritten the next time you update your theme. This is why the child theme approach or a plugin approach is preferred. If you use this method, keep a backup of your analytics code somewhere so you can re-add it after theme updates.

Important placement note. Your analytics script should go in the <head> section of your HTML, not in the footer. Placing it in the head ensures the script loads early and captures the pageview even if the visitor leaves before the page fully loads. If you put it in the footer, you will miss visitors who bounce quickly. Most analytics scripts use the defer or async attribute, so they will not block your page from rendering even though they are in the head.

Method B: Using a plugin to add header scripts

If you do not want to edit theme files, the easiest approach is using a lightweight plugin designed specifically for adding code snippets to your site's header and footer. The two most popular options are WPCode (formerly Insert Headers and Footers) and the older Insert Headers and Footers plugin by WPBeginner.

Step-by-step with WPCode. Go to Plugins → Add New in your WordPress dashboard. Search for "WPCode" and install the free version. Activate it. Navigate to Code Snippets → Header & Footer in the left sidebar. Paste your analytics script tag into the "Header" section. Click Save Changes. That is it. The plugin will inject your code into the head section of every page on your site, and it will survive theme updates because it is not tied to your theme files.

This is the method we recommend for most WordPress users. It takes about two minutes, it does not require any technical knowledge, and the WPCode plugin is lightweight enough that it will not noticeably affect your site performance. It also gives you a centralized place to manage all your header scripts — analytics, meta verification tags, custom CSS — without touching theme files.

After adding the script, verify it is working by visiting your site in an incognito browser window and checking your analytics dashboard for the visit. If the visit does not appear within a minute or two, check that you pasted the full script tag and that there are no errors in the browser console (right-click → Inspect → Console tab).

Method C: Using Google Tag Manager

Google Tag Manager (GTM) is a free tool that lets you manage all your tracking scripts from a single web-based interface. Instead of adding individual script tags to your WordPress site, you add the GTM container code once, and then manage everything else — analytics, conversion tracking, remarketing pixels, heatmap tools — through the GTM dashboard.

How to set it up. Create a free Google Tag Manager account at tagmanager.google.com. Create a container for your website. GTM will give you two code snippets — one for the head and one for the body. Add these to your WordPress site using any of the methods above (child theme, WPCode, or theme editor). Once the GTM container is on your site, log into GTM and create a new tag for your analytics tool. For GA4, choose the built-in GA4 Configuration tag type. For other tools like sourcebeam, create a Custom HTML tag and paste the script tag. Set the trigger to "All Pages" and publish your container.

When GTM makes sense. GTM is overkill for a simple WordPress blog that only needs basic analytics. Where it shines is when you have multiple tracking scripts — analytics, Facebook Pixel, Google Ads conversion tracking, a heatmap tool, a chatbot widget — and you want to manage them all from one place without touching your WordPress files every time you need to add, remove, or update a script. GTM also offers powerful triggering rules: you can fire tags only on specific pages, only when certain buttons are clicked, or only for visitors from certain countries.

The downside. GTM adds its own JavaScript to your site, which adds load time on top of whatever scripts you are managing through it. The GTM interface has a learning curve, and misconfigured tags can lead to double-counting, missing data, or unintended tracking. If you only need one analytics tool on your WordPress site, skip GTM and add the script directly — it is faster, simpler, and lighter.

What to look for after installing analytics

You have installed analytics on your WordPress site. Now what? The first few days of data are the most exciting — and the most confusing if you do not know what to focus on. Here is what to check first.

First visitors. Open your analytics dashboard and confirm that visits are being recorded. Visit your own site in an incognito window and check that the pageview appears. If you see data, your setup is working. If you do not, re-check your script placement and look for errors in the browser console.

Traffic sources. Your referrer or source report tells you where your visitors are coming from. Direct traffic means they typed your URL or used a bookmark. Organic search means they found you through Google or another search engine. Referral traffic means they clicked a link from another website. Social traffic comes from social media platforms. Understanding your traffic mix tells you which channels are already working and which ones need attention.

Top pages. Your pages report shows which pages get the most visits. This is often surprising — the page you spent the most time on might not be your most popular one. Look at what is actually getting traffic and ask why. Is it ranking well in search? Was it shared on social media? Is it linked from a high-traffic external site? Your top pages tell you what your audience cares about, which should influence what you create next.

Bounce rate and time on page. These metrics tell you whether visitors are engaging with your content or leaving immediately. A high bounce rate on a blog post is not always bad — the visitor might have found exactly what they needed and left satisfied. But a high bounce rate on a product page or landing page suggests something is wrong: the content does not match the visitor's expectation, the page loads too slowly, or the next step is not clear.

Performance impact: how analytics tools affect your site speed

Every script you add to your WordPress site has a performance cost. The question is how much — and whether that cost is worth paying. Not all analytics tools are created equal when it comes to page speed.

Google Analytics (GA4) loads a JavaScript file of roughly 28 KB (gzipped) and makes several network requests to Google's servers on every page load. It also sets cookies, which adds to the request size for subsequent page loads. On a well-optimized WordPress site, GA4 typically adds 50-100 milliseconds to your page load time. That might not sound like much, but it compounds with every other script on your page — and WordPress sites tend to accumulate many scripts.

Lightweight analytics tools are dramatically smaller. Most are under 1 KB of JavaScript, make a single network request, and set no cookies. The performance impact is essentially unmeasurable — usually under 5 milliseconds. For WordPress sites where speed is already a challenge (shared hosting, heavy themes, many plugins), the difference between a 28 KB analytics script and a 1 KB one can be the difference between passing and failing Core Web Vitals.

WordPress analytics plugins add their own overhead beyond the tracking script. They load additional PHP on the server side, add database queries, and often include admin dashboard widgets that slow down your WordPress backend. Jetpack in particular is known for adding measurable load time to both the frontend and backend of WordPress sites.

If performance matters to you — and it should, because Google uses Core Web Vitals as a ranking factor — speed up your website and choose the lightest analytics option that gives you the data you need. For most WordPress sites, that means a lightweight script-based analytics tool rather than a heavy plugin or GA4.

Privacy considerations: cookies, consent banners, and GDPR

If your WordPress site has visitors from the European Union — and it almost certainly does — you need to think about GDPR compliance. The General Data Protection Regulation requires that you get explicit consent before setting non-essential cookies or collecting personal data. The penalties for non-compliance are severe: up to 4% of annual global revenue or 20 million euros, whichever is higher.

Google Analytics uses cookies to track visitors across sessions. Under GDPR, this means you need a cookie consent banner that asks visitors for permission before GA4 loads. If they decline — and many do — you get no data for that visit. Some studies suggest that 30-50% of European visitors decline cookie consent, which means your GA4 data significantly undercounts your actual traffic from the EU.

Lightweight analytics tools that do not use cookies sidestep this issue entirely. If your analytics tool does not set cookies and does not collect personal data (like IP addresses or device fingerprints), you do not need a consent banner for analytics purposes under GDPR. This is not a loophole — it is the intended design. The regulation targets tools that track individuals, not tools that count pageviews anonymously. Tools like sourcebeam, Plausible, and Fathom are designed specifically to work this way.

Beyond GDPR, consider the California Consumer Privacy Act (CCPA) and other regional privacy laws. The trend worldwide is toward stronger privacy regulations, not weaker ones. Choosing a privacy-friendly analytics tool now means you are less likely to need to change your setup when the next regulation arrives.

If you do use cookies on your WordPress site for any reason — Google Analytics, advertising pixels, personalization — use a consent management plugin like CookieYes, Complianz, or Cookie Notice to present a GDPR-compliant banner. Make sure the banner actually blocks tracking scripts until consent is given, not just displays a notice.

Setting up goals and conversion tracking on WordPress

Pageview data tells you who is visiting. Conversion tracking tells you who is taking action. For most WordPress sites, there are a few key conversions to track: contact form submissions, email signups, account registrations, and purchases.

Contact form submissions. The simplest way to track contact form conversions is to redirect users to a thank-you page after submission. Set up your form plugin (Contact Form 7, WPForms, Gravity Forms) to redirect to /thank-you/ after a successful submission. Then set up a goal in your analytics tool that fires when someone visits that thank-you page. In GA4, create an event for page_view where the page_location contains "/thank-you/" and mark it as a conversion. In lightweight tools, you can usually track conversions by URL destination.

Email signups. Similar approach — redirect to a confirmation page after signup and track visits to that page as conversions. If your email tool (Mailchimp, ConvertKit, etc.) uses an embedded form, configure it to show a success message on a specific URL rather than an inline confirmation.

WooCommerce purchases. WooCommerce has a built-in order-received page that customers see after completing a purchase. You can track visits to this page as purchase conversions. For revenue tracking, GA4 with the WooCommerce integration (via MonsterInsights or a dedicated plugin) can pass the purchase amount and product details as event parameters. Some lightweight analytics tools also support revenue tracking — for example, if you connect Stripe, tools like sourcebeam can automatically attribute revenue to the pages that drove conversions.

The key principle is the same regardless of your analytics tool: define what a successful action looks like, create a measurable event or destination for it, and configure your analytics to count it. Do this before you start driving traffic to your site, not after — you cannot measure conversions retroactively.

WooCommerce-specific: tracking revenue and product analytics

If you run an online store with WooCommerce, analytics is not just about pageviews — it is about revenue. You need to know which products sell best, which pages drive the most purchases, what your average order value is, and where customers abandon the buying process.

Enhanced e-commerce in GA4. GA4 has built-in e-commerce tracking that can record product impressions, add-to-cart events, checkout steps, and completed purchases with full product and revenue details. Setting this up manually on WooCommerce is complex — it requires pushing a data layer with product information on each relevant page. Plugins like MonsterInsights or GTM4WP automate this integration. Once configured, you can see reports like which products generate the most revenue, what your cart abandonment rate is, and which traffic sources produce the highest average order value.

Revenue attribution. One of the most valuable things analytics can tell a WooCommerce store owner is which marketing efforts actually drive revenue. This goes beyond knowing which pages get traffic — it connects the dots between a visitor's first interaction with your site and their eventual purchase. Did they come from a Google search? A Facebook ad? A blog post? If you use UTM parameters consistently on your marketing links, your analytics tool can attribute revenue to specific campaigns and channels.

Product page performance. Not all product pages perform equally. Some convert visitors into buyers at a high rate; others get plenty of traffic but few purchases. Use your analytics to identify underperforming product pages and investigate why. Is the product description unclear? Are the images poor? Is the price too high? Is the add-to-cart button hard to find on mobile? Analytics gives you the data; you have to do the detective work.

Checkout funnel analysis. WooCommerce has a multi-step checkout process: add to cart, view cart, enter billing details, complete purchase. Visitors drop off at every step. Knowing where the biggest drop-off happens tells you where to focus your optimization efforts. If most people abandon at the billing page, maybe your shipping costs are too high or you are asking for too much information. If they abandon at the cart page, maybe the total is higher than expected. GA4's funnel exploration report and some dedicated WooCommerce analytics plugins can visualize this for you.

Common WordPress analytics mistakes

After helping thousands of WordPress site owners set up analytics, certain mistakes come up again and again. Avoiding these will save you time and give you more reliable data.

Too many analytics plugins. Some WordPress users install multiple analytics tools and plugins simultaneously — Jetpack Stats, MonsterInsights, a GA4 snippet, and a standalone analytics script. Each one adds weight to your page, and having multiple tracking scripts can cause double-counting or conflicting data. Pick one analytics approach and commit to it. If you want GA4 data, use GA4. If you want lightweight analytics, use a lightweight tool. Do not run three tools "just in case."

Not checking the data. Installing analytics is only useful if you actually look at the data. Many WordPress site owners install Google Analytics, feel good about having it, and then never log in again. Set a recurring reminder — weekly or monthly — to review your analytics. Look at traffic trends, top pages, traffic sources, and conversion rates. If you are not going to check it, there is no point in slowing down your site with the tracking script.

Wrong tracking code placement. Placing the analytics script in the footer instead of the header means you miss visitors who leave before the page fully loads. Adding the script to only some pages (like only the homepage) means you have blind spots in your data. Using a page builder that does not include the header on certain templates means those pages are untracked. Always verify that your analytics script is present on every page by visiting different page types and checking the source code.

Not filtering out your own traffic. If you work on your WordPress site frequently, your own visits can skew the data significantly — especially on low-traffic sites. Most analytics tools let you filter out traffic from specific IP addresses or use a browser extension to exclude yourself. Set this up early so your analytics reflects real visitor behavior, not your own browsing.

Losing data during theme or plugin updates. If you added your analytics code directly to your theme's header.php file (instead of using a child theme or a plugin), a theme update will overwrite your changes and silently stop tracking. You might not notice for weeks. Always use a method that survives updates: a child theme, a header/footer plugin like WPCode, or a dedicated analytics plugin.

A recommended analytics stack for WordPress

After weighing all the options, here is the analytics stack we recommend for most WordPress sites. It gives you comprehensive data without sacrificing performance, privacy, or your sanity.

1. A lightweight analytics tool for traffic data. Use sourcebeam, Plausible, Fathom, or Simple Analytics as your primary analytics tool. Add the script tag via WPCode and you are done. You get real-time traffic data, referrer information, top pages, geographic data, and device breakdowns — all without cookies, consent banners, or performance penalties. This covers 90% of what most WordPress site owners need from analytics.

2. Google Search Console for SEO data. Search Console is free, does not require any script on your site (it uses your sitemap and DNS verification), and gives you data that no analytics tool can provide: which Google search queries bring visitors to your site, your average position for each query, your click-through rate, and any indexing issues. Every WordPress site should be connected to Search Console, regardless of what other analytics tools you use. There is no performance cost and no privacy concern because the data comes from Google's side, not from tracking your visitors.

3. PageSpeed Insights for performance monitoring. Run your key pages through PageSpeed Insights periodically — at least monthly, and after any major change to your site. This is not analytics in the traditional sense, but it is essential data about your WordPress site's health. WordPress sites are particularly prone to performance degradation as themes get updated, plugins accumulate, and content grows. PageSpeed Insights gives you a clear score and specific recommendations for improvement.

This three-tool stack is free or very affordable, lightweight, privacy-friendly, and covers all the data you need: who is visiting (analytics), how they found you (Search Console), and whether your site is fast enough to keep them (PageSpeed Insights). You can always add GA4 later if you need advanced features, but start here. Most WordPress site owners will find this stack is all they ever need.

sourcebeam makes WordPress analytics effortless — one script tag, no cookies, no consent banners. Try it free on your WordPress site