当前位置: 首页>>代码示例>>PHP>>正文


PHP gapi::getEntrances方法代码示例

本文整理汇总了PHP中gapi::getEntrances方法的典型用法代码示例。如果您正苦于以下问题:PHP gapi::getEntrances方法的具体用法?PHP gapi::getEntrances怎么用?PHP gapi::getEntrances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gapi的用法示例。


在下文中一共展示了gapi::getEntrances方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
 }
开发者ID:amphibian,项目名称:ext.analytics_panel.ee_addon,代码行数:76,代码来源:ext.analytics_panel.php


注:本文中的gapi::getEntrances方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。