【发布时间】:2011-08-14 18:27:44
【问题描述】:
我想将一些事件跟踪从我的 PHP 脚本推送到我的谷歌分析帐户。我包含一个外部 PHP 文件,该文件在我的头脚本中包含谷歌分析代码,该文件包含在我的所有站点 PHP 文件中 -
header.php:
<?php
include_once("analytics_script.php");
...
?>
index.php:
<?php
include("header.php");
//When i want to track an event from this script -
_gaq.push(['_trackEvent', 'Category', 'Action', 'Label']);
?>
analytics_script.php:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-********-**']);
_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>
所以在 index.php 中将只使用 _gaq.push 跟踪事件 ok 还是我需要将行包装在 javascript 标记中,例如 -
<script>_gaq.push(... </script>
谢谢
【问题讨论】:
标签: php javascript asynchronous google-analytics event-tracking