使用API​​服务器端将事件发送到Google Analytics(分析) [英] Send event to Google Analytics using API server sided

查看:99
本文介绍了使用API​​服务器端将事件发送到Google Analytics(分析)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我使用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 Analytics(分析),您需要自己格式化帖子.提示是使用验证命中进行检查在开发时将其发送给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(分析)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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