N
N
Nikola242017-10-07 23:29:45
Google Analytics
Nikola24, 2017-10-07 23:29:45

Is it possible to pull data using Google Analytics?

Hello. I want to make a visitor counter for the entire time on the site, as well as display the percentage of users visiting from the continents. Is it possible to collect data from Analytics and display it on my website?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikola24, 2017-10-09
@Nikola24

The google-api-php-client-2.2.0 library helped .
1) Connect it to the site
2) Create the necessary keys in https://console.developers.google.com
3) Write all the keys to a file
4) Enjoy the result

require_once 'libs/google-api-php-client-2.2.0/vendor/autoload.php'; 
  $client = new Google_Client(); $client->setApplicationName(""); // имя проекта
  $client->setAuthConfig('');  // путь на файл json с данными для автоматической аунтификации
  $client->addScope('https://www.googleapis.com/auth/analytics.readonly'); 
  $GA_VIEW_ID = 'ga:XXXXX'; // Ваш View_ID 
  $service = new Google_Service_Analytics($client); 

  try { 
    $result = $service->data_ga->get( $GA_VIEW_ID, '100daysAgo', 'today','ga:uniquePageviews'); 
    $count = $result->totalsForAllResults['ga:uniquePageviews']; 
    echo $count; 
  } catch(Exception $e) { 
    var_dump($e);
  }

D
Dimonchik, 2017-10-08
@dimonchik2013

of course
https://developers.google.com/analytics/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question