{"id":9380,"date":"2017-04-21T10:00:50","date_gmt":"2017-04-21T01:00:50","guid":{"rendered":"http:\/\/sitest.jp\/blog\/?p=9380"},"modified":"2017-04-21T09:58:15","modified_gmt":"2017-04-21T00:58:15","slug":"r%e8%a8%80%e8%aa%9e%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6google-analytics%e3%81%ae%e3%83%87%e3%83%bc%e3%82%bf%e3%82%92%e8%a7%a3%e6%9e%90%e3%81%97%e3%82%88%e3%81%86%ef%bc%81r%e8%a8%80%e8%aa%9e%e5%ae%9f","status":"publish","type":"post","link":"https:\/\/sitest.jp\/blog\/?p=9380","title":{"rendered":"R\u8a00\u8a9e\u3092\u4f7f\u3063\u3066Google Analytics\u306e\u30c7\u30fc\u30bf\u3092\u89e3\u6790\u3057\u3088\u3046\uff01R\u8a00\u8a9e\u5b9f\u8df5\u7de8"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u30d7\u30ed\u30c0\u30af\u30c8\u958b\u767a\u30c1\u30fc\u30e0\u306e\u7267\u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/sitest.jp\/blog\/?p=8950\">R\u8a00\u8a9e\u57fa\u790e\u5165\u9580<\/a>\u3001<a href=\"http:\/\/sitest.jp\/blog\/?p=9221\">R\u8a00\u8a9e\u30b0\u30e9\u30d5\u5165\u9580<\/a>\u3068R\u8a00\u8a9e\u306e\u5165\u9580\u8a18\u4e8b\u3092\u66f8\u3044\u3066\u304d\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306f\u3088\u3046\u3084\u304f\u5b9f\u8df5\u7de8\u3068\u3044\u3046\u3053\u3068\u3067Google Analytics\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057R\u8a00\u8a9e\u3067\u89e3\u6790\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\u4e8b\u524d\u6e96\u5099<\/h3>\n<\/div>\n<p>R\u8a00\u8a9e\u306e\u5b9f\u884c\u74b0\u5883\u3068\u3057\u3066\u306fRStusio\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\n\u307e\u305f\u3001Google Analytics\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u306f\u6ca2\u5c71\u3042\u308b\u306e\u3067\u3059\u304c\u3001<br \/>\n\u4eca\u56de\u306f\u6bd4\u8f03\u7684\u4f7f\u3044\u3084\u3059\u3044\u300c<a href=\"https:\/\/github.com\/artemklevtsov\/RGA\" rel=\"nofollow\">RGA<\/a>\u300d\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u306b\u306fRStudio\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u753b\u9762\u3067\u3001<\/p>\n<pre><code>install.packages(\"RGA\")<\/code><\/pre>\n<p>\u3092\u5b9f\u884c\u3059\u308c\u3070\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<p>\u6b21\u306b\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u305f\u3044Analytics\u306e\u30d3\u30e5\u30fcID\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\n\u300c\u7ba1\u7406\u300d\u306e\u30d3\u30e5\u30fc\u30da\u30fc\u30b8\u304b\u3089\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30d3\u30e5\u30fcID\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2017\/04\/1462271471160f5704ccca1346e4f277.png\"><img loading=\"lazy\" src=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2017\/04\/1462271471160f5704ccca1346e4f277.png\" alt=\"\" width=\"918\" height=\"470\" class=\"alignnone size-full wp-image-9698\" \/><\/a><\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\u65e9\u901f\u4f5c\u3063\u3066\u307f\u3088\u3046<\/h3>\n<\/div>\n<p>\u305d\u308c\u3067\u306fRGA\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066Google Analytics \u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code class=\"r\"># Include Library\nlibrary(RGA)\nlibrary(dplyr)\n\n# GA OAuth\nauthorize()\n\n# Get profile\nprof_list <- list_profiles() %>%\n  dplyr::filter(id == {{ViewID}})\nprof_list$id # GA profile id\n\n# Get Sessions Data\ns.data <- get_ga(profileId = prof_list$id,\n       start.date = \"2017-01-01\",\n       end.date = \"2017-03-31\",\n       metrics = \"ga:sessions\",\n       dimensions = \"ga:date\")\n# Get Pvs Data\np.data <- get_ga(profileId = prof_list$id,\n       start.date = \"2017-01-01\",\n       end.date = \"2017-03-31\",\n       metrics = \"ga:pageviews\",\n       dimensions = \"ga:date\")\n\n# Plot\nplot(as.Date(s.data$date), s.data$sessions, type = \"l\", ylim = c(0, 13000), ann = FALSE)\npar(new=T)\nplot(as.Date(p.data$date), p.data$pageviews, type = \"l\", col = \"blue\", ylim = c(0, 13000), ann = FALSE)\n<\/code><\/pre>\n<p>\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8aad\u307f\u8fbc\u307f\u3001authorize\u95a2\u6570\u3067Google\u3068\u9023\u643a\u3057\u307e\u3059\u3002<br \/>\nlist_profiles\u95a2\u6570\u306f\u9023\u643a\u3057\u305f\u30a2\u30ab\u30a6\u30f3\u30c8\u306b\u7d10\u4ed8\u3044\u3066\u3044\u308bAnalytics\u30d3\u30e5\u30fc\u306e\u4e00\u89a7\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u306e\u3067\u3001dplyr\u306efilter\u95a2\u6570\u3092\u7528\u3044\u3066\u76ee\u7684\u306e\u30d3\u30e5\u30fc\u3092\u53d6\u308a\u51fa\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30b0\u30e9\u30d5\u306f\u30012017\/01\/01\u301c2017\/03\/31\u307e\u3067\u306e\u671f\u9593\u3067\u65e5\u5225\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u6570\u3068PV\u6570\u3092\u63cf\u753b\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u5b9f\u884c\u3059\u308b\u3068\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30b0\u30e9\u30d5\u304c\u63cf\u753b\u3055\u308c\u307e\u3059\u3002<br \/>\nget_ga\u95a2\u6570\u306b\u6e21\u3059\u5f15\u6570\u306fAnalytics API\u3067\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u3068\u540c\u3058\u3067\u3059\u306e\u3067\u3001<br \/>\nAnalytics API\u3092\u4f7f\u7528\u3055\u308c\u305f\u3053\u3068\u304c\u3042\u308b\u65b9\u306f\u7c21\u5358\u306b\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2017\/04\/Rplot.png\"><img loading=\"lazy\" src=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2017\/04\/Rplot.png\" alt=\"\" width=\"614\" height=\"406\" class=\"alignnone size-full wp-image-9700\" \/><\/a><\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\u307e\u3068\u3081<\/h3>\n<\/div>\n<p>\u4eca\u56de\u306fGoogle Analytics\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u7c21\u5358\u306a\u30b0\u30e9\u30d5\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\nknitr\u306a\u3069\u306e\u30d5\u30a1\u30a4\u30eb\u4fdd\u5b58\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u3001\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092\u7528\u3044\u3066PDF\u306a\u3069\u306b\u30ec\u30dd\u30fc\u30c6\u30a3\u30f3\u30b0\u3059\u308b\u3053\u3068\u3082\u51fa\u6765\u307e\u3059\u3002<br \/>\nGoogle Analytics\u306f\u3088\u304f\u4f7f\u7528\u3055\u308c\u308b\u65b9\u304c\u591a\u3044\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001R\u3092\u4f7f\u3063\u3066\u9031\u6b21\u3084\u6708\u6b21\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u7c21\u5358\u306b\u30ec\u30dd\u30fc\u30c6\u30a3\u30f3\u30b0\u51fa\u6765\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u3066\u306f\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u30d7\u30ed\u30c0\u30af\u30c8\u958b\u767a\u30c1\u30fc\u30e0\u306e\u7267\u3067\u3059\u3002 R\u8a00\u8a9e\u57fa\u790e\u5165\u9580\u3001R\u8a00\u8a9e\u30b0\u30e9\u30d5\u5165\u9580\u3068R\u8a00\u8a9e\u306e\u5165\u9580\u8a18\u4e8b\u3092\u66f8\u3044\u3066\u304d\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306f\u3088\u3046\u3084\u304f\u5b9f\u8df5\u7de8\u3068\u3044\u3046\u3053\u3068\u3067Google Analytics\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057R\u8a00\u8a9e\u3067\u89e3\u6790\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":9705,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[52,47],"tags":[],"acf":false,"_links":{"self":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/9380"}],"collection":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/comments?post=9380"}],"version-history":[{"count":12,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/9380\/revisions"}],"predecessor-version":[{"id":9706,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/9380\/revisions\/9706"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/media\/9705"}],"wp:attachment":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/media?parent=9380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/categories?post=9380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/tags?post=9380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}