I'm building a distributed widget that is comparable to Google Analytics. Users will add a <script>
tag to their site that references my widget's JavaScript file.
The Google Analytics tracking code looks like this:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
Can anyone explain the reasoning behind separate HTTP and HTTPS hostnames? My instinct is to just secure the www
address and then use the protocol-less syntax, like //www.google-analytics.com/ga.js
. But I'm sure the Google Analytics architects put a lot of thought into this approach. I'd love to understand their logic before I follow/ignore their model.