Reputation: 167
Ok, so I am trying to programmatically add filters to a google analytics view. The guide google puts out:
The guide shows you how to insert a filter. But this filter is created at the account level and then you need to add it to a specific view. How can I add it to a view?
Upvotes: 1
Views: 219
Reputation: 5168
You need to create a profile filter link:
# Note: This code assumes you have an authorized Analytics service object.
# See the Filters Developer Guide for details.
# This request creates a new profile filter link.
try:
analytics.management().profileFilterLinks().insert(
accountId='123456',
webPropertyId='UA-123456-1',
profileId='7654321',
body={
'filterRef': {
'id': '1223334444'
}
}
).execute()
except TypeError, error:
# Handle errors in constructing a query.
print 'There was an error in constructing your query : %s' % error
except HttpError, error:
# Handle API errors.
print ('There was an API error : %s : %s' %
(error.resp.status, error.resp.reason))
Upvotes: 1