![](/img/trans.png)
[英]Site returns a dialog box, similar to a mime file save rather than excute a php file and return html
[英]Using Google Analytics Global Site Tag in PHP file rather than HTML
我正在嘗試對由 PHP 文件而不是 HTML 組成的網站實施谷歌分析。 我是否仍然可以簡單地通過添加 head 元素並將代碼粘貼到 PHP 文件中來使用全局站點標記,或者我是否需要采取替代方法將谷歌分析跟蹤添加到該站點?
創建 ga_include.php
將您的 gtag 粘貼到此文件示例中:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxx-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-xxxxxxx-1');
</script>
將此包含在您要呈現的頁面的 head 部分中,在一個常見的“head.php”或“mypage.php”示例中:
<head>
<title>hello world</title>
<?php include_once("ga_include.php") ?>
</head>
ga_include.php 的路徑如果不在同一個位置修改為合適的路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.