Google Analytics(分析)PHP(发送信息) [英] Google Analytics PHP (Sending information)

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

问题描述

主要想法



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



以下大多数链接都很旧。 2012〜



检索 - 不是我需要的



我已阅读多个StackOverflow帖子,但他们只提及检索信息的方式。

用于Google Analytics(SO)的PHP API

发送 - 我需要的



这篇文章谈论发送信息,但GitHub已被弃用该库。





Google api php客户端(GOOGLE)

问题



如何在PHP中将信息发送到我的Google Analytics帐户?谢谢

解决方案

您通过测量协议。没有特殊的库或开发工具包是必需的,您只需将参数添加到GA端点,并通过Curl / fopen / sockets /发送到Google Analytics即可。 至少要发送数据的帐户的ID,允许将交互分组到会话中的客户端ID(因此它应该对每个访问者都是唯一的,但它不能个人识别用户),交互类型(综合浏览量,事件,时间等等,一些交互类型需要额外的参数)和你使用的协议版本(目前只有一个版本)。



记录浏览视图的基本示例如下所示:

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


Main Idea

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.

Most of the following links are really old. 2012~

Retrieving - Not what I need

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

PHP API for Google Analytics(SO)

Sending - What I need

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

Google Analytics PHP API Redirect URI (SO)

Google api php client(GOOGLE)

Question

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

解决方案

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.

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(发送信息)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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