Search code examples
google-apps-scriptgoogle-analyticsgoogle-analytics-api

How to access Google Analytics Filters for a specific View or Property via API


I am trying to access filters within a specific view for Google Analytics via the API. From everything I can see I can only access the filters for the entire account and there is no denoting within the response which Web Property, Profile, or even View that filter is for.

Looking to either be able to access just the filters within a View OR be able to denote which view a filter lives in within the account response, because then I can loop through those and just pull out the filters for the specific view I am looking for.

Ultimately I am trying to build a way for me to list all of the filters I have across multiple accounts and update things en-mass, like when someone moves or has their IP address updated. I am currently using Google App Scripts which has the built in Google Analytics Service. Using that, I can quickly get the filters with

var filters = Analytics.Management.Filters.list(accountID);
Logger.log(filters)

but as you can imagine (or test if you are so inclined), this logs/returns ALL the filters for the Account ID listed. This response shows the following info (redacted info and changed formatting a bit to display nicer)

{accountId=XXXXX,
parentLink={
href=XXXXX},
excludeDetails={
expressionValue=XXXXX,
field=XXXXX,
kind=XXXXX,
matchType=XXXXX,
caseSensitive=XXXXX},
kind=XXXXX,
created=XXXXX,
name=XXXXX,
id=XXXXX,
type=XXXXX,
updated=XXXXX,
selfLink=XXXXX}

none of which shows the Web Property, Profile, or View.

So, how can filters within a specific view be accessed or the view of filter be seen?


Solution

  • You’re looking for profile filter links

    https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profileFilterLinks#resource