web:modx:revolution:minitips:googleanalytics
MODxでgoogle analyticsを使う
google analyticsのコードをチャンク化する。
ま、普通ならそのまんまチャンクにすればOKなんだけど、MODx Revolutionではチャンクもパラメータをとれるので、一工夫してAccountIDをパラメータで渡すようにしてみました。1)
こんな感じで使ってください。
[[$chunk_google_analytics? &profile_ID=`UA-XXXXX-Y`]]
コード
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', '[[+profile_ID]]']); _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); })(); </script>
1)
って、IDのところにタグを埋め込むだけだが 
web/modx/revolution/minitips/googleanalytics.txt · 最終更新: 2017/04/14 05:21 by 127.0.0.1