我想获取我的一个使用 Google Analytics(分析)的应用程序的事件。 我对 the official documentation 中给出的示例有点困惑。我让它工作,但我不明白如何将它用于我的案例。
require_once 'GA/vendor/autoload.php';
// Start a session to persist credentials.
session_start();
// Create the client object and set the authorization configuration
// from the client_secretes.json you downloaded from the developer console.
$client = new Google_Client();
$client->setAuthConfigFile('client_secrets.json');
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
// If the user has already authorized this app then get an access token
// else redirect to ask the user to authorize access to Google Analytics.
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
// Set the access token on the client.
$client->setAccessToken($_SESSION['access_token']);
// Create an authorized analytics service object.
$analytics = new Google_Service_Analytics($client);
在此代码之后,我想获取事件数据 - 我应该如何指定计数器 ID 和事件信息?
使用查询资源管理器我成功创建了我需要的查询:
googleapis.com/analytics/v3/data/ga?ids=ga%3A111111&start-date=30daysAgo&end-date=2016-05-11&metrics=ga%3AtotalEvents&dimensions=ga%3AeventLabel
最佳答案
我不确定你所说的计数器 ID 是什么意思。您已经拥有了分析服务,只需立即提出请求即可。
$params = array('dimensions' => 'ga:AeventLabel');
// requesting the data
$data = $analytics->data_ga->get("ga:89798036", "30daysAgo", "2016-05-11", "ga:totalEvents", $params );
// displaying the data
foreach ($data->getRows() as $row) {
print "ga:AeventLabel ".$row[0]." ga:totalEvents ".$row[1]";
}
关于php - 使用 PHP 从 Google Analytics API 获取事件数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37161112/