7
votes

I am creating a dashboard to show both Monthly Active Users and Weekly Active Users from Google Analytics.

To query this data I am using the following parameters:

{
  "ids" => @account_id,
  "start-date" => start_date.to_s,
  "end-date" => end_date.to_s,
  "metrics"=> "ga:users",
  "samplingLevel" => "HIGHER_PRECISION"
}

For example, to get Weekly Active Users for each day I'm passing a 7 day interval and for Monthly Active Users I'm using 30 day interval.

The point is that numbers are significantly different comparing to what I've seen in the interface at Audience > Active Users.

I couldn't figure out a query to get the same data from the interface. Do you have any idea?

thanks :)

2

2 Answers

16
votes

I don't think they're currently documented, but you can actually use the following metrics in your API requests:

  • ga:1dayUsers
  • ga:7dayUsers
  • ga:14dayUsers
  • ga:30dayUsers

Note that ga:1dayUsers and ga:users are essentially the same thing, but ga:users and any of the active users metrics cannot be combined in the same request, so if you want to compare you should use ga:1dayUsers.

Update

Queries that use any of the active users metrics mentioned above must be combined with a day dimension (e.g. ga:date) in order to work.

1
votes

The following code should be able to help you collect this data in a single dataframe.

Please note that more than 1 type of variable cannot be captured in the query i.e. at a time, only one of the 1/7/14/28/30 day users can be queried.

At any given point in this on a particular date, the data will be rolled up i.e. If you observe 14 day User data on say 15th of the month then it will be unique users from 1st to 14th. for 16th this will be from 2nd to 15th and so on.

Hope this helps. R Code:

unique_1dayUser_data<-google_analytics(ga_id_raw,date_range=c(start_date,end_date),metrics=c("1dayUsers"),dimensions=c("date"))
unique_7dayUser_data<-google_analytics(ga_id_raw,date_range=c(start_date,end_date),metrics=c("7dayUsers"),dimensions=c("date"))
unique_14dayUser_data<-google_analytics(ga_id_raw,date_range=c(start_date,end_date),metrics=c("14dayUsers"),dimensions=c("date"))
unique_28dayUser_data<-google_analytics(ga_id_raw,date_range=c(start_date,end_date),metrics=c("28dayUsers"),dimensions=c("date"))
unique_30dayUser_data<-google_analytics(ga_id_raw,date_range=c(start_date,end_date),metrics=c("30dayUsers"),dimensions=c("date"))

unique_user_data<-cbind(unique_1dayUser_data,unique_7dayUser_data$`7dayUsers`,unique_14dayUser_data$`14dayUsers`,
                        unique_28dayUser_data$`28dayUsers`,unique_30dayUser_data$`30dayUsers`)

colnames(unique_user_data)<-c("Date","1 Day users","7 Day users","14 Day users","28 Day users","30 Day users")