Google analytics 谷歌分析
如何使用gapi从GA获取事件数据 我有一些检索“源代码”和“访问”的示例代码。 我希望我的事件来自一个名为“视频”的类别,动作名为“播放”,每个活动都有一个文件名作为标签 以下是我当前普通访问的工作代码:Google analytics 谷歌分析,google-analytics,Google Analytics,如何使用gapi从GA获取事件数据 我有一些检索“源代码”和“访问”的示例代码。 我希望我的事件来自一个名为“视频”的类别,动作名为“播放”,每个活动都有一个文件名作为标签 以下是我当前普通访问的工作代码: <?php require 'gapi-1.3/gapi.class.php'; /* Set your Google Analytics credentials */ define('ga_account' ,'dadadadad'); define('ga_passwor
<?php
require 'gapi-1.3/gapi.class.php';
/* Set your Google Analytics credentials */
define('ga_account' ,'dadadadad');
define('ga_password' ,'adadadad');
define('ga_profile_id' ,'dadadadad');
$ga = new gapi(ga_account,ga_password);
/* We are using the 'source' dimension and the 'visits' metrics */
$dimensions = array('source');
$metrics = array('visits');
/* We will sort the result be desending order of visits,
and hence the '-' sign before the 'visits' string */
$ga->requestReportData(ga_profile_id, $dimensions, $metrics,'-visits');
$gaResults = $ga->getResults();
$i=1;
foreach($gaResults as $result)
{
printf("%-4d %-40s %5d\n",
$i++,
$result->getSource(),
$result->getVisits());
echo '<br/>';
}
echo "\n-----------------------------------------\n";
echo "Total Results : {$ga->getTotalResults()}";
?>
我能够猜测函数名是什么。 这对我有用:
$ga = new gapi(ga_account,ga_password);
/* We are using the 'source' dimension and the 'visits' metrics */
$dimensions = array('eventLabel');
//$metrics = array('totalEvents','uniqueEvents','eventsPerVisitWithEvent');
$metrics = array('totalEvents');
$sort_metric = '-totalEvents';
/* We will sort the result be desending order of visits,
and hence the '-' sign before the 'visits' string */
$ga->requestReportData(ga_profile_id, $dimensions, $metrics,'-totalEvents');
$gaResults = $ga->getResults();
$i=1;
foreach($gaResults as $result)
{
printf("%-4d %-40s %5d\n",
$i++,
$result->getEventLabel(),
$result->getTotalEvents()/*,
//$result->getUniqueEvents(),
//$result->getEventsPerVisitWithEvent() */);
echo '<br/>';
}
echo "\n-----------------------------------------\n";
echo "Total Results : {$ga->getTotalResults()}";
$ga=新的gapi(ga_账户,ga_密码);
/*我们正在使用“源”维度和“访问”指标*/
$dimensions=数组('eventLabel');
//$metrics=array('totalEvents'、'uniqueEvents'、'eventsPerVisitWithEvent');
$metrics=数组('totalEvents');
$sort_metric='-totalEvents';
/*我们将根据访问顺序对结果进行排序,
因此在“访问”字符串之前有“-”符号*/
$ga->requestReportData(ga_profile_id,$dimensions,$metrics,'-totalEvents');
$gaResults=$ga->getResults();
$i=1;
foreach($gaResults作为$result)
{
printf(“%-4d%-40s%5d\n”,
$i++,
$result->getEventLabel(),
$result->getTotalEvents()/*,
//$result->getUniqueEvents(),
//$result->getEventsPerVisitWithEvent()*/);
回声“
”;
}
回显“\n------------------------------------------\n”;
echo“总结果:{$ga->getTotalResults()}”;