GoogleアナリティクスIDをスクリプトに動的に挿入しようとしています。 {{configs [0] .ga_id}}がidを格納する場所のようなものです。GoogleアナリティクスIDをスクリプトに挿入する角度を
<script>
google code....
ga('create', '{{configs[0].ga_id}}', 'auto');
</script>
これは機能しません。私もこれらのすべてを試みたが、すべて失敗している。
'{configs[0].ga_id}',
'configs[0].ga_id',
+ configs[0].ga_id +
UPDATE:MarkoCen
あたり、私はこのディレクティブを追加し、私のHTMLは次のようになります。要素を検査するときにIDが正しく、 "UA-XXXXXXXX-1" が、指令ののにconsole.logに私が見る表示され、この "{{コンフィグ[0] .ga_id}}"
<google-analytics id="{{configs[0].ga_id}}"></google-analytics>
app.directive('googleAnalytics', function(){
return {
restrict: 'E',
replace: true,
template: function(elem, attr){
console.log(attr.id);
return "<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create', '" + attr.id + "', 'auto');</script>"
}
}
})
あなたのGAスクリプトをangularJSコントローラに置く必要があります。 http://stackoverflow.com/questions/10713708/tracking-google-analytics-page-views-with-angular-js –
'console.log(elem [0] .id)'を試してください – MarkoCen
それは戻って来ませんでした – Jason