我正在使用 GA 测量协议(protocol)从 iOS 应用向 Google Analytics 发送请求。
我希望能够为所有移动设备创建分割,其中包括来自移动网站和应用程序的点击。我不知道如何告诉 GA 我的自定义用户代理对应于移动设备(以及操作系统版本、应用程序版本、分辨率等)。
有没有办法将这些自定义用户代理映射到设备?或者是否有某种我可以使用的标准用户代理来传达这些信息?
最佳答案
如果您只想判断综合浏览量是来自网站还是应用程序,引用资料如下:https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ds
这是用于解析的参数:https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#sr
我认为没有涵盖应用程序版本或操作系统的任何默认参数,但您可以为这些自定义维度:https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cd_
所以在 php 中,你会做这样的事情:
$url = "www.google-analytics.com/collect";
function request($url, $post_fields) {
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
return $response;
}
$post_fields = array(
"v" => 1, //version
"tid" => $tid, //tracking id
"cid" => $cid, //client id
"t" => "pageview", //hit type
"ds" => $ds, //data source
"sr" => $sr, //screen resolution
"cd1" => $cd1, //custom dimension 1
"cd2" => $cd2, //custom dimension 2
"cd3" => $cd3, //custom dimension 3
);
$post_fields = http_build_query($post_fields);
request($this->url, $post_fields);
当然,您可以在 post_fields 数组中添加您想要的任何其他参数。然后您还需要进入 Analytics 并在 Admin > Property > Custom Definitions 下注册您的自定义维度。此外,您还需要检查 CURLOPT 值以确保它们是您想要的。
关于ios - 使用谷歌分析的自定义用户代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35071625/