WordPress.org

Ready to get started?Download WordPress

Forums

All in One SEO Pack
[resolved] Google analytics code is placed in wrong place (18 posts)

  1. alistairgd
    Member
    Posted 2 years ago #

    Why does the All in one SEO pack plugin put the Google Analytics code in the body of the webpage?

    It should be placed just before the closing head tag.

    http://wordpress.org/extend/plugins/all-in-one-seo-pack/

  2. Michael Torbert
    WordPress Virtuoso
    Plugin Author

    Posted 2 years ago #

    It shouldn't be appearing in the body.
    What is the URL of your website?

  3. alistairgd
    Member
    Posted 2 years ago #

  4. Michael Torbert
    WordPress Virtuoso
    Plugin Author

    Posted 2 years ago #

    It's being output in your theme's footer function.
    With the new tracking code, it can actually be placed anywere. However, with the next update that comes out this week, we may move it back to the head.

  5. alistairgd
    Member
    Posted 2 years ago #

    According to Google it goes in one place, before the closing head tag.

    This is what puts me off using plugins for SEO, you have to check they are complying with good practice, which means you're usually better off doing it yourself in the first place.

  6. Michael Torbert
    WordPress Virtuoso
    Plugin Author

    Posted 2 years ago #

    It can go anywhere.

  7. Alaskan
    Member
    Posted 2 years ago #

    How can I change it? I can't get Google analytics to work, and I think this is the problem. I can't find anything else wrong.

    Can I just remove my Google Anaytics account number from 'All In One SEO' settings, then add the Google Analytics code to my header.php manually?

    Or will that confuse the plugin? Thanks.

  8. Sargon_of_Akkad
    Member
    Posted 2 years ago #

    Stupid question: Why move it back to the head?

  9. danieldeceuster
    Member
    Posted 2 years ago #

    Why move it to the head section? Try to verify Google Webmaster Tools with the code placed anywhere else and you'll get this:

    "Verification failed for [URL removed] using the Google Analytics method (less than a minute ago). The Google Analytics tracking code on your site is in the wrong location. You can verify site ownership only with the asynchronous snippet placed in the <head> section of your home page."

    Ever since Google updated Analytics they have told you to put the tracking code in the head section. The tracking will work with the code anywhere, but Google's instructions are for it to be in the head section.

    @alistairgd: I found a hack to fix this for All In One SEO Pack. Go to your plugin editor and select All in One SEO Pack. The plugin file you want to edit is all-in-one-seo-pack/all_in_one_seo_pack.php

    You are looking for this line of code:

    ////analytics
    if($aioseop_options['aiosp_google_analytics_id'])
    add_action('wp_footer', array($aiosp, 'aiosp_google_analytics'));

    All you have to do is change wp_footer to wp_head and it fixes it for you. Something to keep in mind, you have to be sure that in your header.php you still have this code: <?php wp_head(); ?>

    Of course, if you are using this plugin it must be there else it won't work. This just moves the analytics tracking code from the footer to the head section.

  10. alistairgd
    Member
    Posted 2 years ago #

    @daniel

    Thank you for taking the time to explain how to hack the plugin to be Google compliant, however I have decided to do all my on site SEO by hand.

    Plugins can save time, but the trade off is you never really know what they are doing under the hood, and you get caught it in upgrade chasing.

    So, by hand it is :o)

    Thanks anyway.

  11. cnymike
    Member
    Posted 2 years ago #

    @danieldeceuster Totally in agreement with you. The code snippet should be placed right before the closing head tag as stipulated by Google. I will not use this plugin because of that.

  12. Michael Torbert
    WordPress Virtuoso
    Plugin Author

    Posted 2 years ago #

    Google Analytic's Asynchronous code can be in the head, and the rest of the stuff lower before </body>.
    All in One SEO Pack places Google's tracking code in the <head>

  13. cnymike
    Member
    Posted 2 years ago #

    @Michael Torbert I am glad to hear that. Have verified what you say so thanks for the clarification.

  14. mbyrne
    Member
    Posted 2 years ago #

    What needs to be in the actual page templates? I am adding Google Analytic's Asynchronous code in the form of analyticsTracking.php file and called by <?php include_once("analyticsTracking.php") ?> in the header.php file. But I'm still not seeing any results in my google analytics account.

  15. Michael Torbert
    WordPress Virtuoso
    Plugin Author

    Posted 2 years ago #

    mbyrne,

    You don't need to do that. Just use All in One SEO Pack. That's what this thread is for.

  16. Fanaticweb
    Member
    Posted 1 year ago #

    What happens is the Google analytics ends up being displayed twice? Assuming that we never bothered removing the one that was integrated through the theme's functions and using AIOSEO plugin?

    On my end, it was like that for the longest time and I had no issues, but reading this thread got me wondering if I should bother.

  17. Peter Baylies
    Member
    Plugin Author

    Posted 1 year ago #

    Fanaticweb,

    I would suggest only managing Google Analytics tracking in one place to avoid duplication. i.e. if your theme is already managing it, then don't tell All in One SEO Pack to add it as well; or vice versa.

  18. Fanaticweb
    Member
    Posted 1 year ago #

    Got it and makes perfect sense, the duplication on each page was probably not a good idea after all yet I got away with it for the longest time, will readjust to make sure its displayed a single time, thanks for the headsup Peter.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic