Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

Comments

  1. E.S. Michelson says:

    Good post. Thank you.

    Near as I can determine Google Analytics will not work on a yourdomain.com wordpress.com account unless you upgrade to, or have, a WordPress business plan. ($299/yr.)

  2. Bill says:

    Thank you for the tip. I downloaded a Header/footer plugin and it worked great.

  3. moko says:

    Uh wow! great article.. i need this .. thanks

  4. Maris says:

    How to hide tracking code from page source?
    Everyone can see it….

  5. Maya Mey Aroyo says:

    Hey,
    First I wanna say that I really love this website, been using it quite a lot lately..
    Second,
    I already have a google analytics account on a different website (actually 2), and I can’t seem to find how to add my two new sites to that account…
    I tried the help on the analytics itself, and got to the page where I can add a URL- but the fill-in boxes where grey and I had no option filling in the details. Any advice?

    Cheers!

  6. Febriyan Lukito says:

    I want to ask about the analytics plugin itself. I use the one from Yoast. Is it recommended to install such plugin? Please help on this.

    • WPBeginner Support says:

      If you find it hard to add Analytics code to your website, then you can use such plugins.

  7. Tony McBride says:

    Easy to follow and I liked the fact that you had the video as well as text to explain the how to.
    My site is set up now for tracking, thank you!

    Tony

  8. Ahmad Tahir says:

    I a£ using wordpress blog from wordpress.com that doesn’t allow for plugin installation. I don’t know how to access the websites files on the wordpress.com server.

  9. Mieke Fassart says:

    I had a perfectly running report until April third. After that date my traffic is zero. Can you help?

  10. ROnald says:

    With a multisite network of independent blogs that I administer: Do I need to install Google Analytics *before* I convert the clean WP install to a multisite network, or *after* it has been networked. I want Analytics to report on each site independently.

  11. elizabethsusanjoseph says:

    I followed all this information. but I am getting an error message as follows:

    “Tracking code on page example.com/ does not match property example sites tracking ID UA-61……”

    What might be the problem.

  12. Mahe Karim says:

    I paste this code on my function.php bt not working so i again remove analytical code but my site still showing that “Parse error: syntax error, unexpected ‘<' in /home/eishkool/public_html/~/wp-content/themes/wpstart/functions.php on line 452"

  13. Dawn Reber says:

    This was a very simple and easy to follow tutorial for setting up google analytics. Thanks!

  14. j says:

    great thanks a lot, i love you guys. however google says all too briefly:

    “Create a PHP file named “analyticstracking.php” with the code above and include it on each PHP template page.”

    google provides this google tracking code to use:

    (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’, ‘YOURTRACKINGCODEHERE’, ‘auto’);

    ga(‘send’, ‘pageview’);

    most of us will know that is the analytics tracking snippet

    so i put this in a plain txt file and save as .php fairly simple, but is this the right syntax for a php file? im new and i dont think so – but its what google said to do?. also

    including it on each php template page.. can this just be done with the php get_analyticstracking.php include tag? and if so does my analyticstracking.php script belong in my theme folder or the includes folder?

    the aim here is to call this tracking script into each template file using the include and then adding the following line to each template page immediately after the opening tag:
    to track each page where it is implemented.

    i like the idea of having the tracking done in the php rather than the open headers or footers but im not about to risk breaking the site to do this method when i dont fully understand it. am i on the right track?

  15. Janie Nafsinger says:

    I see the analytics code across the top of my screen above my header even though I pasted it into my footer as instructed?

  16. amanda says:

    Nowhere (except here, on the bottom of all the instructions) does it tell you that a WordPress blog (not self-owned) cannot use Google Analytics! Just want a good stats tracker that will show the visitors to my (free) WordPress blog. I have a StatsCounter counter but it doesn’t show the landing pages or exit pages. It does for my site, but it stopped doing it for my WordPress blog a few months ago. Entirely. I took down the code and re-entered it, even signed up to another tracker and it just won’t communicate right with WordPress and I can’t get that info! Help, anyone?

  17. Lisa Moore says:

    Google specifically says to insert the tracking code before the tag (article here https://support.google.com/analytics/answer/1008080?rd=1). Why are you telling readers to insert the code after the tag instead?

    • Steve says:

      You are so right Lisa although it does work if in footer. The problem I’m having is when I try to verify the analytics in Webmasters Tools, it declines stating it cannot find tracking in HEAD! So I will be going back and putting in Head and not Footer.

  18. WPBeginner Staff says:

    Give it at least 24 hours before your data may start showing up in your analytics account.

  19. Jackie says:

    I had an Analytics account just “there,” but I didn’t use it. Now I want to start using it, and it has the correct information, but it’s showing no activities on my blog. I’ve even installed it onto my WordPress dashboard and it’s still not showing activity.

    Any thoughts??

  20. Deb Lara says:

    Pasted the PHP code snippet along with my GA script in the functions.php file and it worked well. Was looking for the best way to escape using a plug-in! Thanks for this! :)

  21. Concerned Citizen says:

    You refer to “Step 6″ a couple times but I cannot find a “Step 6″.

    • WPBeginner Staff says:

      Thank you for notifying us, we have updated the article. This is an old article rewritten several times since then to keep up with changes. The step 6 is actually step 4 now. Hope this helps.

  22. Lumia says:

    Yes you can

  23. Lumia says:

    Ask those who set up the page and installed analytics to grant you access…

  24. Nathan Pierce says:

    I got a website from someone else. It already has Google Analytics installed. I assume that the Google Analytics account is connected to his Google account, so I won’t be able to transfer that to my own Google account. (It’s impossible to transfer YouTube videos from one Google account to another.)

    So if I set up my own Google Analytics account, and hook that up to the website, will I loose historical data?

    Would this procedure differ from the above?

  25. mobilepundits says:

    I am using online WordPress blog and i want to create Google analytics in my blogs is their any solution please help me thanks!

  26. Linda says:

    I have moved my blog from a blogspot to a wordpress and i wonder if you know if i can change the adress in google analytics to the new one?

  27. WPBeginner Staff says:

    paste the code in header.

    • eh mon! says:

      your video says footer

    • Lucie says:

      I have the same problem. It is really so easy, just to copy the UA code into header? And Do I lost all my historical data on my blog ? I would be so grateful for some help :)

  28. 2wanderers says:

    Hi,
    I am trying to set up Google Analytics with the Plugins Method (Recommended). Where do I paste the code: in the header or in the footer. Could anyone who has tried tell me whether it has worked for them?

    Many thanks
    Susana.

  29. susana says:

    Hi,

    I want to paste the code by using the plugin Insert and Footer. Where do I paste into the header, footer or both in the plugin settings?

  30. Amanda says:

    For the plug-in option, do you paste the code into the header or footer box in the settings?

  31. Rukkie says:

    Please how do I know it’s working after installing the tracking code in the plugin?

  32. WPBeginner Staff says:

    Yes this is the tag.

  33. Zomi Daily says:

    There is no tag in the header.php file of twenty fourteen theme, the only tag similar is <body >

    So where should we place the code?

  34. DreamKatari says:

    Thanks for this. Its so great

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.