简体   繁体   中英

Get all data from Google Analytics

I am new to Google Analytics (started with it 1 week ago) and I am trying to pull all the data available for a specific day and insert it into a mysql database. I want to get everything that is available for that specific day.

$optParams = array( //OPTINAL SETTINGS
          'dimensions' => 'ga:campaign, ga:medium, ga:source, ga:adContent, ga:keyword', //A comma-separated list of Multi-Channel Funnels dimensions. E.g., 'mcf:source,mcf:medium'. (string)
          'metrics' => 'ga:adClicks, ga:adCost, ga:goalValueAll, ga:goal1Completions, ga:goal6Completions',
          'max-results' => 10000,
          'samplingLevel' => 'HIGHER_PRECISION'
          ); //The maximum number of entries to include in this feed. (integer)

       $requestedInfo = '';
       $requestedInfo .= 'ga:sessions';


$data = $analytics->data_ga->get('ga:XXXXX', '2015-04-07', '2015-04-07', $requestedInfo, $optParams);

This code will get me far less results than I can get on the platform when combining two dimensions (primary dimension, secondary dimension). I get thousands of records for specific combinations and with my code I get something in the range of 600. I would like to know how I can format my query to get all the data available (all the records available) and then sort it however I want to.

Also, should I create a different MySQL table for each campaign, medium etc or one that include all is enough?

A few things to note:

First of all you aren't going to be able to get ALL of your data . You are limited to 10000 requests against the api each day per profile id (view). With a max number of rows of 10000. It will be very hard for you to get ALL your data even if its a small site and the data probably wont relate back to itself correctly.

Second you are limited to 8 dimensions even if you use the date as your primary key the data that is returned will not relate back to itself correctly because the data is calculated based upon the initial request that you made.

Third large queries are going to sample data even if you set it to higher_percission.

Your issue:

As to why your returning less results. I think you should try using the query explorer to play around with your requests a little. ga:keyword if its not set then it wont return anything in some cases. Its your query that is reducing the number of rows.

You need to think of the Google Analytics data as a multidimensional database instead of a relational database. There is a difference.

Big Query

A better approach would be to have Google extract your Data for you into Big Query this will allow you to do what ever you want with it. The limitations of the API do not apply to Google Analytics Data in Big query. This requires that you have a Premium Google Analytics account

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