Search code examples
google-analyticsreal-timegoogle-analytics-apigoogle-analytics-firebase

Google Analytics in real time for personalization


Is there a way in Google Analytics to get a visitors information in real time in order to personalize content?

For example, visitor A comes from Google using the "widgets" keyword and using a Chrome browser so I want to show him content related to Chrome based widgets.


Solution

  • Google Analytics provides a Real Time Reporting API as a developer preview in limited beta.

    Real Time Reporting API Private Beta access request form.

    With all the limitations that this means it may be worth giving a try.
    You can find Java, PHP, and Python code examples on the documentation page: https://developers.google.com/analytics/devguides/reporting/realtime/v3/reference/data/realtime/get


    In PHP this is the anatomy of the call to the API:

    $optParams = array(
        'dimensions' => 'rt:medium');
    
    try {
      $results = $analytics->data_realtime->get(
          'ga:56789',
          'rt:keyword',
          $optParams);