How to Use Google Analytics And Get Statistic in WordPress for Beginners
Google Analytics makes it easy for anyone managing a site to track and analyze this data. It's a powerful, free tool that can answer a variety of questions for a wide range of users. Wondering which keywords resonate with visitors? Need insight on what design elements might be turning people away?
Here's how you can start answering the website questions that have been keeping you awake at night.Why is Google Analytics Important for Bloggers?
Once you start a blog, your #1 goal is to get more traffic and subscribers. Google Analytics help you make data-driven decisions by showing you the stats that matter. You can see:
Who visits your website?
This part of analytics answers what is the geographical location of your audience, which browser did the user use to visit your site and many other important information such as: screen resolution, JavaScript support, Flash support, language and more.
This data is extremely useful, and it can help in numerous ways. When getting a custom design, you can use the user data to make sure that your site will be compatible with your audience.
If most of your users don’t have Flash support, then you should avoid adding flash element in your site. If most of your users are on 1280 screen resolutions, then make sure that your design is compatible with that resolution or smaller.
What do people do when they are on your website?
You can track where the user is going on your website, how long do they stay on your website, and what is the bounce rate (the percent of users exit your site on the first visit).
By using this information, you can decrease the bounce rate and increase your pageviews.
Who visits your website?
This part of analytics answers what is the geographical location of your audience, which browser did the user use to visit your site and many other important information such as: screen resolution, JavaScript support, Flash support, language and more.
This data is extremely useful, and it can help in numerous ways. When getting a custom design, you can use the user data to make sure that your site will be compatible with your audience.
If most of your users don’t have Flash support, then you should avoid adding flash element in your site. If most of your users are on 1280 screen resolutions, then make sure that your design is compatible with that resolution or smaller.
What do people do when they are on your website?
You can track where the user is going on your website, how long do they stay on your website, and what is the bounce rate (the percent of users exit your site on the first visit).
By using this information, you can decrease the bounce rate and increase your pageviews.
When do people visit your website?
By looking at the hottest hours in the day for your site, you can pick the time when you publish your post. If that time zone is not compatible with yours, then you can schedule your post to meet that hour.
How do people find your website?
This section of the analytics show you where did the user come from (for example: Search Engines, Direct Links, Referral links from another site).
It also shows you what percentage of your visitors came from each of these sources. Google analytics gives you the breakdown of each of these categories. If it is the search engine category, then it shows you which search engine got you the most traffic, Google, Yahoo, Bing etc.
The breakdown of referral sources show you which sites you need to work with the most. If your top referral source is Facebook, then you need to have exclusive Facebook content to make your Twitter audience feel special.
By looking at the hottest hours in the day for your site, you can pick the time when you publish your post. If that time zone is not compatible with yours, then you can schedule your post to meet that hour.
How do people find your website?
This section of the analytics show you where did the user come from (for example: Search Engines, Direct Links, Referral links from another site).
It also shows you what percentage of your visitors came from each of these sources. Google analytics gives you the breakdown of each of these categories. If it is the search engine category, then it shows you which search engine got you the most traffic, Google, Yahoo, Bing etc.
The breakdown of referral sources show you which sites you need to work with the most. If your top referral source is Facebook, then you need to have exclusive Facebook content to make your Twitter audience feel special.
If your top referral source is an external website, then you might want to consider having a partnership with that website (guest post exchange or something else).
How do people interact with your content?
Google analytics shows how your users interact with your site’s content. It shows you what percent of the user clicked on which link on your site and much more.
Google analytics shows how your users interact with your site’s content. It shows you what percent of the user clicked on which link on your site and much more.
You can run A/B split tests by creating content experiments in Google Analytics to understand what works best to meet your goals.
By seeing the user interactivity, you can work your content around your users. By seeing the answers to the questions above, you can focus on the strategies that work for your site and eliminate the strategies that don’t work.
Simply put, eliminate the guess work and focus on stats that matter, so you can make data driven-decisions.
What You’ll Need
To create this plugin, you’ll need just a few things:
- A live WordPress installation running the theme of your choice.
- Access to your site’s files via FTP.
- A code editor or text editor.
I’m using Coda, which gives me code editing functionality and FTP all in one place, but you could use any code or text editor along with a free FTP client such as Filezilla.
If you haven’t created a plugin before, don’t worry. It’s much simpler than you might think. To create this plugin, you’ll follow five steps:
- Check your active theme’s header.php file to ensure it includes the wp_head hook.
- Create a new file in your plugins folder.
- Get your analytics tracking code from the Google analytics site.
- Add some code including the tracking code to your plugin.
- Activate the plugin.
So let’s get started!
Checking Your Theme File for the wp_head Hook
Plugins insert code into your site by attaching code to a hook which is already written into your theme. Any well-written theme will have the wp_head hook in its header.php file. This hook is used by a multitude of plugins to inserts scripts, styles and more.
If you’ve downloaded your theme from the WordPress theme repository then it should have the wp_head hook in the right place, but let’s check just in case.
In your FTP program, access the wp-content folder in your WordPress installation. Inside that, you’ll find a themes folder and then a folder for your active theme. For example, the folder containing the theme files for the twenty fifteen would be at wp-content/themes/twentyfifteen.
Note: It’s only the active theme you need to be concerned with. Ignore any other themes you have installed in your site.
In your theme folder, you’ll find a file called header.php. Open it.
The header.php file includes all of the code at the beginning of each page, including the <head> section of the page. You should find the wp_head hook at the end of the <head> section. So for example in twenty fifteen the full <head> section looks like this:
The last line before the closing </head> tag includes the wp_head hook. You can use this in your plugin to insert code at this point without having to edit your theme files.
Why shouldn’t you edit the theme files, you might ask? Well, it’s a bad idea for two reasons:
- If the theme is updated in future, you’ll lose any changes you’ve made to the theme files.
- A Google analytics plugin is about functionality (i.e. what’s going on under the hood of your site) and not display (i.e. how your site looks and displays content), so it should be added via a plugin and not a theme.
So now you know your theme is ready, let’s get hold of the Google analytics tracking code.
Note: If your theme doesn’t include this code, then I’d recommend getting another theme. A well-written theme will always include this, and if it doesn’t, who’s to say where else there may be problems?.
Note: If your theme doesn’t include this code, then I’d recommend getting another theme. A well-written theme will always include this, and if it doesn’t, who’s to say where else there may be problems?.
Getting the Tracking Code
When you add your site to your Google analytics account, you’re given a tracking code that you need to insert into your site’s pages so that Google can track visitors to each page.
If you have a Google account you can access analytics data using your existing account, or if you’re one of those rare remaining people who don’t have an account with Google, you’ll need to set one up.
Once you’ve done that, you can copy your tracking code from the Admin section of the analytics site.
At the top of the screen, click on Admin to access the admin screen shown in the screenshot.
Your account will automatically be selected on the left and you’ll need to add your website to the PROPERTY column in the center.
If you haven’t added your site to Google analytics yet, click the PROPERTY drop-down box and select Create New Property. If you’ve already added your site, select that from the PROPERTY drop-down box and then click the Tracking Info button beneath it. Skip the next step.
Adding Your Website to Google Analytics
After clicking the Create New Property option, you’ll be prompted to provide details of your site in the New Property screen:
Fill out the fields with your site’s details and click the Get Tracking ID button to access your tracking code.
Accessing Your Tracking Code
Whether you’ve created a new property or clicked the button to access the tracking code for an existing property, you’ll now be presented with the code to insert into your site:
Creating the Plugin
Next, let’s create the plugin which we’ll add the tracking code to.
In your site’s wp-content/plugins folder, create a new PHP file. Give it a memorable name: I’m calling mine wpmudev-google-analytics.php.
In your code editor, open that file. Add the following to it:
[<?php
/*
Plugin Name: Simple Google Analytics Plugin
Plugin URI: http://w3zetmedia.blogspot.com
Description: Adds a Google analytics trascking code to the <head> of your theme, by hooking to wp_head.
Author: W3zetmedia
Version: 1.0
*/
?>]
This tells WordPress that this is a plugin, who it’s by and what it does. Edit the details of the plugin and author as this is your plugin, not mine.
Now below that code add the function which will contain the analytics tracking code:
Now below that code add the function which will contain the analytics tracking code:
[<?php
function wpmudev_google_analytics() { ?>
<?php }
add_action( 'wp_head', 'wpmudev_google_analytics', 10 );]
At the moment this is an empty function called wpmudev_google_analytics() and it’s attached to the wp_head hook which means that its content will be output whenever WordPress encounters that hook, i.e. at the end of the <head> section in each page.
The next step is to copy the tracking code to your function. Inside the function’s braces (and also inside the opening and closing PHP tags inside the braces), paste the tracking code you copied earlier.
Your function will now look something like this:
The next step is to copy the tracking code to your function. Inside the function’s braces (and also inside the opening and closing PHP tags inside the braces), paste the tracking code you copied earlier.
Your function will now look something like this:
[<?php
function wpmudev_google_analytics() { ?>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-XX', 'auto');
ga('send', 'pageview');
</script>
<?php }
add_action( 'wp_head', 'wpmudev_google_analytics', 10 );]
Now save your plugin file and go to your site admin screens.Activate the plugin and go back to the Google analytics site to verify your tracking code. You may have to wait a short while until Google picks up the new code, and then your code will be reported as working.
Post a Comment for "How to Use Google Analytics And Get Statistic in WordPress for Beginners"