我在使用Piwik跟蹤Drupal 7站點上的分析。 Piwik模塊安裝並完美追蹤。我遇到的問題是使用PHP方法進行報告。當我使用Piwik文檔中的示例代碼時,它會導致一個錯誤,導致整個頁面顯示爲純文本HTML /源代碼,而不是渲染的網站。但是,在Drupal之外的基本PHP文件上使用代碼很好。在Drupal 7中查詢Piwik
這是Piwik文檔中的代碼(我與修改,包括我的身份驗證令牌):
<?php
use Piwik\API\Request;
use Piwik\FrontController;
define('PIWIK_INCLUDE_PATH', realpath('../..'));
define('PIWIK_USER_PATH', realpath('../..'));
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);
// if you prefer not to include 'index.php', you must also define here PIWIK_DOCUMENT_ROOT
// and include "libs/upgradephp/upgrade.php" and "core/Loader.php"
require_once PIWIK_INCLUDE_PATH . "/index.php";
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";
FrontController::getInstance()->init();
// This inits the API Request with the specified parameters
$request = new Request('
module=API
&method=UserSettings.getResolution
&idSite=7
&date=yesterday
&period=week
&format=XML
&filter_limit=3
&token_auth=anonymous
');
// Calls the API and fetch XML data back
$result = $request->process();
echo $result;
如果我改變定義的常量爲真,這則表明有錯誤的頁面:
會話已經開始通過session.auto啓動或在session_start()
的Drupal的.htaccess已經有auto.start關閉,我也試圖改變Piwik會話數據存儲在數據庫中,而不是文件,但都沒有成功。
只是FYI,代碼被放置到節點模板(node - 183.tpl.php)中,以覆蓋單個頁面的輸出。
感謝您的幫助!
'這是Piwik docs'的代碼=>您是否有該文檔的鏈接?我不明白爲什麼有'FrontController :: getInstance() - > init();' – 2014-10-07 04:32:04
Nevermind我發現它:http://developer.piwik.org/guides/querying-the-reporting-api#call- -piwik-api-in-php這實際上就是你可以在Piwik應用程序中使用的代碼。 – 2014-10-07 05:15:25