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.
- 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.
- Wait for an hour
- 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).
- 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.
- Use the Google Drive API to fetch the contents of the file reference you got from step (4)