How to Add Google Analytics Code in Divi Theme
Connecting Google Analytics to your Divi website is one of the most important steps you can take to understand your audience and grow your traffic. Without data, you’re just guessing. This guide will walk you through several simple methods to add Google Analytics to Divi, from a simple copy-and-paste to more advanced techniques for complete tracking control.
Why You Need Website Analytics in the First Place
Before jumping into the "how," it's helpful to understand the "why." Adding Google Analytics is more than just a box-ticking exercise, it gives you the data you need to make smarter decisions about your website and business. When you have analytics properly set up, you unlock a wealth of information.
- Understand Your Audience: Learn where your visitors are coming from (geographically and online), what devices they use (mobile vs. desktop), and their general demographics like age and gender. This helps you tailor your content and design to better fit your ideal visitor.
- Track Marketing Performance: See which channels are driving the most traffic. Is it organic search, social media, email campaigns, or paid ads? Analytics shows you what’s working so you can double down on your most effective marketing efforts.
- Identify Popular Content: Discover which pages and blog posts are getting the most traffic, clicks, and engagement. This helps you figure out what topics resonate with your audience so you can create more of what they love.
- Optimize Your Website: Learn how users navigate your site. Are they finding what they need? Which pages do they exit from most often? This data helps you identify bottlenecks and opportunities to improve the user experience and increase conversions.
- Measure Conversions and Goals: Set up custom "goals" to track important actions like form submissions, phone number clicks, or a visitor landing on your thank-you page. This turns vague traffic numbers into measurable business results.
In short, data from Google Analytics empowers you to stop guessing and start making strategic, data-driven decisions that grow your website, improve user engagement, and increase sales.
First, Find Your Google Analytics Code (Measurement ID)
To connect your Divi site to Google Analytics 4, you'll need one of two things: your Measurement ID or your full tracking script (also known as the Global Site Tag or gtag.js). For most of the methods below, the full script is the easiest to use.
Here’s how to find it step by step:
- Log into your Google Analytics account.
- Click the Admin gear icon in the bottom-left corner.
- In the Property column, make sure your correct GA4 property is selected. If not, use the dropdown to select it.
- Under the Property column, click on Data Streams.
- Select the appropriate web data stream for your website (most accounts will only have one).
- In the "Web stream details" panel, look for the section titled "View tag instructions" at the bottom. Click on it.
- A new screen will pop up. Make sure the “Install with a website builder or CMS” tab is selected, and click the down-arrow next to "Install manually", where it will say "Install your Google tag manually to monitor visitor activity on one website". Go there.
- Here you will see your entire JavaScript tracking code. This is your Global Site Tag (gtag.js). This snippet is what you'll copy and paste into Divi.
Your code will look 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>`
Just click the copy icon on the top right to get the whole thing. Now that you have the tracking code, let's explore the best ways to add it to your Divi theme.
Method 1: Use Divi's Built-in Integration (The Easiest Way)
Elegant Themes makes it incredibly easy to add scripts like the Google Analytics tag directly within the Divi theme options. This is the simplest, quickest, and most reliable method for most users because it doesn't require extra plugins and is safe from being overwritten during theme updates.
Follow these steps:
- From your WordPress dashboard, navigate to Divi > Theme Options.
- You'll be taken to the General settings tab. Click the Integration tab at the top.
- You will see several code boxes. Find the one labeled "Add code to the <head> of your blog".
- Make sure the slider next to this field is enabled (it should be green).
- Paste your entire Global Site Tag (gtag.js) script into this box. This ensures the script loads on every page of your website, which is exactly what Google requires for tracking.
- Scroll down and click the big green Save Changes button.
That's it! Divi will now automatically inject your Google Analytics code into the <head> section of every page on your site. This method is beautiful in its simplicity and is the recommended approach if your only goal is to add the standard GA4 tracking script.
Method 2: Using a WordPress Plugin (Great for More Features)
If you prefer using a plugin or want additional analytics features directly within your WordPress dashboard, this method is for you. A plugin can make the setup slightly easier by authorizing your Google account and often provides reports without you having to leave your site.
Let's use Site Kit by Google, as it's the official plugin from Google itself.
Here's how to set it up:
- In your WordPress dashboard, go to Plugins > Add New.
- In the search bar, type “Site Kit by Google” and press Enter.
- Find the official plugin in the search results and click Install Now, then click Activate.
- Once activated, you’ll see a prompt to begin the setup. Click the “Start Setup” button.
- You'll be guided through an authorization process. You'll sign in with the Google account associated with your Analytics property.
- Follow the on-screen prompts to grant Site Kit access to your Analytics data. It will automatically detect your GA4 property.
- Once connected, Site Kit will not only add the tracking code to your site for you but also pull key analytics data directly into your WordPress dashboard.
The main benefit of a plugin is the convenience of seeing top-level metrics without logging into Google Analytics. However, the downside is that it adds another plugin to your site that you'll need to keep updated, and it can add a little bit of performance overhead.
Method 3: Install via Google Tag Manager (The Advanced & Scalable Way)
This method is for marketers, agencies, or website owners who plan to use more than just Google Analytics. Google Tag Manager (GTM) is a separate free tool that acts as a central hub (or "container") for all your tracking scripts—like the Facebook Pixel, LinkedIn Insight Tag, and more.
Instead of adding many different scripts directly to your site, you just add the GTM script one time. Then, you manage all your other tags from the Google Tag Manager interface. This keeps your site's code cleaner and makes it easier to add, edit, or remove tracking scripts without ever touching Divi's code again.
Here's a high-level overview:
- Sign up for a free Google Tag Manager account and create a container for your website if you haven't already.
- GTM will provide you with two code snippets: one for the
<head>, and one for the<body>of your website. - Copy the first snippet (the one for the
<head>). Go back to your Divi Theme Options: Divi > Theme Options > Integration. Paste it into the box labeled "Add code to the <head> of your blog", just as you would with the standard GA tag in Method 1. - Copy the second GTM snippet (for the
<body>section). Paste it into the box labeled "Add code to the <body>" in the same Integration tab. - Click Save Changes.
Now, with GTM installed on your Divi site, you need to add your Google Analytics tag inside Tag Manager:
- In your Google Tag Manager dashboard, go to Tags > New.
- Name your tag something clear, like "GA4 - Base Tag."
- Click on the Tag Configuration box and choose Google Analytics: GA4 Configuration.
- You'll be asked for your Measurement ID (G-XXXXXXXXXX). Paste it in.
- Next, click the Triggering box. Choose the trigger named All Pages. This ensures your GA tag fires on every page load.
- Click Save.
- Finally, in the top-right corner of your GTM dashboard, click the big blue Submit button, then Publish to push your changes live.
While this method involves more initial setup, it's the professional standard for managing multiple scripts and is the most flexible and powerful solution in the long run.
How to Verify That Google Analytics Is Working
After implementing any of the methods above, it's essential to confirm that your tracking code is firing correctly. The quickest way to do this is with GA4’s Realtime monitoring.
- Open your website in a new incognito browser window (using incognito mode prevents you from being logged into WordPress, which would likely exclude your visit from tracking).
- In your Google Analytics account, navigate to the Reports tab on the left-hand menu.
- In the Reports navigation, click on Realtime.
- Give it a minute. You should see "1" appear in the "Users in Last 30 Minutes" card, and your geographic location should appear on the map.
If you see your visit registered, congratulations! You have successfully installed Google Analytics on your Divi theme.
Final Thoughts
Connecting Google Analytics to your Divi site is a fundamental step toward understanding your visitors and making informed decisions. Whether you choose the direct Divi integration, a helpful plugin like Site Kit, or the more powerful Google Tag Manager, each method will successfully get your data flowing.
Once you have all that rich data flowing from your website into Google Analytics, the next challenge is turning it into actionable insights without spending hours digging through reports. We built Graphed to solve this exact problem. By connecting your Google Analytics account, you can simply ask questions in plain English—like "Which blog posts are driving the most traffic this month?"—and get instant dashboards and reports, saving you from the manual work of building them yourself.
Related Articles
How to Connect Facebook to Google Data Studio: The Complete Guide for 2026
Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.
Appsflyer vs Mixpanel: Complete 2026 Comparison Guide
The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.
DashThis vs AgencyAnalytics: The Ultimate Comparison Guide for Marketing Agencies
When it comes to choosing the right marketing reporting platform, agencies often find themselves torn between two industry leaders: DashThis and AgencyAnalytics. Both platforms promise to streamline reporting, save time, and impress clients with stunning visualizations. But which one truly delivers on these promises?