GAplotR is a simple tool which generates chart image files from Google Analytics data. Its purpose is:
- Query Google Analytics data by its API (using googleAnalyticsR package)
- Generate chart image (using ggplot2 package)
- Data from Google Analytics
- Can do OAuth itself, or get credentials(access tokens and refresh tokens) from outside
- Can cache the latest data to reduce the response time and manage API quota
- Chart generation
- Supports Line chart, Bar chart, and Table
- For Line and Bar chart, can display multiple metrics at the same time.
- Output format: PNG
GAplotR is still under development. You can install this package by using devtools
library(devtools)
install_github('hkjinlee/gaplotr')
You need to start from adding new views of Google Analytics.
Create ga
directory under your working directory, and put a per-site configuration file there, which looks like this. Change view_id
to one of your own.
{
"site_name": "some_project"
"view_id": "ga:XXXXXXX"
}
You can add as many views at the same time. Configuration files can have any name you like, once it has '.json' extension.
hkjinlee-mac:ga hkjinlee$ ls
onestore_app.json onestore_web.json
- gaplotr caches the credentials after the first authentication is successfully finished. The credentials will be written in the JSON file per view.
library(gaplotr)
gaplotr <- gaplotr::gaplotr()
You can create your own configuration file for customization. For configuration file format, please refer to default config file. These default values are overridden by custom configuration, if any.
library(gaplotr)
gaplotr <- gaplotr::gaplotr('path/to/configfile.json')
The example below will generate three charts, of which output directory is figure
under cwd
.
library(gaplotr)
gaplotr <- gaplotr::gaplotr()
getChartParams <- function(type) {
list(
type = type,
title = paste(type, '차트'),
filename = paste0(type, 'chart.png')
)
}
ga_params <- list(
site_name = 'onestore_app',
view_id = 'XXXXXXXX'
)
query <- list(
dimensions = "ga:date",
metrics = c("ga:users", "ga:newUsers"),
`start-date` = "7daysAgo",
`end-date` = "today"
)
gaplotr$generateChart(ga_params, getChartParams('line'), query)
gaplotr$generateChart(ga_params, getChartParams('bar'), query)
gaplotr$generateChart(ga_params, getChartParams('table'), query)