WordPress.org

Ready to get started?Download WordPress

Forums

Installing google analytics (19 posts)

  1. samuraicc
    Member
    Posted 2 years ago #

    How do I install google analytics code?

    It says I must place it onto everypage I want to be tracked..

    where do I place it? In my index?

    samurailabs.cc/MissionControl/

  2. Krishna
    Volunteer Moderator
    Posted 2 years ago #

    You need to place the code only once in WP, place it just before the closing </head> tag.

  3. Erick Hitter
    Member
    Posted 2 years ago #

    You're best off using one of the many available plugins. I've had great success with Google Analyticator and Google Analytics for WordPress, but you can find many more here: http://wordpress.org/extend/plugins/search.php?q=google+analytics.

  4. samuraicc
    Member
    Posted 2 years ago #

    I see all these pages I can edit...

    witch one of these pages is the one where I should place the code?

    Footer
    (footer.php)
    Theme Functions
    (functions.php)
    Header
    (header.php)
    Image Attachment Template
    (image.php)
    theme-options.php
    widgets.php
    Main Index Template
    (index.php)
    Page Template
    (page.php)
    Search Results
    (search.php)
    Search Form
    (searchform.php)
    Showcase Template Page Template
    (showcase.php)
    sidebar-footer.php
    Sidebar Template Page Template
    (sidebar-page.php)
    Sidebar
    (sidebar.php)
    Single Post
    (single.php)
    Tag Template
    (tag.php)
    Styles
    Stylesheet
    (style.css)
    Visual Editor RTL Stylesheet
    (editor-style-rtl.css)
    Visual Editor Stylesheet
    (editor-style.css)
    RTL Stylesheet

  5. Krishna
    Volunteer Moderator
    Posted 2 years ago #

    Open the Header (header.php) and place the Google Analytics code just before the closing </head> tag. See guidelines HERE.

    But remember, when you update the theme, the code will be lost and you have to place it back again, unless you are using a child theme.

  6. ManueBresson
    Member
    Posted 1 year ago #

    Hello,

    I want to install google analytics code on my blog. I am not a geek. I don't want to use a plugin as they say it slowers the site so if i prefer to do it myself. where to find the page to insert the code?
    thanks for your help.
    Emmanuelle

  7. Krishna
    Volunteer Moderator
    Posted 1 year ago #

    Please read my post above. It is done without any plugins.

  8. ManueBresson
    Member
    Posted 1 year ago #

    Hello Krishna,

    Before posting my message, I read the thread and opened your link. How can i enter in my source code page to place the code? Once i have placed it, will google analytics will track all my entire blog?
    Emmanuelle

  9. Krishna
    Volunteer Moderator
    Posted 1 year ago #

    Go to header.php (Dashboard > Editor) and locate </head> and place the Google Analytics code just before the closing head tag and save it.

    will google analytics will track all my entire blog?

    Yes.

    But, you will lose the code when you update the theme next time. You can replace it at the same place as soon as you update the theme.

  10. ManueBresson
    Member
    Posted 1 year ago #

    hello Krishna,

    Below, i have posted what is the html before the closing head tag. Do I have to place the code before /* =Header?

    Thanks

    Emmanuelle

    #access a.assistive-text:active,
    #access a.assistive-text:focus {
    background: #eee;
    border-bottom: 1px solid #ddd;
    color: #1982d1;
    clip: auto !important;
    font-size: 12px;
    position: absolute;
    text-decoration: underline;
    top: 0;
    left: 7.6%;
    }

    /* =Header

  11. bythegram
    Member
    Posted 1 year ago #

    As Krishna also mentioned this change will be erased the next time you update your theme so you really should consider using a plugin. One of the plugins by Erick Hitter at the top of this thread would do the trick and I highly doubt you will notice a speed difference in your site.

  12. Krishna
    Volunteer Moderator
    Posted 1 year ago #

    Don't you find the header.php?

  13. ManueBresson
    Member
    Posted 1 year ago #

    Hello,

    Sorry, i was in the wrong page. I copied pasted below what's before and after the closing head tag and inserted the code. Is it right what I have done?
    Thanks in advance.
    Cheers,
    Emmanuelle

    * tag of your theme, or you will break many plugins, which
    	 * generally use this hook to add elements to <head> such
    	 * as styles, scripts, and meta tags.
    	 */
    	wp_head();
    ?>
    <script type="text/javascript">
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-35437858-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>
    </head>
    
    <body <?php body_class(); ?>>
    <div id="page" class="hfeed">

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum's parser.]

  14. Krishna
    Volunteer Moderator
    Posted 1 year ago #

    It looks OK and should work. You can verify at your Analytics account too.

  15. jhonson
    Member
    Posted 1 year ago #

    after the end of header.php file he can paste the script of any where

  16. ManueBresson
    Member
    Posted 1 year ago #

    Thank you all for your help. It works! I don't know what would I do withouth this forum!
    Cheers,
    Emmanuelle

  17. bigfatty
    Member
    Posted 1 year ago #

    Just to be sure, do I copy the header.php file that's presently in my Twenty Ten theme, put the Google Analytics code in the copy, and upload the file into my child theme? Also, I presently have a Google Plus script code in my footer.php file. Should I do the same with the footer.php file, copy and upload to the child theme? Thanks for advice.

  18. Erick Hitter
    Member
    Posted 1 year ago #

    If you're using Twenty Ten, there's no reason to edit the theme for these things. You can use the wp_head and wp_footer actions to output the relevant scripts.

    That said, if you prefer to edit the theme, then modifying header.php and footer.php in a child theme is the right approach. Though it's unlikely that Twenty Ten will be updated, it's safest to make your changes in a child theme.

  19. Vegan Water Kefir
    Member
    Posted 1 year ago #

    Thank you for this information, Krishna and Erick!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.