Skip to the content...

Welcome to the David Walsh Blog. I'm a MooTools, Dojo, jQuery, CSS, and PHP Web Developer located in Madison, Wisconsin, United States. Please contact me if I can make your experience on my website better.

Secure (SSL) Google Analytics

9 Responses »

Google Analytics is a tremendous tool, especially when your customer wants an eCommerce website. Analytics is even more powerful when your customer uses Adwords to drive in traffic.

Google provides the following code for you to add to your page footer so that Analytics can grab statistics:

%MINIFYHTMLe903e0d5057cb2eded1444f2e11df3774%%MINIFYHTMLe903e0d5057cb2eded1444f2e11df3775%

The problem with this is that if you're pulling this code in on a secure page, a security warning will pop up mentioning that the page is loading both secure and non-secure items. How do you prevent this issue (as well as trust issues with the user)? Simply import the secure version of Google Analytics:

%MINIFYHTMLe903e0d5057cb2eded1444f2e11df3776%%MINIFYHTMLe903e0d5057cb2eded1444f2e11df3777%

For websites that have some pages secure and others not HTTPS protected, I recommend always calling the secure version of Google Analytics' urchin.js.

Discussion

  1. April 14, 2008 @ 6:14 am

    Nice post! Google Analytics has a new tracking code option, ga.js instead of the urchin.js, that handles the ssl component. Here’s a look:

    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

    var pageTracker = _gat._getTracker("UA-xxxxxxx-x");
    pageTracker._initData();
    pageTracker._trackPageview();

  2. muddy
    June 6, 2008 @ 7:19 pm

    The answer to my ssl headaches! Didn’t think to check if Google Analytics offered a secure tracking code. Will be so happy to say goodbye to that annoying “non-secure” pop-up.

    Thank ya thank ya thank ya.

Be Heard!

Share your thoughts with fellow developers of all skill levels! I want to hear from you!

Name*:
Email*:
Website:  
Wrap your code with <code> tags, f00!