[英]How can I reach google analytics datas?
My goal is to show google analytics datas on the header of my site. 我的目标是在我网站的标题上显示Google Analytics(分析)数据。 Thats all I have until now (its from googleApiPhPClient/examples/analytics:
到目前为止,这就是我所拥有的(来自googleApiPhPClient / examples / analytics:
require_once 'library/GoogleApiPhpClient/apiClient.php';
$client = new apiClient();
$client->setApplicationName("Google Analytics PHP Starter Application");
// Visit https://code.google.com/apis/console?api=analytics to generate your
// client id, client secret, and to register your redirect uri.
$client->setClientId('aaa');
$client->setClientSecret('bbb_gK');
$client->setRedirectUri('ccc');
$client->setDeveloperKey('dd');
require_once ('contrib/apiAnalyticsService.php');
$service = new apiAnalyticsService($client);
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken()) {
$props = $service->management_webproperties->listManagementWebproperties("~all");
print "<h1>Web Properties</h1><pre>" . print_r($props, true) . "</pre>";
$accounts = $service->management_accounts->listManagementAccounts();
print "<h1>Accounts</h1><pre>" . print_r($accounts, true) . "</pre>";
$segments = $service->management_segments->listManagementSegments();
print "<h1>Segments</h1><pre>" . print_r($segments, true) . "</pre>";
$goals = $service->management_goals->listManagementGoals("~all", "~all", "~all");
print "<h1>Segments</h1><pre>" . print_r($goals, true) . "</pre>";
$_SESSION['token'] = $client->getAccessToken();
} else {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
but this only drops a "connect me" link. 但这只会删除“连接我”链接。 Am in the somewhat right way on getting analytic datas anyway?
反正以某种正确的方式获取分析数据?
I've been using this code.google.com/p/gapi-google-analytics-php-interface which only requires the google account user name and password and works pretty well 我一直在使用此code.google.com/p/gapi-google-analytics-php-interface,该界面仅需要google帐户的用户名和密码即可正常运行
a sample code of mine where im checking visits $ga->requestReportData($ga_profile_id,array('browser','browserVersion','country'),array('pageviews','visits'),null,"country==USA",$yesterday,$todate);
when you log in to your account, select the profile you already made for your web site . 登录帐户时,选择您已经为网站创建的配置文件。 when you will click it, the url would be like google.com/analytics/web/#report/visitors-overview/… so the ga_profile_id would be the one written after "p" in the URL.. i see this way only to get this profile id
当您单击它时,该网址将类似于google.com/analytics/web/#report/visitors-overview/…,因此ga_profile_id将是网址中“ p”之后的那个。获取此个人资料ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.