if (FALSE) {
# to use default package credentials (for testing)
library(googleAnalyticsR)
ga_auth()
# to use your own Google Cloud Project credentials
# go to GCP console and download client credentials JSON
# ideally set this in .Renviron file, not here but just for demonstration
Sys.setenv("GAR_CLIENT_JSON" = "location/of/file.json")
library(googleAnalyticsR)
# should now be able to log in via your own GCP project
ga_auth()
# reauthentication
# Once you have authenticated, set email to skip the interactive message
ga_auth(email = "my@email.com")
# or leave unset to bring up menu on which email to auth with
ga_auth()
# The googleAnalyticsR package is requesting access to your Google account.
# Select a pre-authorised account or enter '0' to obtain a new token.
# Press Esc/Ctrl + C to abort.
#1: my@email.com
#2: work@mybusiness.com
# you can set authentication for many emails, then switch between them e.g.
ga_auth(email = "my@email.com")
ga_account_list() # lists one set of accounts
ga_auth(email = "work@mybusiness.com")
ga_account_list() # lists second set of accounts
# or authenticate via the service key, that has been added to the GA as a user
ga_auth(json_file = "service-key.json")
}
Run the code above in your browser using DataLab