// 從第一個位置開始抓資料 $filter = "ga:customVarName2 == " . $ga_name; // 過濾條件 echo "- 開始從 GA 抓 " . $ga_name . " 的資料\n"; sleep(1); // 預設從 GA 拿回來的變數 $totalCount = NULL; // 總筆數 $gaResults = array(); // GA 資料陣列 // 遞迴使用 $cnt = 0; $counter = 0; $result_cnt = 0; // 取得 GA Server 傳回來的資料給 $gaResults getGAResults($ga, $totalCount, $gaResults, $ga_id, $dimensions, $metrics, $sort, $filter, $date1, $date2, $offset, $limit); if ($totalCount > 0 && count($gaResults) > 0) { // 有資料 $j = 1; echo "結果:\n"; foreach ($gaResults as $result) { // 寫入資料庫 $tag = substr($date1, 0, 4) . $result->getWeek(); // 週次 YYYYWW $user = intval($result->getCustomVarValue2()); // 會員主鍵 $cnt = intval($result->getPageviews()); // 瀏覽頁數 if (preg_match("/^[0-9]{6}\$/", $tag) && $user > 0 && $cnt > 0) { $status = "寫入資料庫" . ($sth->execute(array(":site" => $site, ":tag" => $tag, ":user" => $user, ":cnt" => $cnt)) ? "成功" : "失敗"); } else {
// 'dimensions' => 'ga:pagePath,ga:userType', // 'metrics' => 'ga:sessions', // 'sort' => '-ga:sessions', // ); //}else{ // $gaarr = array( // 'filters' => 'ga:pagePath=@/local/', // 'dimensions' => 'ga:pagePath,ga:userType', // 'metrics' => 'ga:sessions', // 'sort' => '-ga:sessions', // ); //} $pagepath = '/ca/santaana-test-business-161-24415/'; //$_REQUEST['page_path'] $gaarr = array('filters' => 'ga:pagePath==/local' . $pagepath, 'dimensions' => 'ga:pagePath,ga:date', 'metrics' => 'ga:sessions', 'sort' => '-ga:date'); $garesults = getGAResults($analytics, $profile, '30daysAgo', 'yesterday', $gaarr); echo '<pre>'; $alldata = printResults($results); printResults($garesults); $rows = $results->rows; $pageviews = $rows[1][1]; $newUsers = $rows[1][3]; $users = $rows[1][4]; $sessionsPerUser = $rows[1][5]; ?> <html> <head> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("visualization", "1", {packages:["corechart"]});