Well, in this third installment of “Useful Protocol-Intelligent Javascript Code,” (not intending it to become a series, ha) I was sent a link by Matt Hinze where someone has already written some code that will do this exact thing, particularly for Google analytics js code. Take a look:
<script type=”text/javascript”>
document.write( ‘<scr’+’ipt type=”text/javascript” src=”‘ );
if( document.location.toString().indexOf( ‘https://’ ) != -1 ) {
document.write( ‘https://ssl’ ); } else { document.write( ‘http://www’ ); }
document.write( ‘.google-analytics.com/urchin.js”></scr’+’ipt>’ );
</script>
<script type=”text/javascript”>
_uacct = “UA-XXXXXXX-X”;
urchinTracker();
</script>
<script type=”text/javascript”>
document.write( ‘<scr’+’ipt type=”text/javascript”>’ );
if( document.referrer.toString().indexOf( ‘www.westerfunk.net’ ) ==-1 ) {
document.write( ‘urchinTracker(document.referrer);’ ); }
document.write( ‘</scr’+’ipt>’ );
</script>
I have set this up on Westerfunk.net and will see what the results look like tomorrow, to see if the code is actually rendering properly. So far it appears it is actually making the calls out to google on every page hit, but only G-analytics results will shed light on this theory.
Blog entry where the code came from:
(Original): http://www.reubenyau.com/google-analyti … rrer-only/
(Archived): http://www.westerfunk.net/archives/tech … er%20Only/
Update:
————————————————————-
This appears to be working very well and all my stats look back to normal on google-analytics. So this code is good …
Leave a Reply