Check for Google Analytics Using MooTools 1.2
When I launched my new design last week, I used PHP to comment out Google Analytics because I didn't want to skew the stats. Well, I did skew my stats that day because I forgot to uncomment the damn GA code. Rook move, I know. With that in mind, I've created a MooTools script that checks to make sure Google Analytics is loaded. If not, you get a friendly JavaScript alert() reminder.
The MooTools 1.2 Code
window.addEvent('load', function() {
if(typeof(eval(window)['_ufsc']) == 'undefined') {
alert('David, turn on GA!');
}
});
Not having 10 hours worth of stats is a big deal. This code will (hopefully) prevent this from happening again in the future.
![7 Essential JavaScript Functions]()
I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener
and attachEvent
. Times have changed but there are still a few functions each developer should...
![Create a Sheen Logo Effect with CSS]()
I was inspired when I first saw Addy Osmani's original ShineTime blog post. The hover sheen effect is simple but awesome. When I started my blog redesign, I really wanted to use a sheen effect with my logo. Using two HTML elements and...
![Implementing Basic and Fancy Show/Hide in MooTools 1.2]()
One of the great parts of MooTools is that the library itself allows for maximum flexibility within its provided classes. You can see evidence of this in the "Class" class' implement method. Using the implement method, you can add your own methods to...
![AJAX Page Loads Using MooTools Fx.Explode]()
Note: All credit for Fx.Explode goes to Jan Kassens.
One of the awesome pieces of code in MooTools Core Developer Jan Kassens' sandbox is his Fx.Explode functionality. When you click on any of the designated Fx.Explode elements, the elements "explode" off of the...
Why aren’t you using the same if statement as you do for your config file as mentioned in a previous post?
http://davidwalsh.name/knowing-website-state-php
As a matter of fact, you commented on your own post saying you use it for Google Analytics!
@Jeff: Because I wasn’t developing locally, per say. I was dragging each file to my desktop, and then reuploading as I changed it. Again, not the best way of doing things.
I do, however, use my “website state” strategy at work.
@Jeff: Simply put….I was lazy with my own site and paid the price for it.
Works great unless you are the type to upload something and not confirm the changes (and then have all your visitors get the popup). Hey, if you can make one lazy mistake you can make another, haha.
@Sameer: Very true!
A much simpler and easier to manage solution is to set up a filter in google analytics itself.
For example, “exclude all traffic from user agents marked ‘website-tester.'” Then simply use Firefox’s user-agent switcher extension to use ‘website-tester’ whilst testing.
This also allows more flexibility than the “website state” strategy as PHP, Google Analytics etc… can be clever about your own use of the site for testing purposes even on a website that is live and working for everybody else.
Obviously the website state idea still has validity when when you have two near identical sites, one for production and the other live. As an example my platform generates a robots.txt automatically and on the staging site adds the “Disallow: /” directive to prevent the staging site from being indexed and all those duplicate content issues.
Hey David, this post is a few years old now and it still works! :D but have you come across any new ways of detecting Google Analytics?