-
Notifications
You must be signed in to change notification settings - Fork 48
Management: Accounts, WebProperties, Profiles
Google Analytics provides specific access to the Management api so that you can query to find exactly the profile (or profiles) you want to be working with.
An Account
appears to be the highest level, and contains a set of WebProperty
groups. A WebProperty
is most commonly identified by the id string used in the javascript on each page you're tracking.
Within each WebProperty
are profiles. A Profile
is what we need to provide the API when we query for reporting data. So, the first task is to find which Profile
accessible by the user
is the one we want.
Most of the time, I have access to only a few profiles at a time, so doing user.profiles.select {|profile| profile.id == 12345}
is usually sufficient. If you need to query through the other layers, these are some of the methods available:
# query for all Accounts, WebProperties, or Profiles on a user
Legato::Management::Account.all(user)
Legato::Management::WebProperty.all(user)
Legato::Management::Profile.all(user)
# do the same, but from the user itself
user.accounts
user.web_properties
user.profiles
# an account has web_properties and profiles
user.accounts.first.web_properties
user.accounts.first.profiles
# a web_property has further profiles
user.accounts.first.web_properties.first.profiles
Note: each of the calls to #accounts
, #web_properties
, and #profiles
triggers an API request to GA.