0

私はドメインを持っています。それを myhost.com と呼びましょう。myhost.com にスクリプト addGAcode.js があります。コードには、クライアント ドメインに設定されたアカウントの標準 GA コードを呼び出す関数 includeGA() が含まれています。次のようになります。

function includeGA() {   
var _gaq = _gaq || [];  
_gaq.push(['_setAccount', 'UA-432432432-43']);  
_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);   })(); 
}

includeGA();

このドメインをgrocerinbelfast.comと呼びましょう。

今、myhost.com/addGAcode.js を含めるために、groceryofbelfast スクリプト タグのメタに追加します。残念ながら、GA は機能しません。GA コードは適切にロードされていますが、それが他のドメインにあるため、統計が機能するために必要な食料品店のドメインに Cookie を設定できないと思います。

私のコンセプトのポイントは、Google が何かを変更したり、何らかの調整を加えたい場合に、適切な変更を行うためにクライアントのウェブマスターに毎回電話する必要がないように、サーバーに GA スクリプトを配置することです。

何か案は?

4

1 に答える 1

1

関数内でローカル変数ではなくグローバル変数として宣言する必要があるincludeGA()ため、関数はおそらく機能しません。_gaqincludeGA()

これに変更することで、その特定の問題を修正できます。

function includeGA() {   
    window._gaq = window._gaq || [];  
    _gaq.push(['_setAccount', 'UA-432432432-43']);  
    _gaq.push(['_trackPageview']);

    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);
}
于 2012-10-10T15:08:04.370 に答える