2015-06-15 39 views
0

這是一個相當新手的問題,請與我聯繫...谷歌分析API多個查詢 - 第二功能?

我已成功授權我的Google Analytics API帳戶並正在進行以下通話,該通話已成功打印跳出率。

我想爲網頁瀏覽和會話等內容添加更多查詢,我該怎麼做?

這是困擾我的功能,我需要爲每個查詢創建一個新的功能嗎?

在此先感謝! 湯姆

function getResults(&$analytics, $profileId) { 
    // Calls the Core Reporting API and queries for the number of sessions 
    // for the last seven days. 
    return $analytics->data_ga->get(
     'ga:' . $profileId, 
     'today', 
     'today', 
     'ga:bouncerate'); 
} 

function printResults(&$results) { 
    // Parses the response from the Core Reporting API and prints 
    // the profile name and total sessions. 
    if (count($results->getRows()) > 0) { 

    // Get the profile name. 
    $profileName = $results->getProfileInfo()->getProfileName(); 

    // Get the entry for the first entry in the first row. 
    $rows = $results->getRows(); 
    $sessions = $rows[0][0]; 



    // Print the results. 
    print "<p>First view (profile) found: $profileName</p>"; 
    print "<p>Total sessions: $sessions</p>"; 
    } else { 
    print "<p>No results found.</p>"; 
    } 

回答

0

代碼的下面的部分是什麼實際上使API請求:

$analytics->data_ga->get(
    'ga:' . $profileId, 
    'today', 
    'today', 
    'ga:bouncerate'); 

如果你想使更多的查詢,你必須再次調用$analytics->data_ga->get()方法。您無需爲每個查詢編寫新函數(如果您不想),但每次都需要調用$analytics->data_ga->get()。你如何選擇重用這一點取決於你。