【问题标题】:Custom user agents with google analytics带有谷歌分析的自定义用户代理
【发布时间】:2016-01-28 20:43:11
【问题描述】:

我正在使用 GA 衡量协议从 iOS 应用向 Google Analytics 发送请求。

我希望能够为所有移动内容创建一个细分,其中包括来自移动网站和应用的点击。我不知道如何告诉 GA 我的自定义用户代理对应于移动设备(以及操作系统版本、应用程序版本、分辨率等)。

有没有办法将这些自定义用户代理映射到设备?或者是否有某种标准的用户代理可以用来传达这些信息?

【问题讨论】:

    标签: ios google-analytics google-analytics-api user-agent


    【解决方案1】:

    如果您只是想判断网页浏览量是来自网站还是应用程序,请参考: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 并在管理 > 属性 > 自定义定义下注册您的自定义维度。此外,您还需要检查 CURLOPT 值以确保它们是您想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多