谷歌分析:发送网页浏览量或事件与PHP


Google Analitics : Send PageViews or Event with PHP

我有一个已经使用谷歌分析的网站,但它没有为Ajax动作(例如动态搜索引擎)发送页面视图,我没有找到一个API来通过服务器发送它。

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

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

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

它是一个PHP客户端库,从服务器端与谷歌分析通信。

// 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&源= cc