我有以下代碼,它的工作正常。使用PHP獲取特定的頁面瀏覽量谷歌分析
<?php
require_once __DIR__ . '/vendor/autoload.php';
$analytics = initializeAnalytics();
$response = getReport($analytics);
printResults($response);
function initializeAnalytics()
{
$KEY_FILE_LOCATION = __DIR__ . '/Student-a2aeba87a13b.json';
$client = new Google_Client();
$client->setApplicationName("Hello Analytics Reporting");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
$analytics = new Google_Service_AnalyticsReporting($client);
return $analytics;
}
function getReport($analytics) {
$VIEW_ID = "107034574";
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("30daysAgo");
$dateRange->setEndDate("today");
$sessions = new Google_Service_AnalyticsReporting_Metric();
$sessions->setExpression("ga:pageviews");
$sessions->setAlias("hits");
echo "<pre>";
$browser = new Google_Service_AnalyticsReporting_Dimension();
$browser->setName("ga:pagePathLevel1");
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges($dateRange);
$request->setMetrics(array($sessions));
//Create the Dimensions object.
/* $sessions->setExpression("ga:users"); --get total users
/$browser->setName("ga:userType");
$sessions->setExpression("ga:percentNewSessions"); ---new user session percentage
* $sessions->setExpression("ga:newUsers");
$sessions->setExpression("ga:sessions");
$sessions->setExpression("ga:bounceRate");--bounce tare
$sessions->setExpression("ga:pageviews"); //total page view
$sessions->setExpression("ga:visits");
*
*/
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests(array($request));
echo "<pre>";
// print_r($body);
return $analytics->reports->batchGet($body);
}
function printResults($reports) {
for ($reportIndex = 0; $reportIndex < count($reports); $reportIndex++) {
$report = $reports[ $reportIndex ];
$header = $report->getColumnHeader();
$dimensionHeaders = $header->getDimensions();
$metricHeaders = $header->getMetricHeader()->getMetricHeaderEntries();
$rows = $report->getData()->getRows();
echo "<pre>";
// print_r($rows);
for ($rowIndex = 0; $rowIndex < count($rows); $rowIndex++) {
$row = $rows[ $rowIndex ];
$dimensions = $row->getDimensions();
$metrics = $row->getMetrics();
for ($i = 0; $i < count($dimensionHeaders) && $i < count($dimensions); $i++) {
print($dimensionHeaders[$i] . ": " . $dimensions[$i] . "\n");
}
for ($j = 0; $j < count($metricHeaders) && $j < count($metrics); $j++) {
$entry = $metricHeaders[$j];
$values = $metrics[$j];
print("Metric type: " . $entry->getType() . "\n");
for ($valueIndex = 0; $valueIndex < count($values->getValues()); $valueIndex++) {
$value = $values->getValues()[ $valueIndex ];
print($entry->getName() . ": " . $value . "\n");
}
}
}
}
}
現在我得到的所有頁面數量和獨特的頁面count.Now我的問題是我需要得到特別例如登錄頁面註冊頁面,頁面瀏覽次數etc.Can任何一個可以幫助我如何獲得特定頁面的計數。感謝
既然這樣,你的問題無關與著名Laravelcodeignitercakephp框架...... – ndm