アシノスキマ A monologue of giraffe.LA (jimdo) web top

Google Analytics のjsを外部ファイルにする。

Google Analyticsのタグを埋めていくの面倒だし、なかhtmlにかくのいやだ。と思った。

普通のjsみたいに外部に吐き出せるはずだ、とやってみた。

 

動かない。。。。

(そのままjsに落としただけだから。)

 

I have no idea.

 

特にそれ以上調べたりせずに、放置していたけれど、やっぱり吐き出したい。

 

と、思ったので、調べてみた。

 

あった。。。。

 

 

如何やら外部にふたつに分けて吐き出している様子。

(明は言語やシステムのことに関しては無知です。)

 

貼り付けろ、と提示されるソースを、ふたつにわける。

 

仮に、A.jsとB.jsに分ける。

【A.js】の中身は共通で、【B.js】の中身、UA-xxxxxxxx-x部分はそれぞれ変動。

analyticsにリファラー追加してだしてくれたものと合わせる。

 

【A.js】

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"));

 

【B.js】
var pageTracker = _gat._getTracker("UA-xxxxxxxx-x");
pageTracker._initData();
pageTracker._trackPageview();

 

これだけ。

これを、他のJS同様読み込む。

 

<script src="js/lib/A.js"></script>
<script src="js/B.js"></script>

(ファイル階層は・ファイル名は任意)

 

のだけど、

body最下部(</body>直前)と、

body上部(<body>直前)と、

 

どちらに書くのがセオリーなのだろう?

 

明は何故か最下部。

 

 

コメントをお書きください

コメント: 1
  • #1

    buytadalafilonline (水曜日, 07 11月 2012 04:01)

    I intended to draft you this bit of remark in order to say thank you once again for the pretty guidelines you've documented here. It is quite strangely open-handed of you to present unhampered precisely what a lot of people could have made available as an electronic book to generate some cash for themselves, and in particular now that you could have tried it if you decided. Those good tips likewise served as a good way to recognize that some people have a similar dream the same as my personal own to understand a whole lot more concerning this condition. I am sure there are lots of more fun periods ahead for many who take a look at your website.

jump_top