skardhamar / rga

R Google Analytics
187 stars 90 forks source link

ga real time api #71

Open jpmarindiaz opened 8 years ago

jpmarindiaz commented 8 years ago

Would it be possible to add the real time api functionalities to this package? https://developers.google.com/analytics/devguides/reporting/realtime/v3/

jdeboer commented 8 years ago

Hi @jpmarindiaz, just in case you were not aware, the ganalytics R package can be used to access the Google Analytics Real-Time reporting API. For example:

library(ganalytics)
my_creds = GoogleApiCreds(userName = "my_username@gmail.com", appCreds = "~/oauth_app_creds.json")
rt_query <- RtQuery(view = "ga:987654321", creds = my_creds)
Dimensions(rt_query) <- "rt:minutesAgo"
Metrics(rt_query) <- "rt:pageviews"
GetGaData(rt_query)

In the above example, set userName to yours that you use to access Google Analytics (this is optional, but ensures you are authenticating under the correct Google account), and set the appCreds to the path of where you have saved your Google APIs Project OAuth application credentials JSON file (which you can download from the Google APIs Console). Also set view to the ID of the Google Analytics view of which you wish to get real-time reporting data for.