How To Add Google Analytics to WordPress without plugin
So you want to add Google Analytics to your WordPress theme, but you don’t want to add another plugin. The whole thing is pretty simple and it requires editing header.php file in your theme. It’s important as this file is the one used in displaying every post, page or sub-page on your WordPress site.
If it’s not it probably shows bad design of theme itself, but this doesnt happen often.
The theme doesn’t matter as most of the time the only file you’ll have to edit is that file. Now you can accomplish this in two ways:
Add Google Analytics via WordPress Panel
If you can edit your theme files directly in your WordPress you’ll be able to do it in just under a minute.
1. Log-in into your WP installation as administrator.
2. From left sidebar click on Appearance and then on Editor, you’ll see something as I do below:
3. From the right sidebar find entry for Theme Header (header.php) file and click on it.
4. Once the editor opens you can paste the Google Analitycs code between the < head > and < / head > tags. Once done just press “Update” button to update theme file. After edit it should look just like this:
5. If you don’t see the Update button it means that your theme files aren’t editable/writable by the user. In this case you can either change permission on files or just edit them via FTP/SFTP.
Add Google Analytics via text editor and FTP or SFTP access
Sometimes your theme is protected from writing by the user which runs web server. It’s a good thing since it increases the security risks of theme which is never high enough for WordPress sites. If that’s the case you’ll need to access your site using FTP (File Transfer Protocol) or SFTP ( SSH File Transfer Protocol) program, we recommend FileZilla.
Add your site login data and ip address to your FTP program.
Click “Connect” in order to connect to your server.
Once logged in navigate to your web directory (usually public_html), the important part is that this directory holds folders with your themes (themes), plugins (plugins) and user uploaded content (uploads/date). We’re interested in subfolders of themes, particularly the wp-content/themes/twentyseventeen folder as that’s the theme we’re using.
After navigating to that folder (double click) in your S/FTP program you can download the header file and open it with any text or code editor. Then simply follow the points 3-4 from above guide. Once you save the changes click on file in your FTP client and then on “Upload” option. This will replace the file on server with it’s new version containing your code.
How to verify my WordPress has Google Analytics code included properly
Nothing simpler, open up your website in Chrome or FireFox (if you’re using IE we recommend you to stop :D), you can then click on any space on page and then “View page source”. Once you do it’ll open up another tab with address like view-source:http://YourWordpressSite.com/ – you can as well just type in another type view-source: and after any page on your website. Once opened have a look at code between <HEAD> and </HEAD> tags. Your code should be there.