Description Usage Arguments Value See Also Examples
Get Google Analytics v3 data
1 2 3 4 5 |
id |
A character vector of View Ids to fetch from. |
start |
Start date in YYY-MM-DD format. |
end |
End date in YYY-MM-DD format. |
metrics |
A character vector of metrics. With or without ga: prefix. |
dimensions |
A character vector of dimensions. With or without ga: prefix. |
sort |
How to sort the results, in form 'ga:sessions,-ga:bounceRate' |
filters |
Filters for the result, in form 'ga:sessions>0;ga:pagePath=~blah' |
segment |
How to segment. |
samplingLevel |
Choose "WALK" to mitigate against sampling. |
max_results |
Default 100. If greater than 10,000 then will batch GA calls. |
multi_account_batching |
If TRUE then multiple id's are fetched together.
Not compatible with |
type |
ga = Google Analytics v3; mcf = Multi-Channel Funels. |
For one id a data.frame of data, with meta-data in attributes. For multiple id's, a list of dataframes.
https://developers.google.com/analytics/devguides/reporting/core/v3/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | ## Not run:
library(googleAnalyticsR)
## Authenticate in Google OAuth2
## this also sets options
ga_auth()
## if you need to re-authenticate use ga_auth(new_user=TRUE)
## if you have your own Google Dev console project keys,
## then don't run ga_auth() as that will set to the defaults.
## instead put your options here, and run googleAuthR::gar_auth()
## get account info, including View Ids
account_list <- google_analytics_account_list()
ga_id <- account_list$viewId[1]
## get a list of what metrics and dimensions you can use
meta <- google_analytics_meta()
head(meta)
## pick the account_list$viewId you want to see data for.
## metrics and dimensions can have or have not "ga:" prefix
gadata <- google_analytics(id = ga_id,
start="2015-08-01", end="2015-08-02",
metrics = c("sessions", "bounceRate"),
dimensions = c("source", "medium"))
## multi accounts, pass character vector of viewIds
## outputs a list of data.frames, named after the viewId
multi_gadata <- google_analytics(id = c("123456","9876545","765432"),
start="2015-08-01", end="2015-08-02",
metrics = c("sessions", "bounceRate"),
dimensions = c("source", "medium"))
## if more than 10000 rows in results, auto batching
## example is setting lots of dimensions to try and create big sampled data
batch_gadata <- google_analytics(id = ga_id,
start="2014-08-01", end="2015-08-02",
metrics = c("sessions", "bounceRate"),
dimensions = c("source", "medium",
"landingPagePath",
"hour","minute"),
max=99999999)
## mitigate sampling by setting samplingLevel="WALK"
## this will send lots and lots of calls to the Google API limits, beware
walk_gadata <- google_analytics(id = ga_id,
start="2014-08-01", end="2015-08-02",
metrics = c("sessions", "bounceRate"),
dimensions = c("source", "medium", "landingPagePath"),
max=99999999, samplingLevel="WALK")
## multi-channel funnels set type="mcf"
mcf_gadata <- google_analytics(id = ga_id,
start="2015-08-01", end="2015-08-02",
metrics = c("totalConversions"),
dimensions = c("sourcePath"),
type="mcf")
## reach meta-data via attr()
attr(gadata, "profileInfo")
attr(gadata, "dateRange")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.