views:

99

answers:

2

Is there a way in javascript to detect all images in a document, including those that may be loaded asynchronously (and maybe after the DOM is ready)?

I'm looking to create a function that can detect if Google Analytics has been loaded by searching through the DOM looking for "__utm.gif". document.images doesn't seem to hold this image as it's loaded asynchronously and not displayed.

A: 

Is there any reason you don't want to implement GA detection by checking for the HTTP request to which this gif (i.e., __utm.gif) is appended?

It's this request that's responsible for sending all of the data GA collects to the GA servers, and of course the request is made every time the page is requested or an event is fired on that page.

Again, this request has a very distinct signature--it always begins like this:

utm.gif?utmwv=4&utmn">http://www.google-analytics.com/_utm.gif?utmwv=4&utmn

Here's a complete example from the GA Site.

doug
Thanks for the link, do you have an example of the code to check all the HTTP requests of a document? I would think that would be a security restriction?
Zach
A: 

If you're looking to detect GA, you can simply test for window._gat and window._gaq.

Brian
I would say this would suffice, but just because I have declared the _gat or _gaq variable, doesn't mean my page has been tracked.
Zach