Šime Vidas
Šime Vidas

Reputation: 185933

Issue with IE conditional comments and Google Analytics

I have a web-page that starts like so:

<!DOCTYPE html> 

<html>      
<head>      
    <!--[if lt IE 10]>
    <script>
        location.href = "http://www.getfirefox.com";
    </script>
    <![endif]--> 

That page gets ~500 pageviews/month and for the last 6 months I had no IE visitors according to Google Analytics. However, a few days ago I got a report of an IE6 visit. How did that happen?

Did the redirection code in the conditional comment fire to late?
Did Google Analytics code mistakingly identified a non-IE browser as IE6?

Upvotes: 0

Views: 425

Answers (2)

Stephen P
Stephen P

Reputation: 14800

You register no IE visits because your script with location.href = ... runs before the Google Analytics code gets a chance to run.

You could have registered that IE6 visit if

  1. IE 6 failed to do the location.href assignment (I've seen problems reported with this) but did run the analytics js code.

  2. An IE 6 visitor had javascript turned off (in this case they wouldn't run the analytics code either, so wouldn't register a visit)

  3. Another browser is impersonating IE 6, e.g. in the User-Agent string, but doesn't process the conditional comments.

You can move your conditional comment and the script within it to the end of the page, after the analytics js code if you want Google to count it but still send them off to getfirefox.com

You can also just say

<!--[if IE]
...

don't test a specific version if you always want to send IE away.

Upvotes: 2

Stephan Muller
Stephan Muller

Reputation: 27600

He had javascript disabled.

Also, nice usability. You know they're not going to download firefox and then come back, right?

Upvotes: 1

Related Questions