阅读Google Analytics php Api

时间:2017-12-03 16:12:04

标签: php google-analytics google-analytics-api

我正在尝试从每个国家/地区获取网页浏览量。 我为此目的有以下代码。

function getResults($analytics, $profileId,$url) {
  // Calls the Core Reporting API and queries for the number of sessions
  // for the last seven days.
  $optParams = array(
          'dimensions' => 'ga:country',
          'filters' => 'ga:pagePath=@/605-2/'
    );
   return $analytics->data_ga->get(
       'ga:' . $profileId,
       '2017-11-01',
       'today',
       'ga:pageViews',

     $optParams);
}

代码运行正常。问题是我不知道如何将结果打印为表格

  • 国家/地区观点
    美国| 52个
    澳大利亚| 50

以下是我设法过滤掉的回复

Array ( [0] => Array ( [0] => (not set) [1] => 1 ) [1] => Array ( [0] => Australia [1] => 11 ) [2] => Array ( [0] => Bahrain [1] => 2 ) [3] => Array ( [0] => Belgium [1] => 1 ) [4] => Array ( [0] => Canada [1] => 5 ) [5] => Array ( [0] => Denmark [1] => 1 ) [6] => Array ( [0] => Finland [1] => 1 ) [7] => Array ( [0] => France [1] => 1 ) [8] => Array ( [0] => Germany [1] => 10 ) [9] => Array ( [0] => Hungary [1] => 1 ) [10] => Array ( [0] => Italy [1] => 1 ) [11] => Array ( [0] => Japan [1] => 4 ) [12] => Array ( [0] => Mali [1] => 1 ) [13] => Array ( [0] => Norway [1] => 1 ) [14] => Array ( [0] => Pakistan [1] => 589 ) [15] => Array ( [0] => Peru [1] => 1 ) [16] => Array ( [0] => Saudi Arabia [1] => 13 ) [17] => Array ( [0] => Singapore [1] => 1 ) [18] => Array ( [0] => South Africa [1] => 1 ) [19] => Array ( [0] => South Korea [1] => 2 ) [20] => Array ( [0] => Ukraine [1] => 1 ) [21] => Array ( [0] => United Arab Emirates [1] => 7 ) [22] => Array ( [0] => United Kingdom [1] => 7 ) [23] => Array ( [0] => United States [1] => 10 ) )

0 个答案:

没有答案