沃梦达 / 编程问答 / php问题 / 正文

Google Analytics PHP(发送信息)

Google Analytics PHP (Sending information)(Google Analytics PHP(发送信息))

本文介绍了Google Analytics PHP(发送信息)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,我需要使用 Google Analytics 服务器端.我不需要检索信息,但我需要发送信息.我最终可以发送 js 脚本客户端,但在这种情况下它不是一个选项.

I am working on a project and I need to use Google Analytics server side. I do not need to retrieve information, but I need to send information. I could eventually send js script client side, but in this scenario it is not an option.

以下大部分链接真的很旧.2012~

我已经阅读了多篇 StackOverflow 帖子,但他们只提到了检索信息的方法.

I have read multiple StackOverflow posts, but they only mention ways to retrieve information.

Google Analytics 的 PHP API(SO)

有一篇关于发送信息的帖子,但该库已弃用 GitHub.

There is this one post talking about sending information but the GitHub has been deprecated for that library.

Google Analytics PHP API 重定向 URI (SO)

Google api php 客户端(GOOGLE)

如何使用 PHP 将信息发送到我的 Google Analytics(分析)帐户?谢谢

How do I send information to my Google Analytics account in PHP? Thanks

推荐答案

您通过 测量协议.不需要特殊的库或开发工具包,您只需将参数附加到 GA 端点并通过 Curl/fopen/sockets/whatever 将它们发送到 Google Analytics.

You send data via the Measurement Protocol. No special library or dev kit is required, you simply append parameters to the GA endpoint and send them via Curl/fopen/sockets/whatever to Google Analytics.

每个调用至少包含您要向其发送数据的帐户的 ID、一个允许将交互分组到会话中的客户端 ID(因此它应该是每个访问者的唯一标识,但它不能识别用户的个人身份)、一个交互类型(浏览量、事件、时间等,某些交互类型需要额外参数)和您使用的协议版本(目前只有一个版本).

Each calls includes at least the ID of the account you want to send data to, a client id that allows to group interactions into sessions (so it should be unique per visitor, but it must not identify a user personally), an interaction type (pageview, event, timing etc., some interactions types require additional parameters) and the version of the protocol you are using (at the moment there is only one version).

因此,记录浏览量的最基本示例如下所示:

So the most basic example to record a pageview would look like this:

www.google-analytics.com/collect/v=1&tid=UA-XXXXY&cid=555&t=pageview&dp=%2Fmypage

这篇关于Google Analytics PHP(发送信息)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Google Analytics PHP(发送信息)

基础教程推荐