直接从 PHP 调用 piwik
我有一个 PHP 网站,使用 piwik 作为分析。某些页面是由不执行 HTML/JS 的不同 API 请求的,因此我需要从 php 文件中调用 piwik。使用 piwik 跟踪 api 似乎是错误的,因为它发送 HTTP 请求并要求我手动设置 IP地址等细微差别。 Piwiki 安装在同一台服务器上,所以我猜解决方案与以下内容相关:
require_once "../piwik/piwik.php"
也许......
我该怎么做?
I have a PHP website with piwik as analytics. Certain pages are requested by different API's which don't execute HTML/JS so I need to call piwik from within the php files. Using the piwik tracking api seems wrong as it sends out HTTP requests and demands I manually set the IP address among other nuances. Piwiki is installed on the same server so I guess the solution is something related to:
require_once "../piwik/piwik.php"
maybe....
How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您向本地服务器(没有外部 DNS)发出请求,那么它应该足够快并且不会增加太多开销。就易用性和可维护性而言,使用跟踪 API 是最佳选择。假设您已正确设置 Piwik 跟踪请求的所有 $_GET 参数,您也可能需要“piwik.php”。
一些跟踪参数记录在:https:// matomo.org/docs/tracking-api/#toc-tracking-api-rest-documentation
If you make the requests to the local server (without external DNS) then it should be fast enough and not add much overhead. Using the tracking API is the way to go in terms of ease of use and maintainability. You can also probably require "piwik.php" assuming you have set all the $_GET parameters correctly for Piwik to track the requests.
Some of the tracking parameters are documented in: https://matomo.org/docs/tracking-api/#toc-tracking-api-rest-documentation
Piwik 网站有一个 PHP API 的完整示例实现。仅当您想要强制请求显示为来自特定客户端时,才需要设置 IP。
直接包含 Piwik PHP 文件是行不通的,除非您已经围绕它们大量调整了代码。
The Piwik website has a full example implementation of the PHP API. Setting an IP is only required if you want to force requests to appear to come from a particular client.
Including the Piwik PHP files directly will not work unless you have heavily adapted your code around them.