Forums

GA script added to wrong part of code? (3 posts)

  1. blue928
    Member
    Posted 1 year ago #

    I've just installed WP and setup my google analytics account. In the instructions, google says this:

    Copy the following code block into every webpage you want to track immediately before the </body> tag.

    In the options of the plugin, by default the code shows up in the header of all my HTML files. If I enable "Footer" then it puts the code immediately after the </BODY> tag. Is this going to cause any problems reporting?

    Thanks!
    Blue

  2. cavemonkey50
    Member
    Posted 1 year ago #

    Hello Blue,

    I have yet to here of any adverse effects from anyone having the Google Analytics code after the </body> tag.

    Unfortunately, I have no control over where the code is placed in the footer. It's up to a template tag called wp_footer(). In some themes it's before the </body> tag, other themes it's after.

    If the placement bugs you, you can change it yourself. Just open up your theme's footer.php file and move the <?php wp_footer(); ?> section before the </body>. Hope that helps!

  3. Butuzov
    Member
    Posted 1 year ago #

    so get_footer() not supported anymore?

    course as i understand if footer required by funciton get_footer() GA wouldn't work.

    isn't it better?

    if (get_option(key_ga_footer) == ga_enabled) {
    add_action('wp_footer', 'add_google_analytics');
    add_action('get_footer', 'add_google_analytics');
    } else {
    add_action('wp_head', 'add_google_analytics');
    add_action('get_header', 'add_google_analytics');
    }

Topic Closed

This topic has been closed to new replies.

About this Topic