简体   繁体   中英

Google Analytics API: How to get all Report ID

I want to select all the Report ID of all the added URLs in the Google Analytics account. How can I do something like this?

SELECT report_id FROM google_analytics_account

Example URLs in the Google Analytics account:

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

Where the Report IDs there are 1234567 and 9876543.

Can I do that using the GAPI class only? How?

I have a gapi class.

<!-- 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 />';

Thanks! :)

You can add a filter to your request. something like this should do

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

I'm not sure if its ga:pagePath or ga:landingPagePath that you will need to use check your google analytic's see which page it is you where looking at. Its probably ga:landingPagePath you want.

Also the , is an OR seproator so if you want to add more of them just add another with a ,.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM