How to Add Google Analytics to WordPress (With & Without Plugin)

How to Set Up Google Analytics in WordPress

Are you looking for a convenient way of setting up Google Analytics in WordPress?

One of the most powerful weapons you have as a WordPress site owner is analytics. You can use its data and patterns to make more informed decisions and help you understand your audience better. 

As such, Google Analytics presents one of the best ways to get data insight, such as site performance, user behavior, and traffic patterns.   

In this article, we will look at the best ways to set up Google Analytics in WordPress.

Ways to Integrate Google Analytics with WordPress 

As a site owner, you should always have access to reliable and up-to-date data to run your site efficiently.

Each metric offered by Google Analytics can be analyzed to help you understand your past and present data, allowing you to forecast your future site performance.

These metrics include:

  • Number of site visits
  • Where the visitors came from
  • What they did do while on your site
  • How long they stayed on your site
  • How many pages they visit 
  • What part of the page they stay on the longest
  • Site speed analysis 
  • And so much more.

Other than these, here are additional and interesting ways you can use Google Analytics:

  • Check how users switch between devices and platforms when interacting with your brand
  • Check paths users take on your site and identify drop-off points
  • Set up alerts to notify you of significant changes in your website’s metrics

As you can see, Google Analytics offers a lot of data which can quickly become confusing even for seasoned users.

To add to this, Google Analytics is a standalone platform that can be hard to set up because it requires coding experience. You also need to add a tracking ID to your site code and carry out other processes to implement it fully.

A small mistake could lead to improper tracking or your site breaking.

That is why adding Google Analytics directly to your WordPress dashboard is more convenient and the perfect solution. It ensures that you collect all the information about your site from your website WordPress dashboard, never needing to leave your backend.

There are 3 main ways you can add Google Analytics to your WordPress site:

Use the links above to skip to the method you want to use.

Adding Google Analytics through MonsterInsights and WPCode requires the use of a plugin. Using plugins to add Google Analytics is a quicker, more user-friendly approach that needs no coding experience. 

On the other hand, adding Google Analytics to your site through your theme is a manual approach. Even though it is a cost-effective solution, it requires coding experience, which can result in human error, code misplacement, or breaking your site. 

We recommend you take the plugin approach even if you have coding experience, as it can help you avoid any data-tracking problems.

Adding Google Analytics through MonsterInsights


MonsterInsights is the best plugin to add Google Analytics to WordPress. It is an easy-to-use plugin that transforms complex data into actionable, practical, easy-to-understand insights.

Its advanced features can help you better track specific site aspects like click-through rates, conversion rates, and popular content. You can do all this without complex processes, coding experience, and extra steps like Google Tag Manager, Google Site Tag, and child themes.

It is the easiest way by far to handle the technical Google Analytics setup process without worrying about breaking your site or placing the tracking ID at the wrong location.

MonsterInsights is a highly customizable plugin that lets you personalize the metrics you want from Google Analytics into an easy-to-understand structure and language. 

For these reasons, MonsterInsights is the best way of adding Google Analytics to your site. 

Check out our in-depth MonsterInsights review here.

Step 1: Sign Up for Google Analytics

To get started with adding Google Analytics with MonsterInsights, you will need a Google account. If you do not have one, simply sign up for one. It’s free.

Next, open the Google Analytics site and proceed to the Get Started Today button. 

google analytics wordpress signup

Sign in to Google Analytics with your Google account and find the Start Measuring button. 

google analytics wordpress start measuring

Next, create an account name for the site you want to track. 

google analytics wordpress account name

You can add multiple tracking IDs to the same Google Analytics account, allowing you to monitor all your sites in the same spot. This ensures everything is streamlined, reducing confusion and double work. 

On the pop-up window that will display, check the permissions you want to give Google Analytics and proceed to Next.

google analytics wordpress permissions

On the next screen, you will add Property Details. A property can be a site or an app you want to track. Enter the property name, time zone, and currency, and proceed to the Next page. 

google analytics wordpress property details

The next step is to provide details about your business. On this page, you will add your industry category and business size.

On the next window, tell Google Analytics how you intend to use the platform. Check the objectives boxes applicable to you and proceed to Create.

google analytics wordpress create ga

A new popup will appear where you can review the information and check the terms and conditions box before you hit the ‘I Accept’ button.

With the property details filled out, it is time to create a Data Stream for your property. Since the property we want to track is a WordPress website, we will go with “Web.” 

google analytics wordpress choose platform

On the next page, add the site’s name and URL. Then, if you want, enable Enhanced Measurements to automatically monitor content elements and interactions. 

google analytics wordpress set up stream

Identify the metrics you want to measure automatically in the settings tab on the far left. Then, select Create to proceed to the next page.

google analytics wordpress enhanced measures

At this point, you should have entirely created a property. You will receive a unique tracking code to add to your website. 

Copy this code; you will need it in the next step.

To find your tracking code in the future, simply go to Admin » Property » Data Streams. Select the data stream you want, and you should see the Measurement ID at the far right after the Stream Name, Stream URL, and Stream ID. 

google analytics wordpress stream

With that, you have successfully created a Google Analytics property and its tracking code. 

Step 2: Set Up MonsterInsights

With everything set in the Google Analytics dashboard, head over to your WordPress dashboard to set up MonsterInsights. 

Go to Plugins » Add New. In the plugin repository, search for “MonsterInsights.” Next, install the plugin and activate it. 

If you want to know more about this, check out our tutorial on how to install a plugin.

monsterinsights free install

Even though the free version of MonsterInsights helps you add Google Analytics to your WordPress dashboard, consider getting MonsterInsights Pro from the plugin’s official site for advanced features. 

MonsterInsights Pro can be particularly useful for eCommerce, offering advanced metric measuring tools such as headline analyzers, coupon reports, conversion tracking forms, and user journeys.  

Step 3: Connect MonsterInsights to Google Analytics

Once the plugin is installed and activated successfully, MonsterInsights will automatically direct you to launch the setup wizard. The setup wizard offers a simple line progress bar to help you follow these simple steps. 

monsterinsights launch wizard

Alternatively, you can access the same setup wizard by going to the Insights menu in your WordPress dashboard. Next, head over to Settings and proceed to the ‘General’ tab. Scroll until you find the Launch Setup Wizard button.

monsterinsights alt setup wizard

On the first page of the setup wizard, select a category. Then, hit the Connect MonsterInsights button and let it authenticate. 

monsterinsights connect

Add the Google account you signed up for with Google Analytics and then grant MonsterInsights permissions. 

monsterinsights grant permissions

To Complete Connection, simply pick the property you want to connect.

monsterinsights complete connection

Next, fill out all the required information on the ‘Recommended Setting’ screen, then Save and Continue.

After the plugin completes the setup process, it will redirect you to the Insights WordPress menu. Select the Reports submenu to check out your site insights.

The dashboard uses a tab system to ensure you can easily compare different metrics. 

The metric reports are structured systematically and include the following: 

  • Overview
  • Traffic
  • Publishers
  • Search Console
  • eCommerce
  • Dimensions
  • Forms
  • Realtime
  • Site Speed

For example, on the Publishers tab, you can check default metrics like page views, bounce rate, engaged sessions, and new sessions. You can customize this report to show an exact time period to identify moments of traffic surges or drops. 

monsterinsights report

Further down the page, you can also see more specific data, including Interests and scrolls. The View Full Interests report is a great way to improve your content and understand your audience better. 

average scroll depth

But that is not all you can do with MonsterInsights. Let’s go through the various ways, features, and settings you can use this plugin. 

Step 4: Customize insights with MonsterInsights

Site owners, niches, and industries have different priorities when it comes to reports and metrics. By personalizing your data and making custom reports with MonsterInsights, you can always measure the most relevant metrics to you with ease. 

This makes aligning your goals with your data easier, leading to better decision-making and forecasting. 

MonsterInsights makes it easy to create such custom reports. All these settings can be placed through the setup wizard during the initial configuration. However, to do it manually, go to the Insights menu on WordPress and then visit the Settings submenu. Then scroll to find Launch Setup Wizard and select.

Here you can set up the following configurations:

  • Affiliate link tracking: Even though most affiliate links come with tracking capabilities from the affiliate partner, using MonsterInsights gives you access to your own data. This way, you do not rely on what the report from the affiliate says. You can also compare the report from MonsterInsights and the affiliate easily. 
  • Access control: This feature is especially great if you have a big team. You can easily control who sees your insights by granting specific access to individuals.
  • Automatic Plugin Updates: MonsterInsights carries out updates often to incorporate new features and improve the plugin. Set up automatic plugin updates to ensure you never miss anything. 
  • Enhanced Link Attribution: This feature offers the best way of seeing how users interacted with your links. Identify which links are most clicked on, such as the image, anchor, or title links. Enhanced Link Attribution offers a great way to track event links as well. 
  • 20+ Advanced Tracking: MonsterInsights offers easy-to-use but advanced tracking capabilities such as form tracking, scroll tracking, author tracking, file download tracking, category and tag tracking, and logged-in user tracking. 
  • All in One SEO Toolkit integration: All in One SEO is the best SEO plugin. Its integration with MonsterInsights gives you the best SEO insight, such as keyword tracking, on-page SEO insights, and an SEO score. 
  • eCommerce Tracking: You can track revenue, sales, product performance, shopping cart abandonment, track referral sources, conversion rate, and more. 
  • Advanced Growth Tools: MonsterInsights has several advanced growth tools you can use. Create Custom URLs with set parameters to specifically track the effectiveness of your marketing efforts. The Popular Posts addon highlights your most popular content by creating a list and prominently featuring these top-performing blog posts on your site. Another great feature is A/B testing. It involves comparing two web page versions to determine which performs better in terms of user engagement or conversion rates.
  • Privacy Compliance Addon: This ensures Google Analytics is compliant with GDPR and CCPA.
monsterinsights customization

While these features may seem complicated because of the advanced functionality and customization they offer, MonsterInsights makes it incredibly easy to set up. All you have to do is check the box next to the advanced feature and hit Continue when done. 

monsterinsights confirm customization

That’s it! You have successfully added Google Analytics to your WordPress dashboard. Now, you can get in-depth insights in a simpler, personalized way without ever leaving your WordPress dashboard. 

Adding Google Analytics Through WPCode

WPCode is designed to simplify and manage custom code snippets, reducing reliance on plugins and inevitably reducing site bloating. 

But first, go to your Google Analytics dashboard and select Go To Data Streams. Select the data stream you want and hit View Tag Instructions.

Here, copy the code under the Install Manually tab. 

google analytics manual code

Now, back on your WordPress dashboard, install and activate the WPCode plugin through the plugin repository in your WordPress dashboard.

wpcode install

Go to Code Snippets » Headers & Footers in your WordPress dashboard. 

Next, in the Header section, paste the tracking code you copied earlier.

wpcode header footer

Make sure you hit the Save Changes button and that’s it.

Next, we’ll show you how to connect WordPress to Google Analytics manually without any plugin.

Adding Google Analytics to Your WordPress Theme

It is possible to add the Google Analytics tracking code to the header or footer of the site’s theme without a plugin’s help. 

However, we do not recommend this method. The smallest misstep can cause your entire site to crash or malfunction. Added to that, you may need to update the code if you change the theme or carry out any major updates to your site. 

You may also need to debug tracking issues and constantly check site performance, making it hard to scale. Furthermore, changing the theme code can present a security risk.

With these disclaimers out of the way, there are 3 ways to add the Google Analytics tracking code to your theme. 

  • Add tracking code through the Header.php file
  • Add tracking code through the Footer.php file 
  • Add tracking code through the Functions.php file

Add Code Through The Header.PHP File

You will need to access your files through your cPanel or FTP client portal. We will use the Bluehost cPanel for this example.

Once you log in to your cPanel, go to File Manager under the Files tab. Head over to the public_html root folder.

In this folder, go to wp-content » themes. Locate the active theme you are using on your site and select it. Finally, find the header.php file within this file and right-click to Edit.

cpanel edit header

 In the code editor, find the <head> code line located near the top. Paste the Google Analytics tracking code right before the closing </head> tag. Then, Save the edit.

cpanel add google tracking id header

You have just added the Google Analytics tracking code manually on your WordPress theme through the header.php file.  

Add Tracking Code Through The Footer.PHP File

Adding the tracking code to the footer is almost identical to adding it to the header. The only difference is that you will add it to the footer.php file, not the header.php file.

To get started, use your cPanel or an FTP client portal and locate the public_html root folder like in the previous process. 

Follow the same process you did while inserting the code to the header.php file, but this time, find the footer.php file.

Finally, insert your Google Analytics tracking code just before the closing </body> tag in the footer.php file.

cpanel add google tracking id footer

Add that’s it! You can now successfully add the tracking code to your theme’s header or footer through cPanel or an FTP client.

We insert the tracking code in the header or footer so that it can track every page.

Add Tracking Code Through The Functions.PHP File

For this method, we will use the WordPress dashboard. Here, go to Appearance »Theme Editor

You will see a list of files on the right under Theme Files; locate the ‘functions.php’ file. 

Scroll to the bottom of this page, and just before the closing tag, paste this code:

1 &amp;amp;lt;?php
2 add_action('wp_footer', 'add_Googleanalytics');
3 function add_Googleanalytics() { ?&amp;amp;gt;
4 // Paste your Google Analytics code here
5 &amp;amp;lt;?php }
6 ?&amp;amp;gt;

In Line 4, paste the actual tracking code from your Google Analytics dashboard. 

cpanel add google tracking id functions

Next, hit the Update File button, and you should have added your Google Analytics tracking code.  

Remember that adding the tracking code manually or through WPCode may take a little time before metrics start trickling in on your Google Analytics dashboard.

Congratulations! You can now use Google Analytics to monitor your WordPress website performance. Next, let us look at some commonly asked questions.

FAQs: How to Set Up Google Analytics in WordPress

Is Google Analytics free?

Yes, Google Analytics is free for anyone to use.

Is using Google Analytics through a WordPress plugin safe?

Yes, using Google Analytics through a trusted WordPress plugin like MonsterInsights is safe and recommended. MonsterInsights ensures the security of your website data by adhering to best practices:

  • Data Privacy: MonsterInsights is compliant with privacy regulations like GDPR and provides options to anonymize IP addresses, ensuring user data protection.
  • Secure Integration: It uses secure OAuth authentication to connect with your Google Analytics account, keeping your data safe from unauthorized access.
  • Regular Updates: The plugin is regularly updated to patch security vulnerabilities and maintain compatibility with the latest WordPress versions.

Is GA4 replacing Google Analytics?

Google Analytics 4 (GA4) is not a replacement for Google Analytics (GA) but the newest version. GA4 offers advanced features and a more user-centric approach to tracking data. Learn more here: Google Analytics 4 vs Universal Analytics: Full Comparison.

Do I have to own the domain to set up Google Analytics?

Yes, you need admin access to your domain or website in order to connect your website to Google Analytics.

How do I use Google Analytics and MonsterInsights for SEO?

Combining Google Analytics and MonsterInsights can supercharge your SEO efforts:

  • Keyword Tracking: Use MonsterInsights to track which keywords bring the most traffic to your site. Optimize your content around these keywords for better SEO.
  • Page Insights: Monitor individual page performance in Google Analytics and identify high-performing pages. MonsterInsights provides easy-to-understand reports, helping you improve underperforming content.
  • User Behavior: Analyze user behavior with Google Analytics through MonsterInsights to get insights on user engagement, click-through rates, and more.

How do I export data from Google Analytics to my WordPress site?

To export data from Google Analytics, you can use the export feature in your Google Analytics dashboard. However, a better and simpler way is to integrate it with your WordPress website using MonsterInsights. This method will remove the need to export data since all of it will be readily available in your WordPress dashboard. To set up MonsterInsight:

  1. Install and activate the MonsterInsights plugin on your WordPress website.
  2. Connect MonsterInsights to your Google Analytics account. This can be done through the plugin settings by following the guided setup.
  3. Once connected, MonsterInsights will automatically start tracking your website data, such as page views, user demographics, and more.
  4. Access your data in an easy-to-read format directly from your WordPress dashboard.

If you would like to try other tracking tools other than Google Analytics, here are 13 Tools to Track Visitor Traffic on Your WordPress Site. To add to that, here are additional articles you can read to help you learn more about tracking.

These 3 articles offer an in-depth look at how to track specific site metrics and how you can fully use the information to improve your site.

Comments   Leave a Reply

  1. Hi there,

    When I test my sites with Google PageSpeed I see that the analytics and google search console data consumes resources.

    What is the best way to collect data to Analytics and GSC without making the site slower?

  2. Hi, thank you for the post. Just tried to add the GA code manually to my GeneratePress free theme and got an error message. The editor won’t let me save the file.

    This is the functions.php file of my child theme before pasting the code:

    * GeneratePress child theme functions and definitions.

    function generatepress_child_enqueue_scripts() {
    if ( is_rtl() ) {
    wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' );
    add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );

    Is there something I'm missing?

    Many thanks,

  3. I use Google Analyticator. You just connect the site to your Google Account, select the Analytics Profile and it does the rest for you, including embedding a graph of your visitors into your Dashboard. Brilliant!

    1. Hi,

      Google Analyticator looks good. I want to try.

  4. Hey Jeremy

    Nice tutorial! You could also use Yoast’s “Google Analytics for WordPress” plugin. It supports most of GA’s features and it’s pretty easy to set up.

    – Andor Nagy

    1. Shahzad Saeed May 17, 2018 at 9:54 am

      The ‘Google Analytics for WordPress’ plugin is now rebranded as MonsterInsights.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!