Simon Breton
Simon Breton

Reputation: 2876

Google Analytics Management API and Google App Scripts.: gapi is not defined

I'm trying to get the list of all Google Analytics filters from specific views in a Google Spreadsheet but I'm totally lost in the documentations and code examples on the Management API.

There is this page:

https://developers.google.com/apps-script/advanced/analytics

and these pages:

https://developers.google.com/analytics/devguides/config/mgmt/v3

All the example shared in the Analytics Service page works correctly. However the documentation is very limited and it doesn't seem that I'm able to get Filters list from there.

Then the Analytics Service redirect to the "global" Management API documentation. All the example I'm getting from there are using gapi client library. However I don't know how to use it within Google App Scripts gapi is not defined

Curiously I'm able to get Custom Dimensions list using this script:

  var sourceProperty = 'UA-XXXXXXXXX-' 
  var sourceAccount = 'XXXXXXX' 

  // Set variable for dimensions from our source property
  var sourceDimensions = Analytics.Management.CustomDimensions.list(sourceAccount, sourceProperty)
  // var Filters = Analytics.Management.Filter(sourceAccount, sourceProperty)
  Logger.log(sourceDimensions) 

For example Analytics.Management.Filters.list(sourceAccount, sourceProperty) would do the trick but it doesn't work.

I feel like I'm missing something or there is something I don't understand or is this simply impossible?

Upvotes: 0

Views: 656

Answers (1)

Josh
Josh

Reputation: 431

I think you want the ProfileFilterLinks.list method. So something like this.

var accountId = 'XXX';
var propertyId = 'UA-XXX-X';
var viewId = 'XXXX';

var FilterLinks = Analytics.Management.ProfileFilterLinks.list(accountId, propertyId, viewId);
Logger.log(FilterLinks);

FYI: If you want to get a list of views you can use the Account summaries list command.

Also Profiles where renamed to views sometime ago.

Upvotes: 1

Related Questions