The marketeR
package provides a web analytics toolbox for digital marketers using Google Analytics.
Main features:
- Automatic reports
- Week KPIs assessment
- KPIs forecasts
With marketeR, navigate the ocean of web data with the speed of a swordfish 🐟 !
Open a new R session, and run the following code:
install_github("naileakim/marketeR")
library("marketeR")
Note: If you get the error Error: could not find function "install_github"
, you might need to install / load the package devtools
first:
install.packages("devtools")
library("devtools")
The marketeR package is using the Google Analytics Reporting API V4 to get the data you need, and require you to be authentified with an access token. To start using marketeR, please follow the instructions below:
- Login with your Google Analytics account
- Go to Google Developers Console.
- Click on
Select a project
, then onCreate project
. - Click on the
API Manager
tab in the sidebar, search forAnalytics Reporting API V4
. After clicking on it, click onEnable
. - Click on the
Credentials
tab in the sidebar, then onCreate credentials
, select theOauth 2.0 client ID
option, check theOther
box, give aName
and click onCreate
. - You should now be able to get your
Client ID
andClient secret
.
Open a new R session, and run the following code with your credentials:
client.id <- "PASTE HERE YOUR CLIENT ID"
client.secret <- "PASTE HERE YOUR CLIENT SECRET"
Create your token object, then validate it:
token <- Auth(client.id, client.secret)
ValidateToken(token)
You can also save your token for future sessions:
save(token, file="./token_file")
So that in future sessions, you don't need to create a new token, you can just load it:
load("./token_file")
ValidateToken(token)
The report
function returns a report presenting your website KPIs during the last month, and their evolution over a one year period.
report(website)
- website: The unique Google Analytics table ID of the form ga:XXXXXXX, where XXXXXXX is the Analytics view (profile) ID for which the query will retrieve the data.
report(website = "ga:XXXXXXX")
The output file will be generated in your working directory. Don't know where is your working directory ? Type getwd()
in the R console.
The weekperf
function returns a plot designed to assess your website KPIs during the past 7 days.
weekperf(kpi, website, export)
-
kpi: A Google Analytics metric, such as ga:metrics.
-
website: The unique Google Analytics table ID of the form ga:XXXXXXX, where XXXXXXX is the Analytics view (profile) ID for which the query will retrieve the data.
-
export: If the export option is set as "TRUE", both raw data & graphics will be exported in the current working directory.
weekperf(kpi = "ga:sessions", website = "ga:XXXXXXX", export = TRUE)
The triangles are representing the results of the past 7 days. Their color may vary according to the mean (green is > mean, red is < mean). The mean is represented by the letter m
.
The forecast
function makes forecasts for your website KPIs for the next 3 months, using time-series.
forecast(kpi, website, export)
-
kpi: A Google Analytics metric, such as ga:metrics.
-
website: The unique Google Analytics table ID of the form ga:XXXXXXX, where XXXXXXX is the Analytics view (profile) ID for which the query will retrieve the data.
-
export: If the export option is set as "TRUE", both raw data & graphics will be exported in the current working directory.
forecast(kpi = "ga:sessions", website = "ga:XXXXXXX", export = FALSE)
The black part is the past website traffic data; the blue part is the graphical representation of the forecast.
Félix MIKAELIAN felix.mikaelian@essec.edu 🇫🇷
- RGoogleAnalytics
- forecast
- lubridate
- timeDate
- zoo
- plyr
- dplyr
- grid
- scales
- ggplot2
- ggthemes
- rmarkdown
- knitr
- The marketeR package is under license GPL (>= 2).
- The marketeR logo is using the "Enriqueta" font by FontFuror.
- The marketeR logo is using the icon "Swordfish" by Catalina Montes.
I would love ideas to make marketeR better, so feel free to contribute to this exciting project ✌️ !