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. rehman says:

    I am new to google analytics. Today I got the code and just wanted to paste in correct place. I was wondering whether to keep in end of head section or body section. because as per google analytics instruction it was mentioned to keep in the end of head section. I am now able to successfully install google analytics. Thanks for your help.

  2. michaelcselva says:

    Seems like the easiest way is to insert the script into the footer. Just did that, now I’ll wait 12-24 hours. Hope it works!

  3. NonFictionAddict says:

    Can you set this up if WordPress hosts your blog? Do you have specific directions for that scenario?

  4. green-van says:

    I Am having a problem with Google Analytics, the first time i installed it i was getting correct updates, then i changed my address from http://www.green-van.com/test

    to http://www.green-van.com and made a new step 6. but since then the same statistics, 3 visits and never any new ones. i am using google analitycs wp plug in now, and in my footer.php i have this

    Cufon.now();

    i don’t know if that is interfering with anything.

    maybe i should not use the wp-plugin and do the code directly inside the footer?

    can i send the footer.php or the functions.php to see if things are in the correct order?

    kind regards,

    Giannis

  5. ardegas says:

    @wpbeginner That did the trick. It works now. Thank you.

  6. wpbeginner says:

    @ardegas Try removing the line space in line 2.

  7. ardegas says:

    Ok. Here is the code: http://pastebin.com/Ht1LSCr6

    Remember it’s a child theme file.

  8. wpbeginner says:

    @ardegas The code above works perfectly fine because all it is doing is adding an action in wp_footer to add google analytics…. the only reason why it would not work is if you paste the code in a manner which is not semantically right. Shoot over an email with your functions.php file code using pastebin or similar service… will evaluate and let you know what is wrong.

  9. ardegas says:

    @wpbeginner I’m using a child theme, and functions.php is almost blank. The only function I have now is an empty function: <code><?php function twentyten_posted_on() { } ?></code>. I use this function to remove some metadata from my theme. Without the php tags this function won’t work. So it looks I’m using the right semantics. I’m pulling my hairs right now.

  10. wpbeginner says:

    @ardegas You need to make sure that you are using the write semantics… For example you probably do not need the first <?php code because often functions.php files are already in php… So make sure that you are not opening the php tag if it is already open or closing it when it should be opened….

  11. ardegas says:

    I tried to insert the Analytics code using functions.php, but it gave me this error:

    <i>Warning: Cannot modify header information – headers already sent…</i>. I couldn’t even log in after. I ended removing this offending code from the file manager. It was bad. It’s a pity, because this snippet of code looks beautiful. I tried to remove any offending white space, but it was of no use, and now I’m afraid to even touch the functions.php file again.

  12. lindsayihart says:

    The dashboard will not save the snippet. I have tried placing it just about </body> and also above the wp_footer tag (the note says you shouldn’tt seperate this from the close body tag) Still NOT saving the code.

  13. wpbeginner says:

    @martinfarr1 The footer.php is located in your theme’s folder which can be found /wp-content/themes/your-theme-name/

    If you really don’t have a clue, then try one of the Google Analytics plugin for WordPress.

  14. martinfarr1 says:

    where do i find footer.php? Have been trying to do this for days but am a total beginner I’m afraid!

  15. wpbeginner says:

    @BrianBraker That is because you pasted the other PHP codes without opening the php tag.<?php add_action(‘wp_footer’, ‘add_googleanalytics’); function add_googleanalytics() { ?> <script type=”text/javascript”> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-24076071-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s); })(); </script> <?php }

    //Here you can paste all the other codes

    ?>

  16. BrianBraker says:

    Did not work. Completely screwed up the function.php file so site did not load. Uploaded back up file.There is a bunch of other code in function.php file

    Here it is:

    <?php add_action(‘wp_footer’, ‘add_googleanalytics’); function add_googleanalytics() { ?> <script type=”text/javascript”> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-24076071-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s); })(); </script> require_once(TEMPLATEPATH . ‘/epanel/custom_functions.php’); require_once(TEMPLATEPATH . ‘/includes/functions/comments.php’); require_once(TEMPLATEPATH . ‘/includes/functions/sidebars.php’); load_theme_textdomain(‘StudioBlue’,get_template_directory().’/lang’); require_once(TEMPLATEPATH . ‘/epanel/options_studioblue.php’); require_once(TEMPLATEPATH . ‘/epanel/core_functions.php’); require_once(TEMPLATEPATH . ‘/epanel/post_thumbnails_studioblue.php’); $wp_ver = substr($GLOBALS['wp_version'],0,3); if ($wp_ver >= 2.8) include(TEMPLATEPATH . ‘/includes/widgets.php’); global $shortname; if (get_option($shortname.’_enable_dropdowns’) <> ‘false’) { update_option($shortname.’_enable_dropdowns’,'false’); }; ?>

  17. wpbeginner says:

    @luxdesign28 Yes, Google Analyticator plugin does the job.http://wordpress.org/extend/plugins/google-analyticator/

  18. luxdesign28 says:

    Hi there,

    Is a method or a plugin how to show the data delivered by Google Anlalytic directly on wordpress, without going to Google Analytics webpage ?

  19. Tarun says:

    How to install the same in a subdomain take for example i have a website http://www.xyz.com and i want to track my subdomain http://www.123.xyz.com what should be done in-order to do so ?

  20. Avenir says:

    It Allows usage of custom variables in Google Analytics to track meta data on pages. Thanks for your support will try soon.

  21. Karl Anthony Borg says:

    Was trying to figure out how to install Analytics on WordPress but didn’t manage on my own.

    Thanks to your info – I now managed and GA is up and running.

  22. Nicholas Massey says:

    Just what i was after. I just placed it in the footer. Seems like the easiest option to me. :)

  23. Sven cooke says:

    Thanks for the information. This is good advice for the beginner and seasoned blogger.

    Many thanks

  24. wanie says:

    hello,

    I am using the free wordpress version. Where do I find this part – “theme’s footer.php right above the tag”, so that I can simply copy and paste?

    Thank you!

    • Editorial Staff says:

      You can’t add this in your WordPress.com account. That is why they offer you with their own statistics.

  25. Fask says:

    You can use the same code for the meta robots? in this way:

    add_action(‘wp_head’, ‘insert_meta_robots’);
    function insert_meta_robots() {
    ?>

    <?php
    }

  26. kevin says:

    Analytics doesn’t work past the first page of my WP blog unless I add the code in my footer AND the sidebar.

  27. Tayler says:

    This is somewhat of a disaster! I added the code and now I can’t access my blog, it’s completely whited out

    Parse error: syntax error, unexpected $end in /home3/sulukuc1/public_html/wp-content/themes/constructor/functions.php on line 344

    I saw this error message after I pasted the code in my funtions.php:

    Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home3/sulukuc1/public_html/wp-content/themes/constructor/functions.php:21) in /home3/sulukuc1/public_html/wp-content/themes/constructor/libs/Constructor/Admin.php on line 31

    Warning: Cannot modify header information – headers already sent by (output started at /home3/sulukuc1/public_html/wp-content/themes/constructor/functions.php:21) in /home3/sulukuc1/public_html/wp-admin/theme-editor.php on line 89

    Please help!!!!!!!

    • Editorial Staff says:

      You need to make sure that the code is semantically right … meaning that opening PHP tag may or may not need to be there if the PHP is already open.

  28. Wes Hopper says:

    I’ve read in the Thesis forums that the new GA code is asynchronous and needs to go in the header to work properly. It also doesn’t affect page load like the old code.

  29. WIP says:

    Hello again, sorry my bad. I fixed it! :)

  30. WIP says:

    Hello,

    When I put the Google Analtyics code in the footer.php and in the functions.php my whole blog dissapeared! Total white-out! What happened? What can I do to get it back?

  31. Angela says:

    so if I use a free wordpress blog I can NOT use this plug-in?

    • Editorial Staff says:

      Thats correct. If you are on free WordPress.com then you don’t get this. You however get to use WordPress.com Stats.

  32. Dan says:

    Thanks for this, I’d just pasted it into the head.
    A function is so much neater though!

    Dan

  33. m says:

    Hello,
    Almost, but not quite there, I would like the first option of copy and pasting the code- but, I cannot find the “theme’s footer.php right above the tag” – not in tools, settings, themes, general, etc etc. Sorry to ask its probably simple! I added it to the normal ‘text’ widget works for all else but this.

  34. Lewis Bassett says:

    Thanks. I am just beginning to understand all of the great features that Analytics can offer.

  35. Marc says:

    Great compilation of what a beginner needs to know about Google Analytics and WordPress! I scheduled 1 hour to find out how to setup Analytics for my new site, I was done in 5 minutes… – Thank you!

  36. Ailora says:

    Magnificent tutorial, thanks. I’m in the 12 – 24 waiting period to see if it works but I already appreciate you instructions and your willingness to reply to comments. I actually found what I was looking for in one of your responses to a poster.

  37. Natalie says:

    I really can not make sense of Google analytic. I prefer to use Piwik instead.

  38. Ana Pacquiao says:

    this was very usefull, i had a little trouble because i’m not familiar with the html edition this worked great for me

    THNX A LOT!

  39. Brett says:

    Thanks for the tip, I did the copy and paste and it worked great.

  40. iankramer says:

    Thanks for the good info.

    Any differences/advantages between the direct paste and functions.php methods? Thanks!

  41. Shelley says:

    Great, clear description – even for someone is a codaphobe. Thanks. I am wondering tho, if when google activates this if the stats will appear in the wordpress dashboard like my other stats package did (the wordpress.com stats) which seems to be broken as of today. Thanks!

    • Editorial Staff says:

      There are some advanced Google Analytics plugin that does that, but we recommend that you check on Google Analytics site, to get the full report. Because no plugin gives full integration.

  42. Rose says:

    This is indeed an informative site.It was really helpfull.

  43. Ameya Waghmare says:

    I am not able to figure out still, how do you edit the footer (or header for that matter) of the theme of the webpage?
    can you please give instructions where can I find way to edit my footer?

    I have tried ‘Edit CSS’, ‘Extras’, and also some other options in the ‘Theme’ menu. Couldn’t get it done. :(

    Please help.

    • Editorial Staff says:

      You will need to click on appearance and then editor. Find header.php or footer.php to edit those files.

  44. Jeremy says:

    I’m thinking about going the plugin route – do I need to use both plugins or one or the other?

    I know that the “Google Analytics for WordPress” asks me where I want to embed it but then then “Google Analyticar” doesn’t ask anything about embedding so I’m wondering if it does it or if I have to do something manually…

    Thanks for this walk through!!!

    • Editorial Staff says:

      You need the manual code or the plugin… not both. Google Analyticar just adds the code in your site.. It does not give you an option of where to embed.

      • chris says:

        I am attempting to use the Google Analytics for WordPress plugin to add the code to my wordpress site. It gives an option for installing the code in the header. When I look at my header file after activating and authenticating the plugin, I see no added code in my header file. Is there somewhere else the code is installed besides the header for my theme?

        • Editorial Staff says:

          It should add it in the area, but it will not modify your theme. If the code is not showing in your theme, then it can mean that your theme does not have a wp_head(); hook in the header.php.

  45. Jan Kasal says:

    Step 5 states to paste the code above the body end tag. Google has changed it since. It goes above the head. Just to let you know.
    Jan

    • Editorial Staff says:

      Google has not changed anything… All companies would like to have their scripts added in the header << But it is not wise for the webmaster. Any smart webmaster / developer would keep scripts like analytics in the footer to speed up the load time…

      WPBeginner has the codes in the footer. Twitter.com has the code in the footer and many other sites as well.

      • physio says:

        Ok… apparently the commenting system doesn’t like angle brackets. That second paragraph should have said:

        If you want more accurate analytics you will use the new snippet version and you will put it in the head. If you are paranoid about page load times you will put it just before the close body tag.

        • Editorial Staff says:

          How does the placement reflect accuracy? Whether you put the script in the head, or at the end…. upon the full page load, it will still count one user…

  46. Brandon C. says:

    i wish i had seen this tutorial before i spent three hours trying to figure it out on my own.

  47. Drew Michaels says:

    Would love to know your thoughts on which method you recommend for installation. Such as are there advantages to placing the code by hand vs. using a plugin?

    • Editorial Staff says:

      Using a plugin is adding multiple database queries that you don’t need. By hand is probably the easiest method and it is efficient for the site :)

  48. Omer Greenwald says:

    This is one of the few features I did use a plugin for, even though it can definitely be achieved manually be pasting the code as you explained, thanks for sharing.

  49. Eden-Avalon says:

    I just switched over from an entirely hand-compiled website to one using wordpress. This will be most helpful. Thank you!

  50. Saikou marong says:

    Great tips for a newbie like me i will certainly try it now. The beauty of WPress is that it has a very little limitation.

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.