The marketeR
package provides a web analytics toolbox for digital marketers using Google Analytics.
Main features:
With marketeR, navigate the ocean of web data with the speed of a swordfish :fish: !
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:
Select a project
, then on Create project
.API Manager
tab in the sidebar, search for Analytics Reporting API V4
. After clicking on it, click on Enable
.Credentials
tab in the sidebar, then on Create credentials
, select the Oauth 2.0 client ID
option, check the Other
box, give a Name
and click on Create
.Client ID
and Client 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)
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 :fr:
I would love ideas to make marketeR better, so feel free to contribute to this exciting project :v: !
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.