[精讚] [會員登入]
746

### 五、查詢範例

#### 1. 查詢一週來每日的訪客數

  private function getResults($analytics,$profileId) {
$optParams = array( 'dimensions' => 'ga:date', 'sort' => 'ga:date'); return$analytics->data_ga->get(
'ga:' . $profileId, '7daysAgo', 'today', 'ga:users',$optParams);
}


Array ( [0] => Array ( [0] => 20170804 [1] => 850 ) [1] => Array ( [0] => 20170805 [1] => 484 ) [2] => Array ( [0] => 20170806 [1] => 537 ) [3] => Array ( [0] => 20170807 [1] => 900 ) [4] => Array ( [0] => 20170808 [1] => 870 ) [5] => Array ( [0] => 20170809 [1] => 879 ) [6] => Array ( [0] => 20170810 [1] => 881 ) [7] => Array ( [0] => 20170811 [1] => 53 ) )

#### 2. 查詢最近一個月的SESSION數中，依國別排序由多至少取10筆

  private function getResults($analytics,$profileId) {
$optParams = array( 'dimensions' => 'ga:country', 'sort' => '-ga:sessions', 'max-results' => '10'); return$analytics->data_ga->get(
'ga:' . $profileId, '29daysAgo', 'today', 'ga:sessions',$optParams);
}


Array ( [0] => Array ( [0] => Taiwan [1] => 21192 ) [1] => Array ( [0] => Hong Kong [1] => 1081 ) [2] => Array ( [0] => United States [1] => 232 ) [3] => Array ( [0] => Malaysia [1] => 198 ) [4] => Array ( [0] => China [1] => 139 ) [5] => Array ( [0] => Japan [1] => 97 ) [6] => Array ( [0] => Macau [1] => 91 ) [7] => Array ( [0] => (not set) [1] => 81 ) [8] => Array ( [0] => Singapore [1] => 66 ) [9] => Array ( [0] => Canada [1] => 45 ) )

#### 3. 昨天到今天每個小時間的新訪客數量

  private function getResults($analytics,$profileId) {
$optParams = array( 'dimensions' => 'ga:date,ga:hour', 'sort' => 'ga:date,ga:hour', ); return$analytics->data_ga->get(
'ga:' . $profileId, 'yesterday', 'today', 'ga:newUsers',$optParams);
}


Array ( [0] => Array ( [0] => 20170810 [1] => 00 [2] => 15 ) [1] => Array ( [0] => 20170810 [1] => 01 [2] => 14 ) [2] => Array ( [0] => 20170810 [1] => 02 [2] => 17 ) [3] => Array ( [0] => 20170810 [1] => 03 [2] => 5 ) [4] => Array ( [0] => 20170810 [1] => 04 [2] => 6 ) [5] => Array ( [0] => 20170810 [1] => 05 [2] => 2 ) [6] => Array ( [0] => 20170810 [1] => 06 [2] => 7 ) [7] => Array ( [0] => 20170810 [1] => 07 [2] => 11 ) [8] => Array ( [0] => 20170810 [1] => 08 [2] => 26 ) [9] => Array ( [0] => 20170810 [1] => 09 [2] => 46 ) [10] => Array ( [0] => 20170810 [1] => 10 [2] => 41 ) [11] => Array ( [0] => 20170810 [1] => 11 [2] => 50 ) [12] => Array ( [0] => 20170810 [1] => 12 [2] => 30 ) [13] => Array ( [0] => 20170810 [1] => 13 [2] => 58 ) [14] => Array ( [0] => 20170810 [1] => 14 [2] => 52 ) [15] => Array ( [0] => 20170810 [1] => 15 [2] => 60 ) [16] => Array ( [0] => 20170810 [1] => 16 [2] => 59 ) [17] => Array ( [0] => 20170810 [1] => 17 [2] => 54 ) [18] => Array ( [0] => 20170810 [1] => 18 [2] => 27 ) [19] => Array ( [0] => 20170810 [1] => 19 [2] => 24 ) [20] => Array ( [0] => 20170810 [1] => 20 [2] => 36 ) [21] => Array ( [0] => 20170810 [1] => 21 [2] => 35 ) [22] => Array ( [0] => 20170810 [1] => 22 [2] => 42 ) [23] => Array ( [0] => 20170810 [1] => 23 [2] => 32 ) [24] => Array ( [0] => 20170811 [1] => 00 [2] => 20 ) [25] => Array ( [0] => 20170811 [1] => 01 [2] => 11 ) [26] => Array ( [0] => 20170811 [1] => 02 [2] => 16 ) [27] => Array ( [0] => 20170811 [1] => 03 [2] => 2 ) [28] => Array ( [0] => 20170811 [1] => 04 [2] => 0 ) [29] => Array ( [0] => 20170811 [1] => 05 [2] => 0 ) [30] => Array ( [0] => 20170811 [1] => 06 [2] => 0 ) [31] => Array ( [0] => 20170811 [1] => 07 [2] => 0 ) [32] => Array ( [0] => 20170811 [1] => 08 [2] => 0 ) [33] => Array ( [0] => 20170811 [1] => 09 [2] => 0 ) [34] => Array ( [0] => 20170811 [1] => 10 [2] => 0 ) [35] => Array ( [0] => 20170811 [1] => 11 [2] => 0 ) [36] => Array ( [0] => 20170811 [1] => 12 [2] => 0 ) [37] => Array ( [0] => 20170811 [1] => 13 [2] => 0 ) [38] => Array ( [0] => 20170811 [1] => 14 [2] => 0 ) [39] => Array ( [0] => 20170811 [1] => 15 [2] => 0 ) [40] => Array ( [0] => 20170811 [1] => 16 [2] => 0 ) [41] => Array ( [0] => 20170811 [1] => 17 [2] => 0 ) [42] => Array ( [0] => 20170811 [1] => 18 [2] => 0 ) [43] => Array ( [0] => 20170811 [1] => 19 [2] => 0 ) [44] => Array ( [0] => 20170811 [1] => 20 [2] => 0 ) [45] => Array ( [0] => 20170811 [1] => 21 [2] => 0 ) [46] => Array ( [0] => 20170811 [1] => 22 [2] => 0 ) [47] => Array ( [0] => 20170811 [1] => 23 [2] => 0 ) )

#### 4. 七月訪客數依來源別分組，數量大到小排序

  private function getResults($analytics,$profileId) {
$optParams = array( 'dimensions' => 'ga:medium', 'sort' => '-ga:users', ); return$analytics->data_ga->get(
'ga:' . $profileId, '2017-07-01', '2017-07-31', 'ga:users',$optParams);
}


Array ( [0] => Array ( [0] => organic [1] => 15799 ) [1] => Array ( [0] => (none) [1] => 1814 ) [2] => Array ( [0] => referral [1] => 1538 ) )

#### 5. 七月訪客數、SESSION數連結網址，數量大到小排序

  private function getResults($analytics,$profileId) {
$optParams = array( 'dimensions' => 'ga:pagePath', 'sort' => '-ga:users', 'max-results' => '10' ); return$analytics->data_ga->get(
'ga:' . $profileId, '2017-07-01', '2017-07-31', 'ga:users,ga:sessions',$optParams);
}


Array ( [0] => Array ( [0] => /content/index/10710 [1] => 477 [2] => 513 ) [1] => Array ( [0] => /content/index/10821 [1] => 451 [2] => 581 ) [2] => Array ( [0] => /content/index/10047 [1] => 447 [2] => 502 ) [3] => Array ( [0] => /content/index/10241 [1] => 342 [2] => 414 ) [4] => Array ( [0] => /content/index/10442 [1] => 316 [2] => 334 ) [5] => Array ( [0] => /content/index/10313 [1] => 314 [2] => 349 ) [6] => Array ( [0] => /content/index/10686 [1] => 302 [2] => 307 ) [7] => Array ( [0] => /content/index/11450 [1] => 298 [2] => 303 ) [8] => Array ( [0] => /content/index/10320 [1] => 293 [2] => 378 ) [9] => Array ( [0] => /content/index/10310 [1] => 267 [2] => 278 ) )

6. 七月SESSION數中連結網址帶有'u=note'的參數

  private function getResults($analytics,$profileId) {
$optParams = array( 'dimensions' => 'ga:pagePath', 'filters' => 'ga:pagePath=~u=note', 'max-results' => '10' ); return$analytics->data_ga->get(
'ga:' . $profileId, '2017-07-01', '2017-07-31', 'ga:sessions',$optParams);
}


Array ( [0] => Array ( [0] => /?u=note [1] => 132 ) [1] => Array ( [0] => /?u=note&s=timeline [1] => 4 ) )

END

### 你可能感興趣的文章

[CodeIgniter 3] 取得controller和method的方法 CodeIgniter 3 取得controller和method的方法

[CodeIgniter 3] 資料庫的使用方法整理1/2 --Select的使用 [CodeIgniter 3] 資料庫的使用方法整理：Select的使用

[PHP] 命名空間 namespace及 use PHP >=5.3 開始支援命名空間：namespace

PHP 產生連續的日期 要用PHP產生連續的日期，連續月份

PHP 數字加解密函式 自寫的數字加解密，勉強用

[PHP] 處理mail 函式的標題中文字亂碼 PHP的mail函式若標題有中文字得先處理過，否則收信者會看到亂碼

[PHP] 字串編碼及解碼函式 為何要將字串編碼？理由很簡單，就是不要讓人家輕易的知道字串內容是什麼。例如點選分頁時，我們常會用這樣的連結： index

[PHP] 移除陣列或字串中的重覆元素 移除陣列或字串中的重覆元素

[PHP] 類別的繼承及建構子和解構子 PHP 類別的繼承及建構子和解構子

[無留言]

### 隨機好文

Smarty安裝 smarty 是著名的樣版引擎，非常的好用，用多了突然發現拿掉smarty反而不會寫php了，以下是安裝過程..

[AS3] 變數型態 基本類型宣告 as3 有下列幾種基本類型：string, int, number, object, boolean, n

[Javascript] 偵錯方式 (火狐中的javascript偵錯) javascript 並不是很容易偵錯(debug)的語言，但那是以前，現在有很多瀏覽器支持很多的工具，此文以火狐為例談談偵錯...