Google Analytics API: filter by URI?

前端 未结 4 2008
梦如初夏
梦如初夏 2021-01-31 09:19

My site has user profiles that are accessible via URLs that look like this: www.domain.com/profile/123/.... I want to show users page view statistics of their profi

相关标签:
4条回答
  • 2021-01-31 09:30

    This will work:

     filters=ga:pagePath=~/profile/123/
    

    To do /*/view/* (as per @VinnyG’s comment), this should work:

    filters=ga:pagePath=~/[^/]+/view/
    

    I'm assuming you want to match one (and only one) directory before /view/.

    0 讨论(0)
  • 2021-01-31 09:37

    worked for me.

        
        require('gapi.class.php');
        $ga = new gapi('mail@example.com','google_analytics_password');
        $filter = 'ga:pagePath==/home.php';
    
        //first parameter is your Google Analytics profile id
    
        /* How to find Google Analytics Profile ID
        http://stackoverflow.com/questions/4119610/get-google-analytics-id-from-the-code-embed/4120625#4120625
        */
        $ga->requestReportData(0000000,array('pagePath'),array('pageViews','UniquePageviews'), '-pageViews', $filter);
    
        foreach($ga->getResults() as $result)
        {
            echo $result->getPageviews();
            echo $result->getUniquePageviews();
            echo $result->getPagePath();
        }
        ?>
    
    0 讨论(0)
  • 2021-01-31 09:44

    Another filter from the Dimension Filters that would work for you is contains "=@"

    ga:pagePath=@/profile/123

    0 讨论(0)
  • 2021-01-31 09:45

    Use the 'Contains a match for the regular expression' operator (~) from the Dimension Filters.

    filters=ga:pagePath=~/profile/123/*
    
    0 讨论(0)
提交回复
热议问题