Google Analytics(分析)在新的Web + App中跟踪自定义事件 [英] Analytics track custom events in new Web+App

查看:177
本文介绍了Google Analytics(分析)在新的Web + App中跟踪自定义事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经通过cURL来跟踪google analyticsPHP的自定义事件(API命中),但是现在分析已弃用此方法.我了解到,新的分析Web + App用于跟踪此类事件,但是我找不到任何可以跟踪这些事件的信息. 我当前的代码:

I used to track custom events (API hits) with google analytics and PHP via cURL, but now analytics is deprecating this method. I understood that the new analytics Web+App is used to track this kind of events, but i cannot find anything that allows me to track those events. my current code:

$response = $client->post('https://www.google-analytics.com/collect', [
    'form_params'   => [
        'v'     => 1,
        't'     => 'event',
        'ec'    => 'ap1-v1-xxx',
        'ea'    => 'invoke',
        'el'    => 'MY-API',
        'tid'   => 'XXXXXXXX',
        'cid'   => '555'
    ]
]);

这样做,我能够跟踪每个命中并获得有关API使用情况的统计信息,这就是分析面板的外观:

Doing this, i was able to track every hit and have statistics about API usage, this is what the analytics panel looked-like:

但是,正如我所说的,分析技术已弃用此方法,并且它停止了跟踪我的点击数:

But, as i said, analytics is deprecating this method, and it stopped tracking my hits:

https://support.google.com/firebase/answer/9167112 ?ref_topic = 6386699

有没有办法跟踪这些自定义事件?我在PHPcURL中找不到任何类似的东西.

There is a way to keep track these custom events? I can't find anything alike in PHP or cURL whatsoever.

谢谢!

推荐答案

方法(测量协议)已被弃用,并不是因为它使用的是新的(至今尚未公开)测量的版本2协议.

It's not so much the method (measurement protocol) has been deprecated, it's that it is using a new, as of yet apparently undocumented, version 2 of the measurement protocol.

这很有道理-您无法再发送匹配类型(因为现在只有一个类型的事件,其名称可以自定义),并且您无法发送事件类别,操作和标签,因为它们不再存在,并且已经替换为事件参数.

That makes sense - you cannot sent hit type anymore (because there is now a single type event, whose name can be customized), and you cannot send event category, action and label, since those no longer exist, and have been replaced by event parameters.

由于似乎还没有文档,因此您可以进行一些逆向工程.我在Web& app属性(实际上是gtag.js)中查看了由代码发出的针对网页浏览的请求:

Since there does not seem to be documentation yet, you can do a bit of reverse engineering. I looked at the request issued by the code from a web&app property (actually gtag.js) for a pageview:

https://www.google-analytics.com/g/collect? // endpoint, remains the same
v=2 // protocol version, v2
&tid=G-XXXXXXXXXX // tracking id
&_p=1253409603 // no idea, don't think this needs to be set
&sr=1920x1080 // screen resolution, not applicable to a serverside call
&ul=de-de // user agent language, probably not relevant for a serverside call
&cid=533127994.1575982871 // client id
&_s=1  // no idea
&en=pageview // event - this corresponds broadly to hit type t in the previous version
&dl=http://localhost/test2.html // document location
&dr= // document referrer, not relevant for a serverside call
&dt=Title // document title
&sid=1575982870 // no idea
&sct=1 // no idea
&seg=1 // no idea

我认为对于服务器端应用程序,您可以忽略所有标有"no idea"(我认为这是由Javascript跟踪代码确定的参数)的参数.

I think for a serverside application you can ignore all parameters marked with "no idea" (I assume that is something determined by the Javascript tracking code).

您需要设置"v = 2",而不是"v = 1",而对于点击类型,您需要设置"en"作为事件名称,而不是"t".我将看看是否可以确定如何发送事件参数(我在办公室,没有时间进行实验),但是无论如何这应该足以让您入门(我通过curl和它显示在web& app属性的实时"部分中,因此它也应该对您有用).

Instead of "v=1" you need to set "v=2", and instead of "t" for hit type you need "en" for event name. I will see if I can work out how to sent event parameters (I am in the office and don't really have time to experiment), but in any case this should be enough to get you started (I tested a call via curl and it showed up in the realtime section of a web&app property, so it should work for you, too).

这篇关于Google Analytics(分析)在新的Web + App中跟踪自定义事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆