0

I'm setting up Google Analytics for my Wordpress website. I'm using a theme called "Virtue." I want to track all the pages of my website, and from what I have read I need to paste my script at the end of the head tag.

My question is that in my public_html folder on my cPanel File Manager, I have three files that have the word "head" in them.

The directory is public_html/wp-content/themes/virtue/templates/head.php for the head.php file. But there is also a header.php and a page-header.php file. Am I supposed to paste my code into each of these files, or just the head.php file?

I've read that Google Analytics takes a few hours to recognize the website, so I want to know if I'm pasting my code in the proper place. I really don't want to trouble shoot this for days on end because I'm at the point with my site where I would like to do Google AdWords.

Thank you very much for reading this post and responding as it is appreciated.

4 Answers 4

2

Plugins might slowdown the website. Just, Paste the code in public_html/wp-content/themes/virtue/templates/head.php

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I added a comment to this file to let me know what the script did, and the comment showed up on every page. So I removed the comment and kept the script. I'm sure this is the right thing to do but I'm going to wait for tomorrow to see if Google recognizes the script.
You can check 'Real time' google analytics to check whether it is working or not.
1

Just place the code in header.php. And in case you do not want to edit any of file then you can use the below mentioned plugin to add the tracking code in the head section from wordpress backend itself :

https://wordpress.org/plugins/header-footer/

And if you also wanted to check whether the code is included or not that you can simply check the source view (Ctrl+U) of your website pages and search for Google analytics code.

Comments

0

The documentation of GA refers to the tag of the HTML document, and not a specific file.

If you're less tech-savvy, you can simply use one of the thousands of plugins that exist for this, for example :

https://wordpress.org/plugins/google-analytics-for-wordpress/

(I'm not affiliated, this is the first google search result).

Comments

0

You only need to put it in 1 file and it doesn't even matter which one as long as it's a file that gets included in every page.

I currently have no WP installation to check which one that is, but if you put it in the file that has the <head>-tag in it, you should be fine.

2 Comments

I edited the head.php file with a comment //something, and the text I put in the comment showed up on every page of my website, so I'm assuming this is the main head tag for the entire site. So I just removed the comment and past the tag in and now I'm going to wait to see if Google recognizes my site.
No need to wait, just visit your page and see if that shows up in the realtime results. IIRC, the other results won't show anything until put to 24 hours.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.