所以我有:
<?php
header( 'Location: http://my-link' );
?>
我需要跟踪该页面,但我找到的教程教你如何在链接中执行此操作,正如您所看到的,我没有链接,我使用页面重定向。
跟踪代码
<script type="text/javascript">
function recordOutboundLink(link, category, action) {
try { var myTracker=_gat._getTrackerByName();
_gaq.push(['myTracker._trackEvent', category , action ]);
setTimeout('document.location = "' + link.href + '"', 100)
}catch(err){}
}
</script>
它适用于链接:
<a href="http://www.your-affiliate-link.com" onClick="recordOutboundLink(this, 'Affiliate Links', 'your-affiliate-link.com');return false;">
有没有办法在php标题部分实现它,而不是集成在链接中?
例如:
header( 'Location: http://my-link; onClick="recordOutboundLink(this, 'Affiliate Links', 'your-affiliate-link.com');return false;' );
修改
以下是我要实现的目标:https://productforums.google.com/forum/#!topic/analytics/tXX--cOnkDs
编辑2
这是解决方案,我希望它可能对其他人有用:
<script type="text/javascript">
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-57067301-1', 'auto');
ga('send', 'pageview');
</script>
<script type="text/javascript"> function recordOutboundLink(link, category, action) { try { var myTracker=_gat._getTrackerByName(); _gaq.push(['myTracker._trackEvent', category , action ]); setTimeout('document.location = "' + link.href + '"', 100) }catch(err){} } </script>
<script type="text/javascript">
recordOutboundLink(this, 'Affiliate Links', 'http://hotmart.net.br/show.html?a=F2357823M');
setTimeout(function(){window.location='http://hotmart.net.br/show.html?a=F2357823M';}, 500); // working with a 500ms timeout to make sure the tracking is done correctly
</script>