Google Analytics API dimensions vs metrics

The Google Analytics API has dimension and metric fields for getting data. If just a metric is specified then the data returned is for the time period as a whole. If dimensions are also supplied then the data is segmented by the metric. This post looks at the XML returned when a dimension is supplied and when it is not.

What is a dimension?

Dimensions are segments like browser and browser version, country, landing and exit pages, the URL or title of a page, and the source website a visitor has come from.

What is a metric?

Metrics are the counts of a dimension for specific data types, such as counts of new visitors, page views, unique pageviews and so on.

Retrieving data for a metric

If you were going to get the count of pageviews and unique pageviews for an account profile as a whole without specifying a dimension, you would specify “ga:pageviews,ga:uniquePageviews” as the metric when making the API call. Example XML output for this for my blog would be something like this:

<entry>
 <id>http://www.google.com/analytics/feeds/data?ids=ga:7426158&&start-date=2009-04-04&end-date=2009-05-03</id>
 <updated>2009-05-02T17:00:00.001-07:00</updated>
 <title type="text"/>
 <link rel="alternate" type="text/html" href="http://www.google.com/analytics"/>
 <dxp:metric confidenceInterval="0.0" name="ga:pageviews" type="integer" value="111634"/>
 <dxp:metric confidenceInterval="0.0" name="ga:uniquePageviews" type="integer" value="101403"/>
 </entry>
 

Note that there are two separate dxp:metric nodes which store the metric name in a name element and the value element of the node is the count for that metric. Because no dimension was specified there will only be one <entery> node.

Retrieving data for the dimension vs metric

If the “ga:pagePath” was used the the dimension value then there will be a number of <entry> nodes equal to or less than the max-results value of the API call. Some example output for one of the <entry> nodes from my blog is as follows:

<entry>
 <id>http://www.google.com/analytics/feeds/data?ids=ga:7426158&ga:pagePath=/jquery-get-set-form-values/&start-date=2009-04-04&end-date=2009-05-03</id>
 <updated>2009-05-02T17:00:00.001-07:00</updated>
 <title type="text">ga:pagePath=/jquery-get-set-form-values/</title>
 <link rel="alternate" type="text/html" href="http://www.google.com/analytics"/>
 <dxp:dimension name="ga:pagePath" value="/jquery-get-set-form-values/"/>
 <dxp:metric confidenceInterval="0.0" name="ga:pageviews" type="integer" value="2903"/>
 <dxp:metric confidenceInterval="0.0" name="ga:uniquePageviews" type="integer" value="2684"/>
 </entry>
 

Note that there is now an additional <dxp:dimension> node which specifies the dimension name and value as elements of the node. A script parsing data from this XML would need to loop through the <entry> nodes and extract the dimension names and values, and metric names and values into some sort of array or other data format to be able to use it.

PHP Analytics API Class

I have written and am continuing to develop and PHP Class for accessing the Google Analytics API which converts the above XML into easy to use arrays. Please refer to my Google Analytics API and PHP Series for more details and to download the class.

Get the ID for the Google Analytics API IDS parameter

Google announced an API for the Google Analytics product last week and I posted the start of a PHP class for using the API on Thursday and will post extensions to the class for getting data from the XML this week. In order to get data you need to know the ID for the Google Analytics Account Profile and this post looks at one way to get it without needing any programming code.

Using the Analytics Web Interface

Log into Google Analytics. The table in the main section of the welcome area has a list of your accounts as shown in the example screenshot below. (I have a number of accounts under my login but have Photoshopped them out). Click the account name you want to get the ID for. Where to click is highlighted with the red arrow in the screenshot below.

select the google analytics account

Next you’ll see a list of profiles for the account. Click “View Report” next to the profile you want the ID for. Note that the ID is not the same as the UA-XXXX-XX style code which is shown on this page and what is in the Javascript code that it added to your web pages. Again, the red arrow shows what to click (and I’ve again Photoshopped out the other profiles under this account).

select the analytics profile

Now that you’re on the account profile page look in the browser address bar and you can see the ID there. I’ve highlighted the ID with a red box in the screenshot below. The ID is 7426158 in this example.

get the id from the browser address bar

API Call

The API call to https://www.google.com/analytics/feeds/accounts/default will return a list of all account IDs you have access to with your login and password and is another way to get the IDs. I will show how to do this tomorrow.

Disable auto renew at GoDaddy

I use GoDaddy to register my domain names and secure certificates. When a new product is bought from GoDaddy it will be default set to auto-renew. I prefer to manually renew everything and this post shows how to disable auto renewal at GoDaddy. Following these instructions you can also change a product from not auto-renewing to auto-renew.