2015-06-15 40 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()。你如何选择重用这一点取决于你。