因此,我正在爬网博客以检测哪些文章有问题(链接断开和链接到我们不再销售的产品)。因此,自从文章创建到一年后(除非在一年之内完成,在这种情况下是新的),我一直在尝试获取点击量,然后为其添加点击量数据。我这样做是为了对列表进行优先排序,因为有1000多个有问题的文章。
因此获取anlytics的功能取自Google Analytics(分析)API文档,并进行了修改:
function getResults($analytics, $profileId, $page, $startdays, $enddays) {
return $analytics->data_ga->get(
'ga:' . $profileId,
$startdays.'daysAgo',
$enddays.'daysAgo',
'ga:sessions',
array(
'filters' => 'ga:pagePath=='.$page.',ga:medium==organic'));
}
function printResults($results) {
// Parses the response from the Core Reporting API and prints
// the profile name and total sessions.
if (count($results->getRows()) > 0) {
// Get the profile name.
$profileName = $results->getProfileInfo()->getProfileName();
// Get the entry for the first entry in the first row.
$rows = $results->getRows();
$sessions = $rows[0][0];
// Print the results.
print "Total sessions: $sessions\n";
} else {
print "No results found.\n";
}
}
将这些参数实际放入函数中的代码为:
$sql="SELECT * FROM `articles_tbl` LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$url=$row["article_url"];
$published_date=$row["date_published"];
$your_date = strtotime($published_date);
$now = time();
$datediff=$now-$your_date;
$startdays = round($datediff / (60 * 60 * 24));
$enddays=$startdays-365;
if($enddays<0){
$enddays=1;
}
$analytics = initializeAnalytics();
$profile = getFirstProfileId($analytics);
//The domain has been removed for obvious reasons
//this is to get the folders in the URL:
//"/blog/news/pagefolder/"
$page=str_replace(DOMAIN,"",$url);
$results = getResults($analytics, $profile, $page, $startdays, $enddays);
printResults($results);
echo "for url: ".$page." between ".$startdays." days ago and ".$enddays." days ago.";
}
}
因此,这当前输出:“总会话:999999,网址:/ blog / news / pagefolder /,介于859天之前和494天之前。
现在,上图是该时间段内的整个网站访问量(已在Google Analytics(分析)中手动确认),但是我只想知道该URL的确切会话数。无论如何,我不会显示任何内容或更改流量。我只能假设它在应用过滤器之前给了我会话,因此它总是一样吗?我一直盯着这个看了好几个小时,没有运气,我读到的所有内容都说,仅通过执行pagePath ==而不是pagePath = @应该可以使它准确无误,但没有运气,仍然可以获得所有网站流量...
答案 0 :(得分:0)
原来是有机过滤器。它正在破坏过滤器,因此没有任何作用。