GA 是 Google 提供的一個免費的數據分析平台。目前提供了網頁與移動裝置的分析服務。
GA 提供了提供
分析的工具
內容分析
社交分析
行動分析
轉換分析
廣高分析
GA 網站提供了大部分的資料分析服務。但如果使用者需要
自製分析圖表
對資料進行進一步分析
自定義資料進行分析
就需要進行資料的提取與分析。
RGoogleAnalytics 是一個R 套件,可以抓取GA 網站上資料到 R 做分析
GA 網站畫面
GA 網站畫面
而後, 你需要到 Google Developers Console 申請使用 Google Api 的授權
獲得 Google Api 授權後, 記下 Client id 跟 Client Secret
Install Library
Authentication - Oath2
Get Profile
Get Data
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))
Query Explore 提供網頁介面使用 Core Reporting API (核心報表 API)
Dimensions & Metrics Explorer Matrics 和 Dimensions 的文件