Forums

Analytics says insert code before header, WP says footer (8 posts)

  1. Monica
    Member
    Posted 5 months ago #

    Hi,
    I want to insert code to track my blog with Google Analytics. The site has given me the snippet of code, and says to insert it just before </head>.

    WordPress support forums said to insert it before </foot>. Then there's the plug ins that will do it for you. Which is correct - head or foot? Is a plug-in recommended? (I have a self-hosted WP site.)

    Thank you!

  2. dkotter
    Member
    Posted 5 months ago #

    I have always put the Google Analytics code before the </head>. I figure it's their code and that's what they recommend, so might as well follow that. I know a few analytics plugins I've used also place the code there, so you shouldn't have any issues following Google's instructions.

  3. SwansonPhotos
    Member
    Posted 5 months ago #

    Loading an external script file in the head is common...if you have inline javascript, it should be placed just above the closing body tag.

    Some scripts need to be loaded in the head for the 'content' to work, some can be deferred as noted (as they have no affect on site content).

    Many optimization tools do not review 'what' the js actually is or does and just make general comments to load in 'footer'...

    What you do want to avoid is loading inline javascript in the head.

    If your site properly allows caching of the external js files locally, your clients' browsers will not have 'get' them on subsequent page loads.

  4. Monica
    Member
    Posted 5 months ago #

    Thank you for your responses! I never got any notice that I had received responses, so I just checked here wondering about that. Must be a setting.

    Anyway, I don't know much about coding, so the second answer is a little beyond me - wouldn't know "inline javascript" if it hit me in the face - so I'm going to follow the advice of the first response! Sounds easy enough. If I have problems, I'll be back!

    Thanks!

  5. Monica
    Member
    Posted 5 months ago #

    Mission accomplished, I think, but I have a question: what's the difference between header.php and header-admin.php? And if I want to track my About page, is there a separate page to insert the tracking code? Or does the header hit every page? (that's right, not a coder, or anything like that)

    thanks!

  6. esmi
    Theme Diva & Forum Moderator
    Posted 5 months ago #

    header.php is one of the template files in your theme. header-admin.php is a WordPress core file and should never be edited.

  7. Monica
    Member
    Posted 5 months ago #

    Thank you for that critical bit of information. Never edit the admin files! Check!

    So it sounds like I did it right. We'll see if it actually works...

  8. erixcus
    Member
    Posted 4 days ago #

    can anyone help me on the question above? I am new to WP and i want to insert the Google Analytic codes just before the header.

    Thanks

Reply

You must log in to post.

About this Topic