\analytics_api
Synopsis
class analytics_api
{
- // methods
- public boolean login()
- public string call()
- public void load_accounts()
- public array data()
- public Returns get_summary()
- public Returns get_summaries()
- protected void curl_init()
- public void sec2hms()
Members
public
- $accounts
—
array
A list of accounts retrieved from the load_accounts() method. This is an associative array where the index is the profile name/domain name (referred to as "title" in the XML) and the values are tableId, accountId, accountName, webPropertyId, profileId and title (title being the profile name/domain name). The profileId and tableId are synonymous, although the tableId includes the ga: prefix whereas the accountId does not. It's the tableId that needs to be passed as the id to the call() method - $auth
—
string
The authorization token returned when logging in. It's used for subsequent requests. If can be used for several days after logging in so could be set from a previously used auth key rather than logging in each time.
Methods
protected
- curl_init() — Returns an instance from curl_init with all the commonly needed properties set.
public
- call() — Calls an API function using the url passed in and returns either the XML returned from the call or false on failure
- data() — Calls the API using the parameters passed in and returns the data in an array.
- get_summaries() — Gets a summary for all profiles to which this login has access, calling the get_summary() function for each account in turn and putting them into a single multi-dimensional array indexed by the account title (i.e. the same index that's used for the ->accounts array)
- get_summary() — Gets a summary for the specified profile and time range containing the number of visits, pageviews, average time on site raw and formatted, and pages per visit
- load_accounts() — Loads the list of accounts into the $this->accounts associative array. You can then access the properties by the profile's domain name.
- login() — Logs into the Google Analytics API and sets $this->auth to the authorisation token returned
- sec2hms() — This function formats seconds into h:m:s and comes from http://www.laughing-buddha.net/jon/php/sec2hms/