Google AnalyticsAPI:如何获取所有报告ID

时间:2013-09-19 02:15:22

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

我想选择Google Analytics帐户中所有添加的网址的所有报告ID。 我怎么能这样做?

SELECT report_id FROM google_analytics_account

Google Analytics帐户中的示例网址:

https://www.google.com/analytics/web/?hl=en#home/a3456789w2345678p1234567/
https://www.google.com/analytics/web/?hl=en#home/a3456789w2345678p9876543/

报告ID有1234567和9876543。

我可以只使用GAPI类吗?怎么样?

我有一个gapi课程。

<!-- language: lang-php -->

    require_once 'gapi.class.php';
    $ga = new gapi('my_test_email@gmail.com', 'my_test_email_password');

    $report_id = 1234567;
    $dimensions = array('browser', 'browserVersion');
    $metrics = array('pageviews', 'visits');
    $sort_metric = null;
    $filter = null;
    $start_date = null;
    $end_date = null;
    $start_index = 1;
    $max_results = 30;
    $ga->requestReportData(
        $report_id, 
        $dimensions, 
        $metrics, 
        $sort_metric, 
        $filter, 
        $start_date, 
        $end_date, 
        $start_index, 
        $max_results
    );

    foreach ($ga->getResults() as $result) {
        echo '<strong>'.$result.'</strong><br />';
        echo 'Pageviews: ' . $result->getPageviews() . ' ';
        echo 'Visits: ' . $result->getVisits() . '<br />';
    }
    echo '<p>Total pageviews: ' . $ga->getPageviews() . ' total visits: ' . $ga->getVisits() . '</p>';
    echo '<font color="blue"><pre>',print_r($ga->getResults()),'</pre></font>';
    echo '<hr />';

谢谢! :)

1 个答案:

答案 0 :(得分:0)

您可以在请求中添加过滤器。这样的事情应该做

ga:landingPagePath%3D@ReportID=1234567,ga:pagePath%3D@ReportID=9876543

我不确定您需要使用的ga:pagePath或ga:landingPagePath是否会检查您的google analytic,看看您在哪个页面查看。它可能是ga:你想要的landingPagePath。

此外,是一个OR提词器,所以如果你想添加更多的,只需添加另一个,。