问题描述
我有一个网站,我使用 javascript 函数将事件发送到 Google Analytics:
I have a website where I send events to Google Analytics using javascript function:
ga('send', 'event', 'showphone', 'feedback', 'result');
但是我还需要使用 PHP 从 server-side
发送一些类似的事件.我尝试了这个快速入门教程:Hello Analytics API:PHP 快速入门对于服务帐户 和报告的作用就像一个魅力,但我不知道如何发送事件.
However I also need to send some similar events from server-side
using PHP. I tried this quick start tutorial: Hello Analytics API: PHP quickstart for service accounts and reporting works like a charm, but I have no idea how to send event.
能否请您逐步向我展示我应该编写什么代码来发送与上述完全相同的事件.
Could you please show me step-by-step what I should code to send exactly same event like mentioned above.
推荐答案
Hello Analytics API:服务帐户的 PHP 快速入门 根本不会帮助您.该代码使用核心报告 API,核心报告 API 用于请求来自 Google Analytics 的数据,而不是向 Google Analytics 发送数据.
Hello Analytics API: PHP quickstart for service accounts is not going to help you at all. That code uses the core reporting API the core reporting API is for requesting data from Google Analytics not sending data to Google Analytics.
要将数据发送到 Google Analytics,我们使用测量协议.测量协议用于向 Google Analytics 发送信息,您发布的 JS 代码段也使用测量协议.
To send data to Google Analytics we use the Measurement Protocol. The measurement protocol is used to send information to Google analytics the JS snippet you posted also uses the measurement protocol.
您可以使用任何支持 HTTP post 或 Http Get 的语言的测量协议.话虽如此,但没有特定于 PHP 的库可用于将信息发送到 Google 分析,您将不得不自己格式化您的帖子.一个提示是使用 Validating hits 来检查它在开发过程中将其发送给 Google 之前.
You can use the measurement protocol from any language that supports HTTP post or Http Get. That being said there is no PHP specific library for sending information to Google analytics you are going to have to format your post yourself. A tip would be to use Validating hits to check it before you send it to Google while you are developing this.
它可能看起来像这样
http://www.google-analytics.com/collect?v=1&tid=UA-XXX-Y&cid=35009a79-1a05-49d7-b876-2b884d0f825b&an=My%20Awesom%20APP&aid=com.daimto.awesom.app&av=1.0.0&aiid=come.daimto.awesom.installer &t=event&ec=list&ea=accounts&userclicked&ev=10
这篇关于使用 API 服务器端向 Google Analytics 发送事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!