1

如何将此 php 变量作为自定义变量放入此 javascript 代码中?

我在我的登陆页面上为每个访问者生成了一个动态编号。这可作为 php 变量使用;

$点击数

我已经有以下代码与 GA (javascript) 一起使用;

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
  _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>

我的问题:如何将此 php 变量作为自定义变量放入此 javascript 代码中?

4

1 回答 1

3
<script>

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);

  _gaq.push(['_setCustomVar', 1, 'clicknumber', <?= $clicknumber ?>, 2]);

  _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>

更多信息:https ://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables#setup

于 2013-02-19T14:01:46.133 回答