本文整理汇总了PHP中gapi::getNewVisits方法的典型用法代码示例。如果您正苦于以下问题:PHP gapi::getNewVisits方法的具体用法?PHP gapi::getNewVisits怎么用?PHP gapi::getNewVisits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gapi
的用法示例。
在下文中一共展示了gapi::getNewVisits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
function fetch_daily_stats($ga_user, $ga_password, $ga_profile_id)
{
global $LOC;
$data = array();
$data['cache_date'] = date('Y-m-d', $LOC->set_localized_time());
require_once PATH_LIB . 'analytics_panel/gapi.class.php';
// Compile yesterday's stats
$yesterday = new gapi($ga_user, $ga_password);
$ga_auth_token = $yesterday->getAuthToken();
$yesterday->requestReportData($ga_profile_id, array('date'), array('pageviews', 'visits', 'timeOnSite'), '', '', date('Y-m-d', strtotime('yesterday')), date('Y-m-d', strtotime('yesterday')));
// Get account data so we can store the profile info
$data['profile'] = array();
$yesterday->requestAccountData(1, 100);
foreach ($yesterday->getResults() as $result) {
if ($result->getProfileId() == $ga_profile_id) {
$data['profile']['id'] = $result->getProfileId();
$data['profile']['title'] = $result->getTitle();
}
}
$data['yesterday']['visits'] = number_format($yesterday->getVisits());
$data['yesterday']['pageviews'] = number_format($yesterday->getPageviews());
$data['yesterday']['pages_per_visit'] = $this->analytics_avg_pages($yesterday->getPageviews(), $yesterday->getVisits());
$data['yesterday']['avg_visit'] = $this->analytics_avg_visit($yesterday->getTimeOnSite(), $yesterday->getVisits());
// Compile last month's stats
$lastmonth = new gapi($ga_user, $ga_password, $ga_auth_token);
$lastmonth->requestReportData($ga_profile_id, array('date'), array('pageviews', 'visits', 'newVisits', 'timeOnSite', 'bounces', 'entrances'), 'date', '', date('Y-m-d', strtotime('31 days ago')), date('Y-m-d', strtotime('yesterday')));
$data['lastmonth']['date_span'] = date('F jS Y', strtotime('31 days ago')) . ' – ' . date('F jS Y', strtotime('yesterday'));
$data['lastmonth']['visits'] = number_format($lastmonth->getVisits());
$data['lastmonth']['visits_sparkline'] = $this->analytics_sparkline($lastmonth->getResults(), 'visits');
$data['lastmonth']['pageviews'] = number_format($lastmonth->getPageviews());
$data['lastmonth']['pageviews_sparkline'] = $this->analytics_sparkline($lastmonth->getResults(), 'pageviews');
$data['lastmonth']['pages_per_visit'] = $this->analytics_avg_pages($lastmonth->getPageviews(), $lastmonth->getVisits());
$data['lastmonth']['pages_per_visit_sparkline'] = $this->analytics_sparkline($lastmonth->getResults(), 'avgpages');
$data['lastmonth']['avg_visit'] = $this->analytics_avg_visit($lastmonth->getTimeOnSite(), $lastmonth->getVisits());
$data['lastmonth']['avg_visit_sparkline'] = $this->analytics_sparkline($lastmonth->getResults(), 'time');
$data['lastmonth']['bounce_rate'] = $lastmonth->getBounces() > 0 && $lastmonth->getBounces() > 0 ? round($lastmonth->getBounces() / $lastmonth->getEntrances() * 100, 2) . '%' : '0%';
$data['lastmonth']['bounce_rate_sparkline'] = $this->analytics_sparkline($lastmonth->getResults(), 'bouncerate');
$data['lastmonth']['new_visits'] = $lastmonth->getNewVisits() > 0 && $lastmonth->getVisits() > 0 ? round($lastmonth->getNewVisits() / $lastmonth->getVisits() * 100, 2) . '%' : '0%';
$data['lastmonth']['new_visits_sparkline'] = $this->analytics_sparkline($lastmonth->getResults(), 'newvisits');
// Compile last month's top content
$topcontent = new gapi($ga_user, $ga_password, $ga_auth_token);
$topcontent->requestReportData($ga_profile_id, array('hostname', 'pagePath'), array('pageviews'), '-pageviews', '', date('Y-m-d', strtotime('31 days ago')), date('Y-m-d', strtotime('yesterday')), null, 20);
$data['lastmonth']['content'] = array();
$i = 0;
// Make a temporary array to hold page paths
// (for checking dupes resulting from www vs non-www hostnames)
$paths = array();
foreach ($topcontent->getResults() as $result) {
// Do we already have this page path?
$dupe_key = array_search($result->getPagePath(), $paths);
if ($dupe_key !== FALSE) {
// Combine the pageviews of the dupes
$data['lastmonth']['content'][$dupe_key]['count'] = $result->getPageviews() + $data['lastmonth']['content'][$dupe_key]['count'];
} else {
$url = strlen($result->getPagePath()) > 30 ? substr($result->getPagePath(), 0, 30) . '…' : $result->getPagePath();
$data['lastmonth']['content'][$i]['title'] = '<a href="http://' . $result->getHostname() . $result->getPagePath() . '" target="_blank">' . $url . '</a>';
$data['lastmonth']['content'][$i]['count'] = $result->getPageviews();
// Store the page path at the same position so we can check for dupes
$paths[$i] = $result->getPagePath();
$i++;
}
}
// Slice down to 10 results
$data['lastmonth']['content'] = array_slice($data['lastmonth']['content'], 0, 10);
// Compile last month's top referrers
$referrers = new gapi($ga_user, $ga_password, $ga_auth_token);
$referrers->requestReportData($ga_profile_id, array('source', 'referralPath', 'medium'), array('visits'), '-visits', '', date('Y-m-d', strtotime('31 days ago')), date('Y-m-d', strtotime('yesterday')), null, 10);
$data['lastmonth']['referrers'] = array();
$i = 0;
foreach ($referrers->getResults() as $result) {
$data['lastmonth']['referrers'][$i]['title'] = $result->getMedium() == 'referral' ? '<a href="http://' . $result->getSource() . $result->getReferralPath() . '" target="_blank">' . $result->getSource() . '</a>' : $result->getSource();
$data['lastmonth']['referrers'][$i]['count'] = number_format($result->getVisits());
$i++;
}
return $data;
}
示例2:
$ga->requestReportData($ga_profile, $dimensions, $metrics, '-visits', $filters, $start_date, $end_date, 1, 50);
?>
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<?php
include 'admin_menu.php';
?>
</div>
<div class="span9">
<h2>Analytics-Visitors</h2>
<div id="ajaxStatus"></div>
<div id="visualization"></div>
<div class="well">
<h3><?php
echo $ga->getNewVisits();
?>
people visited this site.</h3>
</div>
<div class="row">
<div class="span3">
<div id="divVisits">
<table class='table table-striped'>
<tr><td>Visits</td><td><strong><?php
echo $ga->getVisits();
?>
</strong></td></tr>
<tr><td>Unique Visitors</td><td><strong> <?php
echo $ga->getNewVisits();
?>
</strong></td></tr>