Concrete5 + Google Analytics
PermalinkConcrete5 needs to change how it implements tracking.
At present, it seems the 'standard' when coding up a template is to enter the tracker implementation code (that connects to what gets entered in the dashboard) just before the closing </body> tag.
See attachment.
Google changed the game a few months ago, and I think it's time to adjust Concrete5 to follow through here - not so much technically (just updating a couple of lines of text right) but the 'training' or the 'way we do things here').
End of the day, Google wants it's tracking code in the header.
I want to enter this through the Dashboard (it's easy to do this!).
No go at present.
Thoughts? Appreciate some comment from Concrete5 core team here as well.
Theme developers shouldn't need to worry about tracking codes, since the end-user supplies them, not the theme developer.
Just my notes. We should keep
<?php Loader::element('footer_required'); ?>
As on footer, and there are other tracking codes that still required to be at the bottom of the page (correct me if I'm wrong).
Perhaps, we could have "global header" section and rename the existing "tracking code" to "global footer"...
Noo.. this confuses newbies...
Grrrrr....
We need two spots in the Dashboard to add tracking or other code:
1. Additional Header Code
2. Additional Footer Code
We already have calls in the templates for header_required and footer_required. Let's just get a spot to add to the header.
Seems to me that would solve the issue at hand.
The user would then have an easier time going to Sitewide Settings and adding it to Additional Header Code.
That's my thought, at least.
http://www.concrete5.org/community/forums/usage/adding_google_analy...
If you actually look in the footer_required.php file, you'll see that it's pretty minimal. When using this code, it's more semantic and you can put it wherever you want.
As a side note, Paul Irish noted in his HTML5 boilerplate sceencast that he continues to put GA code in the footer because he doesn't count a partial page load as a page view.
Hope this helps.
just sayin.
This new script placement will just help Google report more impressions, since much can go wrong between <head> and </body> tags.
Wonder who that benefits?
But in my own experience, clients won't install this sort of script themselves, which for me makes it a mute point - if you as the developer end up having to do it for them you might as well stick the script in your theme file(s).
Users happy dealing with code/script are probably also able to use Drupal, Joomla backends too. I know that's a massive generalisation, but I put my clients on C5 as they are not at all techy but can still get stuff done on C5 despite that. Script installation isn't on the agenda.
Much like Wordpress's "Edit Themes" option:
http://developer.practicalecommerce.com/uploads/images/0001/4103/1-...
That would be a neat addition to the core or an awesome add on for the marketplace. (hint hint nudge nudge ;-)
I always put the tracking code in the head.
Jon
That being said, yeah the form in the dashboard that is geared specifically for your tracking code should probably have a drop down next to it asking if you want it in the header or footer. I thunk that's more graceful to a mom than spattng fields for everywhere all over
The idea of having a code editor in the dashboard for themes is interesting for separate reasons, particularly if it can be controlled with permissions and workflow.. But that's probably a bigger conversation.
I believe.
Just a heads up.
best wishes
Franz Maruna
CEO - concrete5.org
http://about.me/frz
function addTrackingCodeInHead($page){ if(!$page->isEditMode()){ $v = View::getInstance(); $v->addHeaderItem('<script type="text/javascript"">whatever here</script> ');
Short version: Leave the code at the bottom.
I would hope to see C5 implement something as has been suggested to allow simple input of code snippets, etc, into the header as they currently do in the footer.
Best wishes,
(Pecked out on a mobile device...)
http://about.me/frz
Just get on and do it.
Google's not going to change their requirements any time soon, especially since that:
1) they are convinced this leads to faster load times
2) they say the code has to be in the head to support some of their GA event features
We all want C5 to be as appealing to users as possible - on that we agree :) Since GA is such a widely used and endorsed product, and since other non-Google products also require JS to be placed globally in the head, why not make the option available and make this as easy for users as possible?
Best wishes,
(Pecked out on a mobile device...)
http://about.me/frz
Actually. It doesn't load faster. From a performance point of view any https calls are bad news.....especially in the head.
Miser has had the option to move the code into the head from day dot. However the default is to keep it at the bottom since it was shown in benchmarks to impact performance.
From a tracking point of view. I personally think it's a bit anal. If a visitor clicks away before your page has loaded then they are unlikely to have seen any adverts or content. If you want to rack up numbers so your site looks popular to potential advertisers-then put it in the head. But I prefer to make a site more interesting so users linger.
2) HTTPS called are necessary sometimes. If a page loads under HTTPS and a JS element uses HTTP the page won't be completely secure. Chrome and FF give subtle hints about this, IE throws an ugly warning message defaulting to blocking the unsecured elements. The Google JS loads conditionally in HTTP or HTTPS depending on how the page is called.
3) There are plenty of scenarios where a user may click away before a page loads - especially if you have some other element (non-GA JS loading from a 3rd party server, slow ad platform, poorly optimized images, etc) that can leave a page >90% loaded for an extended period of time.
1. Many GA scripts are being moved into the head not because it is faster. But to bump up page hits on partial loads. ESPECIALLY for those sites that pop-up those annoying adverts on page loading when people know it is an ad and close it before it is complete. It is only achievable now that it is an asynchronous call and no longer blocks (anywhere, including the body). Therefore it makes zero difference where you put it on a page for load times. So no. Your site won't load faster with the asynchronous GA in the head as opposed to the footer, only that a request pipe is used for a long time because it is an https call when it could be being used to show content. But if you want to prove it. I'm open to seeing the numbers. I'll then make the default for Miser to move it into the head. But from experience (and actually running benchmarks like those below, rather than listening to opinions). It does not make the page load faster, only gets a hit registered more quickly.
GA at end of body:
http://www.webpagetest.org/result/110504_VA_HSEG/...
GA in Head
http://www.webpagetest.org/result/110504_QW_HSFJ/...
2. Of course it is necessary. But many sites don't use it at all apart from GA (paypal is another). In those cases, it is better that the https call doesn't lock up a request pipe until everything else interesting has loaded.
3. Then you have bigger problems than worrying about an extra page hit or two.
But it brings up an interesting discussion about page hits. From goggles point of view as soon as a link is clicked they want the number. From my point of view, I want "quality" statistics. By that I mean, I want to know who has actually seen what and what is the most effective. Having 100,000 page hits means nothing to me if no-one is actually looking at my content (i.e adverts etc) since it will not generate clicks. I (personally) would rather see 10 hits and work to increasing it further rather than 100,000 (to get 10 real views) and raising it to 200,000 to get 20.
But, of course. If your selling a site. You just want bigger numbers to make it look more popular than it really is. thats why I think the GA loyalty and time on site are better indicators than hit-count.
I'm not a JS programmer but from my reading one of the benefits of asynchronous JS is that the actual action script (ex: registering of the visit (not hit - that's different)) is run after the page loads. Therefore the position of the code wouldn't increase the visitor count. Anecdotally, of the literally hundreds of sites we manage I haven't seen any kind of blip or jump in visits after converting users to the newer GA code.
2) But many sites DO use those features - including ecommerce sites that want to track events and purchases accurately. Isn't C5 about flexibility, ease of use and customization?
3) Note: I should have been clearer earlier when I mentioned scenarios where users click prior to a full page load... I'm not aware of this happening on any of our sites, but I was merely citing a common example.
Let's be clear - you're the one that made this about hits (but I think you mean visits). I don't sell ads on our sites ... in fact, only one site we operate has ads and that's an internally run ad platform where ads aren't sold on an impression basis, so it makes no difference to me at all.
My business is online marketing - so we want the most accurate stats, and we want the best performance. We use whatever means are necessary to get the GA code in the proper place. What I'm advocating is having C5 give non-tech-savvy users the same opportunity.
after further discussion it became clear that this should actually jive with old themes too..
so ta-da.
1. Indeed. there is always "jitter". You will notice that the time to first byte is less in the second case and that in the first case (in the footer) GA took 2x longer to return!. I'd much rather GA took longer when my page was visible than before. A better "benchmark" is the document complete rather than completely loaded. But if you point me to some real numbers showing significant improvements by putting GA in the head-then by all means post them.
I guess it's a real issue for you. But for me it's just changing a define in site.php So considering I don't think it makes any difference in page load times, it's an arbitrary choice and having it at the bottom is of no consequence.
Saying that though. I do agree that it would be useful to have the capability to stuff things into the head in the same way you can in the footer. The only issue (as I see it) is that people will abuse it and could cause all sorts of problems with clashes in javascript and dependency ordering. Should it go before all other head javascript? After?
The addheaderItems seems a much more logical and controlled method and prevents all that although it does require a bit of extra effort.
For the time being, I'm sure a savvy add-on dev could whip up a hack "package" that does what you're asking, or rather we could educate users on how to do this via the editing the theme.
Also would appreciate thoughts from the core on this.