Search code examples
phpgoogle-analyticsgoogle-analytics-apigoogle-api-php-client

Google Analytics PHP API : get reporting


I have a professional website using Google Analytics for metrics and I try to automatize one task I used to do manually but.. not able to understand if it's possible ?!

I just began to using the Google PHP client library to access the Google Analytics API on my website Test with the HelloAnalytics.php file is OK, I manage to connect and retrieve my data.

What i'm trying to do is :

  • Get all URLs viewed in the past 24H (what you can see when you navigate in the GA dashboard -> Behavior -> Site content -> All pages)
  • Combine those datas with my custom Definition which is in fact a special token i generate for every users on my website via PHP, then send it thought with Javascript and ga('set', 'mycustomdefinition', 'my token');

Is it possible ? Many thanks in advance for your support !


Solution

    1. Data under 24-48 hours old has probably not completed processing so I recommend not looking at data viewed in the last 24 hours it wont be correct. Other wise yes you can see this.

    2. Assuming you mean custom Dimension yes you can extract custom dimensions and the page path in the same request.

    You might want to have a look at the Dimensions & metrics explorer as well as the google analytics query explorer both will help you understand what data can be extracted from the API.