Why should we as developers use Google Analytics? While I’m a huge believer of do it your-self data analysis, google analytics is so easy to use and get set up, its perfect for a small dev team or a WordPress site where simplicity is key.

Using Google Analytics we can begin to understand our audience. We can find out who is actually buying that product, signing up for our email list or liking our Facebook page simply by using google analytics and all the cool things tied into it. Throughout this post we’ll get into why Google Analytics is so important and why everyone with an online presence should be using Google Analytics. Next we’ll cover exactly how to install Google Analytics. It’s also important to note that it can take 24-48 hours for Google Analytics to actually start working and you can see the data from your site.

Why should I use Google Analytics

If your a common reader of theramblingdev you know we love data. While building custom dashboards and being able to draw insights from your data is great, in most cases when were using a WordPress site we don’t have the time, skills, or budget to do this. That’s where google analytics comes in.

If your starting a WordPress site, there’s a good chance that your trying to and will eventually have some traffic visiting your site. One of your first steps after getting your site up and running will be to get more users to visit your site. By using Google Analytics we can make data-driven business decisions.

What Google Analytics can Do

While I’d love to cover all the things Google Analytics can do in depth we simply wouldn’t have time to cover it all in this article. If your interested for more in depth and accurate data check out the official Google Analytics Blog. With that in mind here are some of the things the New Google Analytics can do:

  • Where your users are visiting from, can filter by all, new and returning users!
  • The effectiveness of your marketing campaigns
  • Where new users are coming to your site from (Facebook, a blog, etc..)
  • What pages get the most views
  • What are your top events
  • What are your top selling products
  • Activity on platform (are users coming from the web, mobile, etc..)
  • Ecommerce purchase by item name
  • Events count by event name
  • Realtime data view to actively monitor live users
  • A whole bunch more!

Hopefully this list give you a clear idea what you can do with Google Analytics and why its an important tool to your sites growth. To get started, head over to Google Analytics and login to your google account or make a new one. Next you can follow the onscreen instructions and should be able to get the basics set up without to much trouble. After getting a basic account setup you need to create a new property, this is simply a piece of your business that’s all tracked under one unique ID. For example if you run an ecommerce shop but also have a blog you could create two separate properties to track data to each of them separately. You can have 100 properties on a single account so no worries on having too many.

To add a new property go to the admin tab at the very bottom of the left sidebar, next go ahead and hit the create property button.

Go ahead and fill out the Property setup with your info. Next click the Show Advanced Properties and toggle on the Create a Universal Analytics Property. Next go ahead and leave the default to create both a google Analytics 4 and a Universal Analytics property. The reason we have to add this advanced setting is in case we decide to use WordPress plugins to manage our google analytics. Most plugins are built using the older version of google analytics so this ensure the plugin will still work. If you know you wont use a plugin then you can skip this step.

Finally go ahead and answer the questionnaire as to why your using google analytics. What you answer here shouldn’t make a difference and is just an example of how google is collecting data to better improve their products. It’s funny, they are literally using their analytics platform to gather data on who is using their analytics platform! But I digress, after this is all done go ahead and hit the create button.

Set Up the Data Stream

Nice, we are almost there just a few more steps. At this point you should be seeing a page that says to go set up your data stream. If not that means you added the Universal Analytics property, in this case you simply skip this step and will end up directly at the stream details page. If you did the standard setup and didn’t touch the advanced settings then you need to create your stream first then it’ll send us over to stream details. This data stream is how we are going to collect and send our data from our WordPress (or any) site to the Google Analytics platform.

Since we’re using WordPress in this case go ahead and choose Web. Next enter your websites URL and what ever you want the stream name to be. This stream name can be anything that will help you identify what this stream is/does. In most cases simply make it the site name in our case the stream name will be theramblingdev. Go ahead and check the Enhanced measurement button if its there, then create your new stream! At this point we are all setup to connect our WordPress site to google analytics. Keep the current page open since well need it in the next step.

Connect WordPress site to Google Analytics

There are a few ways to add Google Analytics to your WordPress Site. The first and simplest way is by using MonsterInsights. This is one of the best google analytics plugins on the market and can take out all the frustration of setting things up if your not the most tech savvy. MonsterInsights offers a free Lite version that should be enough for most basic use cases. Should you need more options you can upgrade to the Plus version for $99.50 per year.

The next way is by adding your google tracking code into your functions.php file. All we have to do here is create a new function that will hold our tracking code and update the file. This is not too hard to do at all but just be careful if you don’t know a lot about code not to change anything other than the code shown below!

The last way we we’re gunna cover is by adding the tracking code inside our theme options from the WordPress dashboard. The issue with this method is not every themes is the same in how to add code to your head or footer. With that said almost all themes allow some sort of direct code to be added to initialize custom plugins like Google Analytics or Google Maps.

Adding With the Official WordPress Plugin

Okay here’s how to add Google Analytics with MonsterInsights:

  • From your WordPress dashboard navigate to Plugins -> Add New
  • Search for Google Analytics Dashboard Plugin for WordPress by MonsterInsights. Go ahead and download and activate it.
  • Head back to the dashboard and a new Insights option and tab should open.
  • go ahead and Launch the Wizard to get started.
  • Follow the wizard and fill our the instructions, stay with the default options for now.
  • Feel free to upgrade to a pro version or install their recommended plugin if want. For now we are going to skip these steps.
  • Finally we can finish the setup! It can take a day or two for all of your sites traffic to actually start coming in, this happens no matter what way you decide to install Google Analytics.
  • Go ahead and go to our Insights ->Reports to get your first look at the dashboard.

This should get us up and running with MonsterInsights and Google Analytics,.

Add Google Analytics in Functions.php

The next way to add Google Analytics is by adding it in code Theme Functions (functions.php). To do this we need to find our way to our function.php file. To navigate here, go to your WordPress dashboard -> Appearance -> Theme Editor.

If for some reason you can get access to your theme editor, such as you have a bad plugin or there we’re issues installing your theme that never got addressed, then you need to make the change inside your hosting provider or through and FTP Client like FileZilla.

For our case were going to use File Manager on Plesk and edit the file this way. In most cases any changes I make to files is through FTP or through my hosting platform. I also typically only install plugins and themes using FTP, if this is something that needs to be covered let me know in the comments.

So to find the file, in FTP or hosting it will be under your site or if you only have 1 site then it could be under httpdocs -> next find the wp-content folder -> inside this folder go into themes -> now find your active theme (if your not sure you can check in WordPress dashboard->appearance ->themes ). Once inside your active theme we need to find functions.php and open it.

Edit the function.php file

Okay at this point we should all be together again. Now go ahead and add the following highlighted/yellow code to your functions.php file. All this is doing is adding this script to our themes header.


 *  Do not remove these lines, sky will fall on your head.
 *  @package Publisher

if ( ! defined( 'MTS_THEME_WHITE_LABEL' ) ) {
	define( 'MTS_THEME_WHITE_LABEL', false );

 * Starting Theme Engine :)
include_once get_parent_theme_file_path( 'includes/class-publisher.php' );

add_action('wp_head','my_analytics', 20); function my_analytics() { ?> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-26575989-48"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'YOUR TAG HERE!!!'); </script> <?php }

Where you see YOUR TAG HERE!!! you need to go ahead and add your personal google analytics tracking tag! Where do you get that you ask? well if you kept your google analytics site open after creating your property you may see exactly where its at, if no no worries we’ll show you.

From your google analytics homepage (assuming your using the new google analytics) go to admin at the bottom of your left sidebar. Next you should see a way to create new properties as well as a little drop down to select your property. Ensure you have the property you created earlier selected then click the button underneath called “Data Streams“, next expand your property and you should come to a screen with all your tracking details. Expand the Global site tag (gtag.js) field under tagging instructions. This is where you will see your full tracking script, it should look the same as the one above but with a different tracking or “Measurement ID”. Now go ahead and copy your ID and add it in place of YOUR TAG HERE!!! (note, keep the ‘ ‘).

After adding you can check to see if the code was added by going to your site and opening dev-tools (F12 in chrome) and searching for your tag with CTRL-F. If you see any errors or your site is broke, don’t panic just remove the tags and try again.

Add Google Analytics in Theme Options

In my case I’m using a custom theme by MyThemeShop. Theey have fantastic themes and great customer support! I totally recommend checking them out if you’ve not yet. MyThemeShop has a nice way to add and edit the header and footer so we can simply add our script tags that Google Analytics gave us directly into here. This can be added into the header or footer, in our case I’ll add them to our footer code.

After saving, go back to your site and open dev tools (F12 for chrome) and search for your tag. If everything went okay your site should load and you should be able to find your tag in the elements tab in dev tools.


Google Analytics is a powerful tool that we only just began to scratch the surface of. If we cant measure how people use or interact with our websites we’ll never understand what drives our conversions. Google Analytics gives us the power to gather and make data backed critical decisions for our site or business.

Going forward, we’ll try and cover even more Google Analytics content such as creating custom events and a detailed look at the Google Analytics Dashboard. Follow us on Facebook and Twitter to stay tuned for our future post.

Give a Comment