Google Analytics

Google Analytics (GA)

GA 是 Google 提供的一個免費的數據分析平台。目前提供了網頁與移動裝置的分析服務。

GA 提供了提供

RGoogle Analytics

GA 網站畫面

GA 網站畫面

GA 網站畫面

GA 網站畫面

先前步驟

GA Flow

RGoogleAnalytics Use Outline

安裝

install.packages(“RGoogleAnalytics”)

授權

//Using RGoogleAnalytics library

library(RGoogleAnalytics)

//Copy client id and client secret from Google Developers Consol

client.id <- “XXXXXXXX”

client.secret <- “YYYYYYYY”

//Getting Oath using Oath2

oath_token <- Auth(client.id=client.id, client.secret = client.secret)

//Save the token if you want

save(oath_token, file=“oath_token”)

獲取報表

Google Analytics 可以設置不同的報表組, 例如: Web 報表, Mobile 報表等。 以 Mobile 為例 不同的 APP 也很有可能有著不同的報表。使用 GetProfiles function 可以列出所有的報表。

// Load if nessesary

load(“oath_token”)

//Check if token validate

ValidateToken(oath_token)

// Getting Profiles

profile <- GetProfiles(oath_token)

profile

獲取資料

// if not specify table id in gaExamples.R

ga.table.id <- “ga:79915131”

// See the chart of Type of visitor

// Init 將 Query 參數做成 list

query.list <- Init(start.date = “2014-01-01”, end.date = “2014-03-15”, dimensions = “ga:userType”, metrics = “ga:users”, max.result = 500, sort = “ga:users”, filters = NULL, table.id = ga.table.id)

// build the query object 並且做 Validation

ga.query <- QueryBuilder(query.list)

// Get the ReportData

ga.data <- GetReportData(ga.query, oath_token)

ga.data

userrow <- rownames(ga.data)

pie(ga.data\(users, labels = ga.data\)userType, col = rainbow(14))

其他相關網站

相關的 Google Analytics 連結

RGoogleAnalystics 連結