I am trying to connect to google analytic s API through a script running on R studio server.
I have followed steps from this tutorial:
http://www.r-bloggers.
One suggestion would be to use a Google Service Account. The googleAuthR package by Mark Edmondson, available through CRAN, provides functionality to perform server-side authentication in R using a Google Service Account. Another package by the same author called googleAnalyticsR, also on CRAN, integrates with googleAuthR
and uses the resulting authentication token to execute queries against the Google Analytics Reporting APIs, including the latest version, 4.0.
To achieve this:
googleAuthR
(see the example below.):The following example R script references the JSON file containing the private key and performs a basic Google Analytics reporting query. Remember to set the json_file
argument to the appropriate file path and the id
argument to the appropriate Google Analytics view:
library(googleAuthR)
library(googleAnalyticsR)
gar_auth_service(
json_file = "API Project-xxxxxxxxxxxx.json",
scope = "https://www.googleapis.com/auth/analytics"
)
google_analytics(id = "123456789", start = "2016-06-01", end = "2016-06-28")