正在开发自定义代码以发送用户搜索详细信息以及商店何时发生 404。为此,我有类似以下的内容
<?php
$page = '404';
if ($page == '404') {
$result[] = "ga('send', 'pageview', { 'page': '404/?url='+ document.location.href + document.location.search +'&ref=' + document.referrer, 'title': '404 Error'});";
}
$searchText = 'abc';
$searchResultCount = 0;// or number of records on search query
if ($searchText != '') {
if ($searchResultCount == 0) {
$result[] = "ga('send', 'pageview', { 'page': $searchText, 'title': 'Search No rsult'});";
} else {
$result[] = "ga('send', 'pageview', { 'page': $searchText, 'title': $searchResultCount.' Found on Search'});";
}
}
$moreTracking = implode("\n", $result);
?>
<!-- BEGIN GOOGLE UNIVERSAL ANALYTICS CODE -->
<script type="text/javascript">
//<![CDATA[
(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-<?php echo $accountId; ?>-1', 'auto');
ga('send', 'pageview');
<?php echo $moreTracking; ?>
//]]>
</script>
<!-- END GOOGLE UNIVERSAL ANALYTICS CODE -->
我添加正确吗?用于跟踪 404 错误和搜索结果或未找到用户查询的搜索记录。