gpt4 book ai didi

php - 谷歌分析 : Send PageViews or Event with PHP

转载 作者:搜寻专家 更新时间:2023-10-31 21:33:45 25 4
gpt4 key购买 nike

我有一个已经使用 Google Analytics 的网站,但它没有为 Ajax 操作(例如动态搜索引擎)发送页面 View ,我没有找到一个 API 来通过服务器用 PHP 发送它。

最佳答案

对于您的任务,请查看 Google Measurement Protocol https://developers.google.com/analytics/devguides/collection/protocol/v1/?hl=de

现在我指向我的 Github 项目 - 也许它对你的任务有用。

https://github.com/ins0/google-measurement-php-client

它是一个 PHP 客户端库,用于从服务器端与 Google Analytics 通信。

// autoloader
require_once( dirname(__FILE__) . '/../src/Racecore/GATracking/Autoloader.php');
Racecore\GATracking\Autoloader::register(dirname(__FILE__).'/../src/');

// init tracking
$tracking = new \Racecore\GATracking\GATracking('UA-XXXXXXXX-X',false);

// optional when not setting the client id by constructor
$tracking->setAccountID('UA-XXXXXXXX-X');

/**
* Page Tacking
*/
$page = new \Racecore\GATracking\Tracking\Page();
$page->setDocumentPath('/test/pageview/blub.jpg');
$page->setDocumentTitle('Test Image Title');

$tracking->addTracking($page);

// Do the Job!
Try {
$tracking->send();
echo 'success';

} Catch (Exception $e) {
echo 'Error: ' . $e->getMessage() . '<br />' . "\r\n";
echo 'Type: ' . get_class($e);
}

否则你可以使用其他很棒的存储库,看这里

https://github.com/search?q=google-measurement&source=cc

关于php - 谷歌分析 : Send PageViews or Event with PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24882173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com