Jump to content

Google Analytics - Best place for code?

Recommended Posts


If I'm using PL5 with PL5 Framework, what is the best way to include Google Analytics code?


I know we have an Advanced section in Settings but that just allows for Header scripts. Should we also have a footer (after body) section to place scripts like GA.


Share this post

Link to post
Share on other sites

there's a ton of ways to do this one, you could use a plugin or a hook like wp_footer.

Share this post

Link to post
Share on other sites

Does it make any difference if it's in the header or footer?

Share this post

Link to post
Share on other sites
On 2/25/2016 at 2:01 PM, hibbsy78 said:

Any more progress on this one? The amount of sites viewed on mobile is ever increasing so this is a big issue.

Good ole Big G recommend after closing body tag - so I'm goin with what they say. ;)

Share this post

Link to post
Share on other sites

Update: I've now put it in the same place Pagelines.com uses in the Header section of PL5 settings. If it's goo enough for PL it's good enough for me. It's works just fine.

Share this post

Link to post
Share on other sites

Ideally tracking codes are placed at the footer. It is to allow your site to render while the browser is waiting for off-domain assets (which in this case, tracking codes from analytics). It is a recommended format where:

  • header: scripts essential for the site to function and render. removing these will severely break site functionality / design.
  • body: content (well, lol)
  • footer: the rest of the non-essential scripts that the site doesn't need to function/render. Or other scripts that can be triggered to load later after everything else.

As far as I know the browser engine renders the page from header > body > footer in order. So if a part of the header doesn't load in time, it prevents the body from rendering at all. Unless you have a server that somehow speeds up loading site assets, or if your server's running on HTTP/2.

TL;DR: Place it in the footer, unless you have something else up your sleeve.

Share this post

Link to post
Share on other sites

you can copy footer.php to your child theme and add scripts there, especially if you're loading js that requires being loaded from footer

Share this post

Link to post
Share on other sites

Just add the GA script in the PL5 Advance Settings.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • Queue-it
      By Queue-it+
      Where do I add the google experiment code for A/B testing so it would be above the original google analytics tracking code? 
      1. I've tried to put in the Pagelines Advanced settings
      2. and in the functions php file, but none of that worked. 
      I'm using a SEO yoast plugin to connect wordpress with GA and there are no settings to add the code before the original one.
    • atcdomainsolutions
      By atcdomainsolutions+
      When adding Google Analytics to a site, it's best to add it into the Custom Javascript/Header HTML area (below the Custom LESS box) to ensure it is tracked on all pages, correct?
      If not, where should I add it?  
    • Ron
      By Ron+
      I had Google Analytics working on a site which I just completely redid using DMS.  I took the site live last Monday night and forgot to put in the tracking code for the first few days and then last Friday put it in (added to the Custom CSS box) and checked the source code for the home page and it was showing in there.
      Today there is still no data showing up in Analytics for the past week including today and I contacted tech support for Analytics and the rep said the source code was not showing the Analytics tracking code.  I then realized that I was logged in and he was not so I logged out of WP and rechecked the source code for the page and when I checked it this time it was not showing up.
      I checked further and noticed that I would insert the code into Custom CSS and then save it and Publish and when I logged out and back in it wouldn't be there but there would be something starting with 'Minify'.  My minify plugin was already deactivated so I deactivated my auto-optimize plugin and then the Analytics code would stay correct in the Custom CSS when I logged out and in again.  But even after this it still wouldn't show in page source code when I logged out.  I even cleared the cache to make sure that wasn't the issue but it didn't fix this problem.
      I'm using DMS version 1.1.5 with the child theme version 1.0.1 and WP version 3.8.1.  The site is http://clearwaterbeachcondosforsale.com.  Would love to get some help in sorting this out.  Analytics has people to help with getting the code working but I know from past experience that when the issue is theme-related it is better to get help from the theme people because either the Analytics people will say they can't help or they will suggest something that may cause other problems.
      Any suggestions?
    • eveliut
      By eveliut
      Hi there,
      Whatever I do, my Google Analytics Status says: Tracking Not Installed. I've been playing with it for a couple of weeks now. I've pasted my snippet to Editor > Footer.php, as well as to Site Options > Custom Code > Footerscripts Code or Analytics. I've also tried several plugins. I went back and I made sure I followed all the steps. Nothing seems to be working. According to Google forums, a lot of people seem to be facing this problem. Unfortunately, one cannot expect much help from Google. :)
      Am I missing something? Do you have any ideas? Any help appreciated. ;)
    • teobishop
      By teobishop
      I've loaded the plugin "launchpad" LaunchPage onto a new site I'm working on, and I'm running into a problem with Google Analytics.
      The launchpad LaunchPage looks fine, and functions well from a design standpoint, but Google isn't able to find my tracking code. I've entered it into the Pagelines "Site Options" page, just as I have for all of my other sites running Pagelines. But, Google can't find the code.
      I even added a separate Google Analytics plugin to see if I could circumvent whatever the problem was in Pagelines, but Google still can't track the site.
      Is anyone having a similar problem?