Stopping Internet Explorer’s Insecure Content Warning with Google Analytics
May 24th, 2007
Don’t you just love the insecure content warning you see all the time in Internet Explorer? Clearly, the engineers at Microsoft were looking out for our best interests when they decided to throw a warning each and every time an image or JavaScript file happened to be linked from the non-SSL side of your site.
If you’ve implemented Google Analytics, you may have run into this problem. By linking to the urchin.js file from an otherwise secure page, you can trigger the insecure content warning in IE. Yea!
The solution is quite simple. In your PHP head section, first look to see if the $_SERVER['HTTPS'] value is set and has a value of “on.” Then set a value that contains the path to the secure version of the urchin.js file as follows:
if(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']==’on’))
{ $gaSrc = ‘https://ssl.google-analytics.com/urchin.js’;
} else {
$gaSrc = ‘http://www.google-analytics.com/urchin.js’;
}
Bonus tip: by placing this in the head section, you can also set an absolute path to your images directory or any other dependent paths, helping further eliminate the possibility of triggering IE’s insecure content warning.
In the footer of any PHP page that links to Google Ananalytics, simply echo the $gaSrc variable set above as follows:
<script src=”<?php echo $gaSrc; ?>” type=”text/javascript”></script>
<script type=”text/javascript”>
_uacct = “[YOUR ACCOUNT NUM]“;
urchinTracker();</script>
Be sure to replace “[YOUR ACCOUNT NUM]” with your Google Analytics tracking number. That’s it!
Sphere: Related Content
