Search code examples
google-analyticsanalyticsgoogle-analytics-api

Subdomain as a filter (Google Analytics API)


We are new to Google Analytics (GA), and we are trying to figure out if we should use it for our use case, which is:

Suppose that we have a domain, say example.com
And we have hundreds of users.
And each user should get his/her own 'website' which actually is a subdomain of our site
(e.g. steve.example.com)

We would like to -
-----------------------
1. not require each user create a separate GA account (& code).
2. show each user's web-analytics stats in his/her own site

To get the above, will the following work ?
------------------------------------------------
1. we will create 1 GA account/tracking-code for example.com
2. we will use Google Analytics API to get data
3. to retrieve data only for 1 subdomain (user), we will specify the respective subdomain as a filter
4. using retrieved data, we will draw Tables & Charts using javascript libraries like Google Charts

Is 3 possible ? i.e. Will we be able to send queries to Google Analytics API that include subdomain as one of the filters (alongwith Metrics & Dimensions like PageViews & Location) ?

Research/Reading that I have done:
---------------------------------------------
1. Most solutions are pointing towards creating separate Profiles for different SubDomains, but this is not an option for us, since there are so many of them, and also 50 seems to be a limit on the number of Profiles that each Domain can have (from https://developers.google.com/analytics/resources/concepts/gaConceptsAccounts )
2. Google Analytics does not allow tracking codes/profiles to be created via API


Solution

  • I would suggest going over the domain tracking documentation first, there are lot of details and settings that could make things complicated.

    As for the reports and whether to create a dynamic segment or a filter -- it depends on what you want to show. If it is visitors/pageviews/etc. for a given subdomain (blog.example.com), I would go for the filter, because if you create a dynamic segment, it will give you the total numbers of pageviews generated on other subdomains / main site as well (segment works like that, it includes all visit-data, see this article for details).

    Don't worry about the reporting profiles (or views as they are called now). You are going to have just one including all the data (see the documentation about setting up correct filters for subdomain tracking).