我需要帮助来阐明 php 和谷歌分析 (g4) 之间的 utm 跟踪。我的客户希望我使用 php 为 UTM 变量构建一个跟踪仪表板。在 WordPress CMS 上运行的网站。
我简单地使用 PHP $_GET HTTP GET 变量来捕获这些参数并将它们存储在数据库中:
$utm_source = ( isset($_GET['utm_source']) ) ? sanitize_text_field($_GET['utm_source']) : '';
$utm_source = (!empty($utm_source)) ? $utm_source : 'no source';
//further saving to the database
为了详细调试,我还在 wordpress 初始化挂钩的 txt 文件中记录了所有传入的 GET 变量:
add_action( 'init', 'init_tracking_all_gets_variables' );
function init_tracking_all_gets_variables() {
$fp = fopen('gets_variables.txt', 'a');
$time = current_time("D M d, Y H:i:s");
$string = '==================================' . "\n";
$string .= $time . "\n";
$string .= serialize($_GET) . "\n";
fwrite($fp, $string);
fclose($fp);
}
所以看起来这段代码按我预期的那样工作,我们看到传入的 utm 标签。但在 G4 中,有时我们会以某种方式看到奇怪的会话源/媒体,例如:ecosia.org / organic、yahoo / organic、posten / valgfritt、l.facebook.com / referral 等,用户访问量非常小。他们从不在我的跟踪仪表板上跟踪,甚至在我的 gets_variables.txt 文件中也不会跟踪,该文件应该将所有传入的获取变量绝对写入该站点。问题出在哪里?