Google Analytics lets you track the traffics of your website and the behavior of the traffic(users). You can check the details of users’ behavior from Google Analytics. Some useful features of Google Analytics are…
- Find the number of users visited your website.
- From where the users are coming(Organic, Social, Direct, etc).
- How much time users are spending on your site?
- Which pages are most popular on your website.
- Which age group of the users is visiting your site mostly.
- And many more …
You can add Google Analytics to WordPress in different methods. I have discussed two methods below, These two methods are easy and safe and also beginner friendly.
But, first, you need to sign up for Google Analytics. If you already have signed up for it then you can ignore the Signing up process and go to the next step.
Google Analytics account creation
Go to http://analytics.google.com/ and log in with your Google account.
Enter a name for the account. You can enter your name or the name of your website so that you can recognize the account(You can have multiple Analytics accounts for different websites with a single Google account).
Go to the next screen by clicking on the Next button at the bottom. It will ask you to choose the platform where you want the Analytics to measure traffic.
Here choose the Web option for the website traffic measurement.
Go to the next screen by clicking on the Next button at the bottom. Here you need to enter your website details, for which you are creating the Analytics account.
- Enter a name for the website. You can choose any name here.
- Enter the website URL. Select the protocol of your website (HTTPS or HTTP).
(If your site doesn’t have a secure protocol installed you can install it in a few minutes by this tutorial.)
- Select the website type. If you do not find a match for your website, you can select the Other option.
- Select Reporting Time Zone. Select the location where you are located, so that it can match with your time zone.
After filling all these details click on the CREATE button. You will be asked to accept terms and conditions on the next screen. Accept these.
You can copy this code or save somewhere else(You can copy this code from the analytics account later also). You need to enter this code to your WordPress website by one of the methods discussed below. You can choose the method which you find easier. All the methods will work fine with your WordPress website.
Add Google Analytics to WordPress by adding the code to the theme header
To connect Google Analytics to your WordPress website you can choose this method. This is the recommended method if you do not want to compromise the loading speed by adding more plugins(Though not all the plugin slower down the load speed of the website).
For this method, you need to paste the Analytics code to the theme’s header.php file. I would recommend you to create a child theme and customize with codes on the child theme. So that you do not lose any codes when the theme updates.
After creating the child theme activate the theme ( Also you can do it on the main theme if you do not want to create a child theme).
Now go to Appearances -> Theme Editor.
It will open the code editor for the theme core files. Select the theme here (current theme is always selected). Select the header.php from the right. Paste the Analytics code before the closing of the </head> tag as the image below.
Now update the file. Google Analytics is now successfully integrated with your WordPress website.
You can measure the traffic details from the Analytics window.
NB: When you will change the theme, you need to paste the same code on the new themes header.php file.
Add Google Analytics to WordPress by Insert Header and Footer Plugin
You can add Google Analytics to WordPress by using the Insert Header and Footer plugin. This plugin will push the Google Analytics code to the page when the page will load. For that, you need to install the plugin. This plugin has more that one million active installations.
After installing the plugin activate it. And go to Settings -> Insert Header and Footer.
Now on the Scripts in Header box paste the Google Analytics code. And save it.
You can check this plugin will do the same job as I described the manual method. It will push the code between the <head> tags of the website.
Both the methods discussed above are beginner-friendly and easy. You can add Google Analytics by following any one of the methods.
The manual method, by adding the analytics code to the theme header file is the method I use on the WordPress websites.
Remember, when you will change the theme you have to add the code again to the new theme’s header file.
You can choose the second method (with the plugin) if you are not comfortable with adding codes to the theme files.
You can ask me for any query. I will definitely get back to you.