是否可以使用php-ga API库实现用户ID跟踪?我想将其与客户端跟踪联系起来。
php-ga library - https://github.com/thomasbachem/php-ga
用户ID - 网络跟踪(通过analytics.js) - https://developers.google.com/analytics/devguides/collection/analyticsjs/user-id
由于
答案 0 :(得分:1)
您可以在没有任何库的情况下推送事件。只需使用measurment协议:https://developers.google.com/analytics/devguides/collection/protocol/v1/以下是我在服务器端执行的操作:
<?php
$data = array(
'v=' . 1,
't=' . 'approved', //Page
'tid=' . 'UA-XXXXXXXX-X', //GA account code
'cid=' . $ga_user_id, // 1267034788.1479821336 needs to be extracted from $_COOKIE['_ga']
'ec=' . 'credit', // for event only - event category
'ea=' . 'denied', // for event only - event action
'el=' . '12345', // for event only - event label
);
$ch = curl_init('www.google-analytics.com/collect');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
以下是我用于构建网址的构建工具:https://ga-dev-tools.appspot.com/hit-builder/