internalSearchAnalysis: Internal Search Analysis

Usage Arguments Examples

View source: R/Overview_InternalSearchAnalysis.R

Usage

1
internalSearchAnalysis(ClientID, ClientSecret, ViewID, StartDate, EndDate, SplitDaywise = T)

Arguments

ClientID
ClientSecret
ViewID
StartDate
EndDate
SplitDaywise

Examples

 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
##---- 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:searchKeyword,ga:source", metrics = "ga:searchUniques,ga:searchExitRate,ga:searchResultViews,ga:searchRefinements,ga:totalEvents,ga:goalCompletionsAll", 
        max.results = 1000, sort = "-ga:searchUniques", table.id = ViewID)
    ga.query <- QueryBuilder(query.list)
    ga.data <- GetReportData(ga.query, token, split_daywise = SplitDaywise)
    topSearchedKeywords <- sqldf("select searchKeyword, sum(searchUniques) as searchUniques from [ga.data] group by searchKeyword order by searchUniques desc LIMIT 20")
    sqlQuery <- "select * from [ga.data] WHERE searchKeyword IN (select searchKeyword from topSearchedKeywords)"
    topSearchedKeywordsWithSources <- sqldf(sqlQuery)
    g1 <- ggplot(data = topSearchedKeywordsWithSources, aes(x = searchKeyword, 
        y = searchUniques, fill = source)) + geom_bar(stat = "identity") + 
        coord_flip()
    print(g1)
  }

erenturunc/AnalyticsMiner documentation built on May 20, 2019, 4:09 p.m.