View source: R/Overview_PageBusinessAnalysis.R
1 | pageBusinessAnalysis(ClientID, ClientSecret, ViewID, StartDate, EndDate, SplitDaywise = T)
|
ClientID |
|
ClientSecret |
|
ViewID |
|
StartDate |
|
EndDate |
|
SplitDaywise |
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 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (ClientID, ClientSecret, ViewID, StartDate, EndDate,
SplitDaywise = T)
{
checkPackages("RGoogleAnalytics", "httpuv", "ggplot2", "scales",
"sqldf")
library(httpuv)
library(ggplot2)
library(RGoogleAnalytics)
library(scales)
library(sqldf)
token <- Auth(ClientID, ClientSecret)
ValidateToken(token)
query.list <- Init(start.date = toString(StartDate), end.date = toString(EndDate),
dimensions = "ga:pageTitle", metrics = "ga:uniquePageviews,ga:pageviews,ga:entranceRate,ga:bounceRate,ga:avgTimeOnPage,ga:pageValue",
max.results = 1000, sort = "-ga:uniquePageviews", table.id = ViewID)
ga.query <- QueryBuilder(query.list)
ga.data <- GetReportData(ga.query, token, split_daywise = SplitDaywise)
quartiles <- quantile(ga.data$uniquePageviews)
sqlQuery <- paste("select * from [ga.data] where uniquePageviews > ",
as.character(quartiles[2]), " order by pageValue desc LIMIT 20")
topValuedPages <- sqldf(sqlQuery)
p1 <- ggplot(data = topValuedPages, aes(x = pageTitle, y = uniquePageviews)) +
geom_bar(stat = "identity", fill = "#0072B2") + ggtitle("Top Valued Pages Unique Page Views") +
coord_flip()
p2 <- ggplot(data = topValuedPages, aes(x = pageTitle, y = pageValue)) +
geom_bar(stat = "identity", fill = "#D55E00") + ggtitle("Top Valued Pages Values") +
coord_flip()
multiplot(p1, p2, cols = 2)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.