简体   繁体   中英

How to store unsampled reports from Google Analytics API to Google Drive?

I read this instruction on how to retrieve data for unsampled reports from Google Analytics API to Google Drive: https://developers.google.com/analytics/devguides/config/mgmt/v3/unsampled-reports#introduction

As far as I understand, here are the steps to retrieve unsampled reports: 1. Store the unsampled reports to Google Drive API 2. Use Drive API to download the file

However, I couldn't find the instructions on how to store the unsampled reports to Google Drive API. Could you please tell me in details on how to do this? Also if you could, please tell me how to use Drive API to download the file as well.

Thank you in advance.

First of all, Unsampled Report is only available to Google Analytics 360 (Previously Google Analytics Premium) users. So if you use only the free version of the product this feature is simply not available, the API should give you an error.

The Unsampled API has 3 methods:

  • insert - Creates a new Unsampled Report
  • get - Get the status of a given Unsampled Report
  • list - list the status of all unsampled reports you created in a given profileId

Now you have to keep in mind that Unsampled Reports can take a few hours to be generated. So the dynamics of using the Unsampled Reporting API are obviously a bit different from the Core Reporting API. After a query on the Core Reporting API you get the results right away. With the Unsampled API you just create a report and have to wait for it to be ready.

Here's, roughly, how exporting data from the Unsampled API works.

  1. Use the insert method on the API to create a new Unsampled Report. The Response will probably have a status: PENDING which means the report is being processed. You want to store the id parameter you get from this request.
  2. Wait for an hour
  3. Use the id from step (1) and issue a get request to the API. This will give you the current status of the unsampled report. If this is still PENDING go back to step (2).
  4. If the status is COMPLETE the report should be complete and already waiting for you in Google Drive. The API should return a driveDownloadDetails.documentId you want to store this.
  5. Use the Google Drive API to fetch the contents of the file reference you got from step (4)

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