{"id":2818,"date":"2017-04-12T11:00:35","date_gmt":"2017-04-12T02:00:35","guid":{"rendered":"https:\/\/www.sria.co.jp\/blog\/?p=2818"},"modified":"2017-05-25T17:59:11","modified_gmt":"2017-05-25T08:59:11","slug":"ranking-by-analytics","status":"publish","type":"post","link":"https:\/\/www.sria.co.jp\/blog\/2017\/04\/ranking-by-analytics\/","title":{"rendered":"Google\u30a2\u30ca\u30ea\u30c6\u30a3\u30af\u30b9\u304b\u3089\u30a2\u30af\u30bb\u30b9\u6570\u306e\u591a\u3044\u8a18\u4e8b\u3092\u53d6\u5f97\u3059\u308bWordPress\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u4f5c\u3063\u3066\u307f\u305f"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3002<br \/>\n\u8a18\u4e8b\u306e\u4e2d\u306b\u6d41\u884c\u308a\u306e\u30cd\u30bf(\u3059\u3054\u30fc\u3044\uff01\u3068\u304b)\u3092\u5165\u308c\u3066\u307f\u3088\u3046\u3068\u601d\u3063\u305f\u3051\u3069\u3001\u7121\u7406\u77e2\u7406\u611f\u304c\u51c4\u3044\u306e\u3067\u8ae6\u3081\u3066\u3057\u307e\u3063\u305f\u6728\u6751\u3067\u3059\u3002<\/p>\n<p>\u3055\u3066\u3001\u304a\u6c17\u3065\u304d\u306e\u65b9\u3082\u3044\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u304c\u30014\u67081\u65e5\u306b\u30db\u30fc\u30e0\u30da\u30fc\u30b8\u3068\u30d6\u30ed\u30b0\u304c\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u3057\u307e\u3057\u305f\uff01(\u3071\u3061\u3071\u3061)<br \/>\n\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u306b\u304a\u3051\u308b\u3053\u3060\u308f\u308a\u306f\u4ed6\u306e\u30e1\u30f3\u30d0\u30fc\u306b\u8ffd\u3005\u8a9e\u3063\u3066\u9802\u304f\u3068\u3057\u3066&#8230;\u4eca\u56de\u306f\u3001\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u5408\u308f\u305b\u3066\u300c\u30d6\u30ed\u30b0\u30c8\u30c3\u30d7\u306b\u3042\u308bPopular Posts(\u3044\u308f\u3086\u308b\u4eba\u6c17\u306e\u8a18\u4e8b)\u3092Google\u30a2\u30ca\u30ea\u30c6\u30a3\u30af\u30b9\u306e\u30c7\u30fc\u30bf\u3092\u5143\u306b\u53d6\u5f97\u3059\u308b\u300d\u3068\u3044\u3046\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u306e\u3067\u3001\u5fc5\u8981\u306a\u6e96\u5099\u3084\u5b9f\u88c5\u624b\u9806\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u524d\u63d0\u6761\u4ef6<\/h2>\n<ul>\n<li>PHP 7.0<\/li>\n<li>WordPress 4.7.3<\/li>\n<\/ul>\n<h2>\u4f55\u6545\u30a2\u30ca\u30ea\u30c6\u30a3\u30af\u30b9\u304b\u3089\u306e\u53d6\u5f97\u3092\u884c\u3046\u306e\u304b<\/h2>\n<p>\u3054\u5b58\u3058\u306e\u65b9\u3082\u591a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001WordPress\u306b\u306f\u30a2\u30af\u30bb\u30b9\u6570\u304b\u3089\u4eba\u6c17\u306e\u8a18\u4e8b\u3092\u8a08\u7b97\u3057\u3066\u3088\u3057\u306a\u306b\u3057\u3066\u304f\u308c\u308b\u30d7\u30e9\u30b0\u30a4\u30f3\u304c\u591a\u6570\u5b58\u5728\u3057\u307e\u3059\u3002(\u4ee3\u8868\u7684\u306a\u306e\u306f<a href=\"https:\/\/ja.wordpress.org\/plugins\/wordpress-popular-posts\/\">WordPress Popular Posts<\/a>\u3068\u304b\u3067\u3059\u304b\u306d)<br \/>\n\u305f\u3060\u3001\u3053\u308c\u3060\u3068\u30a6\u30a3\u30b8\u30a7\u30c3\u30c8\u306b\u8ffd\u52a0\u3055\u308c\u308b\u3068\u3044\u3046\u6271\u3044\u306a\u306e\u3067&#8230;<\/p>\n<p><a href=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/3981506f6265aa157b0f6fa101c040f3.png\"><img loading=\"lazy\" class=\"alignnone wp-image-2843 size-large\" src=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/3981506f6265aa157b0f6fa101c040f3-1024x331.png\" alt=\"\" width=\"1024\" height=\"331\" srcset=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/3981506f6265aa157b0f6fa101c040f3-1024x331.png 1024w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/3981506f6265aa157b0f6fa101c040f3-300x97.png 300w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/3981506f6265aa157b0f6fa101c040f3-768x249.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>\u4eca\u56de\u306e\u3088\u3046\u306b\u3001\u30d8\u30c3\u30c0\u30fc\u90e8\u306b\u8868\u793a\u3057\u305f\u3044\u3068\u3044\u3046\u5834\u5408\u306b\u306f\u4e0d\u5411\u304d\u3067\u3057\u305f\u3002<br \/>\n\u4ed6\u306b\u3082\u63a2\u3057\u3066\u307f\u305f\u306e\u3067\u3059\u304c\u3053\u308c\u3068\u3044\u3063\u3066\u898b\u3064\u304b\u3089\u305a\u3001\u300c\u3069\u3046\u8003\u3048\u3066\u3082\u4f5c\u3063\u305f\u65b9\u304c\u65e9\u3044\u300d\u3068\u3044\u3046\u7d50\u8ad6\u306b\u81f3\u3063\u305f\u306e\u3067\u30b5\u30af\u30c3\u3068\u4f5c\u3063\u3066\u307f\u308b\u4e8b\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<h2>\u6e96\u5099<\/h2>\n<p>\u305d\u3046\u3068\u6c7a\u307e\u308c\u3070\u3001\u307e\u305a\u306fGoogle\u30a2\u30ca\u30ea\u30c6\u30a3\u30af\u30b9\u304b\u3089\u53d6\u5f97\u3059\u308b\u624b\u6bb5\u3092\u63a2\u3059\u6240\u304b\u3089\u3067\u3059\u3002\u3053\u308c\u306b\u3064\u3044\u3066\u306f<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/reporting\/core\/v4\/?hl=ja\">Reporting API v4<\/a>\u304c\u552f\u4e00\u7121\u4e8c\u306e\u9078\u629e\u80a2\u3067\u3057\u305f\u3002<br \/>\n\u4ed6\u306eGoogle APIs\u3068\u540c\u3058\u3088\u3046\u306bPHP\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u306e\u304c\u3046\u308c\u3057\u3044\u3067\u3059\u306d\u3002<\/p>\n<h3>API\u306e\u6709\u52b9\u5316<\/h3>\n<p>\u307e\u305a\u6700\u521d\u306b\u3001Reporting API\u306e\u6709\u52b9\u5316\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/console.developers.google.com\/?hl=JA\">API Manager<\/a>\u3092\u958b\u3044\u3066\u3001\u300c\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u300d\u306e\u300cAPI\u3092\u6709\u52b9\u306b\u3059\u308b\u300d\u3092\u9078\u629e\u3057\u3066\u3001\u300cGoogle Analytics Reporting API\u300d\u3092\u6709\u52b9\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/0bfff1eec05daf244add3bdd09d88d8c.png\"><img loading=\"lazy\" class=\"alignnone size-large wp-image-2846\" src=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/0bfff1eec05daf244add3bdd09d88d8c-1024x246.png\" alt=\"\" width=\"1024\" height=\"246\" srcset=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/0bfff1eec05daf244add3bdd09d88d8c-1024x246.png 1024w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/0bfff1eec05daf244add3bdd09d88d8c-300x72.png 300w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/0bfff1eec05daf244add3bdd09d88d8c-768x184.png 768w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/0bfff1eec05daf244add3bdd09d88d8c.png 1184w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>\u753b\u50cf\u306f\u6709\u52b9\u306b\u306a\u3063\u305f\u72b6\u614b\u306e\u3082\u306e\u3067\u3059\u3002\u3061\u306a\u307f\u306b\u3001\u300cAnalytics API\u300d\u3068\u3044\u3046\u306e\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u3053\u308c\u3067\u306f\u306a\u3044\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<br \/>\n\u307e\u305f\u3001API Manager\u3092\u958b\u3044\u305f\u30bf\u30a4\u30df\u30f3\u30b0\u306a\u3069\u3067\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210\u3092\u6307\u793a\u3055\u308c\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u753b\u9762\u306e\u6307\u793a\u306b\u5f93\u3048\u3070OK\u3067\u3059\u3002<\/p>\n<p>\u7d9a\u3051\u3066\u3001\u8a8d\u8a3c\u60c5\u5831\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u30b5\u30a4\u30c9\u30d0\u30fc\u304b\u3089\u300c\u8a8d\u8a3c\u60c5\u5831\u300d\u3092\u9078\u629e\u3057\u3066\u3001\u300c\u8a8d\u8a3c\u60c5\u5831\u3092\u4f5c\u6210\u300d\u304b\u3089\u300c\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u30ad\u30fc\u300d\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/93d3d4d45983953cf56d2f7cf222a6c1.png\"><img loading=\"lazy\" class=\"alignnone size-large wp-image-2849\" src=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/93d3d4d45983953cf56d2f7cf222a6c1-1024x698.png\" alt=\"\" width=\"1024\" height=\"698\" srcset=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/93d3d4d45983953cf56d2f7cf222a6c1-1024x698.png 1024w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/93d3d4d45983953cf56d2f7cf222a6c1-300x204.png 300w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/93d3d4d45983953cf56d2f7cf222a6c1-768x523.png 768w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/93d3d4d45983953cf56d2f7cf222a6c1.png 1098w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>\u3059\u308b\u3068\u3001\u3053\u3093\u306a\u753b\u9762\u306b\u63a8\u79fb\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/75fbad709fe6211691d5eb55017a783d.png\"><img loading=\"lazy\" class=\"alignnone size-large wp-image-2850\" src=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/75fbad709fe6211691d5eb55017a783d-1024x645.png\" alt=\"\" width=\"1024\" height=\"645\" srcset=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/75fbad709fe6211691d5eb55017a783d-1024x645.png 1024w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/75fbad709fe6211691d5eb55017a783d-300x189.png 300w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/75fbad709fe6211691d5eb55017a783d-768x483.png 768w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/75fbad709fe6211691d5eb55017a783d.png 1112w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u306f\u300c\u65b0\u3057\u3044\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u300d\u3092\u9078\u629e\u3057\u307e\u3059\u3002<br \/>\n\u3059\u308b\u3068\u3001\u5165\u529b\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u5897\u3048\u308b\u306e\u3067\u3001\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u540d\u3068\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8ID\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/8ef9cfcf890f412b7e4ed11d49726535.png\"><img loading=\"lazy\" class=\"alignnone size-large wp-image-2851\" src=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/8ef9cfcf890f412b7e4ed11d49726535-1024x784.png\" alt=\"\" width=\"1024\" height=\"784\" srcset=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/8ef9cfcf890f412b7e4ed11d49726535-1024x784.png 1024w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/8ef9cfcf890f412b7e4ed11d49726535-300x230.png 300w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/8ef9cfcf890f412b7e4ed11d49726535-768x588.png 768w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/8ef9cfcf890f412b7e4ed11d49726535.png 1230w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u540d\u3068\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8ID\u306f\u4efb\u610f\u306e\u3082\u306e\u3067\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u300c\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8ID@\u30d7\u30ed\u30b8\u30a7\u30af\u30c8ID.iam.gserviceaccount.com\u300d\u3068\u3044\u3046\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9(\u306e\u3088\u3046\u306a\u6587\u5b57\u5217)\u306f\u5f8c\u307b\u3069\u5229\u7528\u3059\u308b\u306e\u3067\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>\u30ad\u30fc\u306e\u30bf\u30a4\u30d7\u306fJSON\u306e\u307e\u307e\u3067OK\u3067\u3059\u3002<br \/>\n\u5168\u3066\u5165\u529b\u3057\u3066\u300c\u4f5c\u6210\u300d\u3092\u9078\u629e\u3059\u308b\u3068\u3001\u8a8d\u8a3c\u60c5\u5831\u306e\u5165\u3063\u305fJSON\u304c\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u308c\u308b\u306e\u3067\u3001\u4fdd\u7ba1\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>\u3082\u3057\u5148\u307b\u3069\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u30e1\u30e2\u3057\u5fd8\u308c\u305f\u5834\u5408\u306f\u3001\u300c\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u7ba1\u7406\u300d\u304b\u3089\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<br \/>\n\u3057\u304b\u3057\u3001\u8a8d\u8a3c\u60c5\u5831\u306e\u5165\u3063\u305fJSON\u306f\u518d\u767a\u884c\u304c\u3067\u304d\u306a\u3044\u305f\u3081\u3001\u3082\u3057\u7121\u304f\u3057\u305f\u5834\u5408\u306f\u518d\u5ea6\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u30ad\u30fc\u306e\u4f5c\u6210\u3092\u518d\u5ea6\u884c\u3046\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<h3>\u30a2\u30ca\u30ea\u30c6\u30a3\u30af\u30b9\u306e\u8a2d\u5b9a<\/h3>\n<p>\u30a2\u30ca\u30ea\u30c6\u30a3\u30af\u30b9\u5074\u306b\u3082\u8a2d\u5b9a\u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3001\u5fd8\u308c\u305a\u306b\u884c\u3063\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\n\u3068\u3044\u3063\u3066\u3082\u96e3\u3057\u3044\u3082\u306e\u3067\u306f\u306a\u304f\u3001\u53c2\u7167\u3057\u305f\u3044\u30c7\u30fc\u30bf\u306e\u30d3\u30e5\u30fc(\u307e\u305f\u306f\u3001\u305d\u308c\u304c\u5c5e\u3059\u308b\u30a2\u30ab\u30a6\u30f3\u30c8\u3084\u30d7\u30ed\u30d1\u30c6\u30a3)\u306e\u300c\u30e6\u30fc\u30b6\u30fc\u7ba1\u7406\u300d\u304b\u3089\u3001\u30e1\u30e2\u3057\u305f\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306b\u5bfe\u3057\u3066\u6a29\u9650\u3092\u4ed8\u4e0e\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/5884a801fd3e66d16f86275a54b0f493.png\"><img loading=\"lazy\" class=\"alignnone size-large wp-image-2854\" src=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/5884a801fd3e66d16f86275a54b0f493-1024x913.png\" alt=\"\" width=\"1024\" height=\"913\" srcset=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/5884a801fd3e66d16f86275a54b0f493-1024x913.png 1024w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/5884a801fd3e66d16f86275a54b0f493-300x268.png 300w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/5884a801fd3e66d16f86275a54b0f493-768x685.png 768w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2017\/04\/5884a801fd3e66d16f86275a54b0f493.png 1538w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>\u6a29\u9650\u306f\u300c\u8868\u793a\u3068\u5206\u6790\u300d\u3067\u5927\u4e08\u592b\u3067\u3059\u3002<\/p>\n<h2>\u53d6\u5f97\uff06\u69cb\u7bc9\u6761\u4ef6<\/h2>\n<p>\u3067\u306f\u6e96\u5099\u3082\u6574\u3063\u305f\u306e\u3067\u5b9f\u88c5\u306b&#8230;\u306e\u524d\u306b\u3001\u53d6\u5f97\u6761\u4ef6\u3084\u5b9f\u88c5\u306b\u304a\u3051\u308b\u65b9\u91dd\u3092\u6c7a\u3081\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u30b7\u30f3\u30d7\u30eb\u306b\u3001\u300c\u5168\u671f\u9593\u3067\u30e6\u30cb\u30fc\u30afPV\u6570\u306e\u591a\u3044\u9806\u300d\u300c4\u4ef6\u300d\u3068\u3044\u3046\u65b9\u91dd\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u307e\u305f\u3001\u30c6\u30fc\u30de\u4e0a\u3067\u306f\u300c\u8a18\u4e8b\u30bf\u30a4\u30c8\u30eb\u300d\u300c\u30ea\u30f3\u30af\u5148URL\u300d\u300c\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1\u753b\u50cf\u300d\u3092\u5229\u7528\u3059\u308b\u306e\u3067\u3001\u95a2\u6570\u304b\u3089\u306f\u3053\u306e\u3042\u305f\u308a\u306e\u60c5\u5831\u3092\u8fd4\u3059\u305d\u3046\u306a\u4e2d\u8eab\u3092\u69cb\u7bc9\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u30a2\u30af\u30bb\u30b9\u6bce\u306bAPI\u3078\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u884c\u3063\u3066\u3057\u307e\u3046\u3068\u4e0a\u9650\u306b\u9054\u3057\u3066\u3057\u307e\u3046\u53ef\u80fd\u6027\u3082\u5341\u5206\u306b\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u4fdd\u5b58\u3057\u3001\u6700\u5f8c\u306e\u53d6\u5f97\u304b\u30891\u6642\u9593\u4ee5\u4e0a\u7d4c\u904e\u3057\u3066\u3044\u308b\u5834\u5408\u306b\u6700\u5f8c\u53d6\u5f97\u51e6\u7406\u3092\u884c\u3046\u3088\u3046\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<h2>\u69cb\u7bc9<\/h2>\n<p>\u3044\u3088\u3044\u3088\u672c\u5f53\u306b\u5b9f\u88c5\u306b\u5165\u308a\u307e\u3059&#8230;\u304c\u3001\u305d\u306e\u524d\u306b<a href=\"https:\/\/github.com\/google\/google-api-php-client\">API\u30e9\u30a4\u30d6\u30e9\u30ea<\/a>\u3092\u5165\u308c\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002<br \/>\n\u4eca\u56de\u306fComposer\u7d4c\u7531\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u306e\u3067\u3001\u4f5c\u696d\u7528\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4e0a\u3067\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">$ composer require google\/apiclient:^2.0<\/pre>\n<p>\u3082\u3057\u624b\u52d5\u3067\u5165\u308c\u308b\u5834\u5408\u306f\u3001\u4e0a\u8a18\u30da\u30fc\u30b8\u3092\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u307e\u305f\u3001\u5148\u307b\u3069\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305fJSON\u3082\u8a2d\u7f6e\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306fauth\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u3066\u3001\u305d\u306e\u4e2d\u306b\u8a2d\u7f6e\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u30d7\u30e9\u30b0\u30a4\u30f3\u672c\u4f53\u306ffunctions.php\u306e\u4e2d\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u307e\u3067\u306e\u69cb\u9020\u3092\u56f3\u306b\u3059\u308b\u3068\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">.\r\n\u251c\u2500\u2500 auth\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 \u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305fJSON.json\r\n\u251c\u2500\u2500 composer.json\r\n\u251c\u2500\u2500 composer.lock\r\n\u251c\u2500\u2500 functions.php\r\n\u2514\u2500\u2500 vendor\r\n    \u251c\u2500\u2500 autoload.php\r\n    \u2514\u2500\u2500 \u30e9\u30a4\u30d6\u30e9\u30ea\u8272\u3005<\/pre>\n<p>(\u3061\u306a\u307f\u306b\u3001\u3053\u3046\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u9020\u3092\u30c6\u30ad\u30b9\u30c8\u3067\u4f5c\u308a\u305f\u3044\u6642\u306ftree\u30b3\u30de\u30f3\u30c9\u304c\u4fbf\u5229\u3067\u3059\u3002Homebrew\u304b\u3089\u5165\u308c\u307e\u3057\u305f)<\/p>\n<p>\u305d\u306efunctions.php\u306e\u4e2d\u8eab\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;?php\r\n\/*\r\nPlugin Name: PopularPosts\r\nDescription: GoogleAnalytics\u304b\u3089\u4eba\u6c17\u306e\u6295\u7a3f\u3092\u53d6\u5f97\u3059\u308b\u30d7\u30e9\u30b0\u30a4\u30f3\r\nVersion: 1.0\r\nAuthor: SRIA\r\nAuthor URI: https:\/\/www.sria.co.jp\/\r\n*\/\r\n\r\n\/\/ composer\u8aad\u307f\u8fbc\u307f\r\nrequire_once __DIR__ . '\/vendor\/autoload.php';\r\n\r\n\/\/ \u8a3c\u660e\u66f8\u30c7\u30fc\u30bf\r\ndefine('KEY_LOCATION', __DIR__ . '\/auth\/\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305fJSON.json');\r\n\/\/ \u53d6\u5f97\u3059\u308b\u30d3\u30e5\u30fcID\r\ndefine('VIEW_ID', YOUR_VIEW_ID);\r\n\/\/ \u53d6\u5f97\u3059\u308b\u6295\u7a3f\u6570\r\ndefine('GET_COUNT', 4);\r\n\/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u6642\u9593(\u79d2)\r\ndefine('CACHE_TIME', 3600);\r\n\r\n\/\/ \u30c6\u30fc\u30de\u304b\u3089\u4f7f\u7528\u3059\u308b\u95a2\u6570\r\nfunction pp_get_popularposts()\r\n{\r\n    $ret = [];\r\n\r\n    \/\/ \u6700\u7d42\u53d6\u5f97\u6642\u9593\u3092\u53d6\u5f97\r\n    $updateTime = get_option('pp_update_time');\r\n\r\n    \/\/ \u30c7\u30fc\u30bf\u304c\u7121\u3044\u304b\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u6642\u9593\u3092\u7d4c\u904e\u3057\u3066\u3044\u305f\u3089\u53d6\u5f97\r\n    \/\/ \u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u53d6\u5f97\r\n    if (!$updateTime || $updateTime + CACHE_TIME &lt;= time()) {\r\n        \/\/ \u30af\u30e9\u30b9\u306e\u521d\u671f\u5316\u3068API\u521d\u671f\u5316\r\n        $client = new Google_Client();\r\n        $client-&gt;setApplicationName('Analytics Reporting');\r\n        $client-&gt;setAuthConfig(KEY_LOCATION);\r\n        $client-&gt;setScopes(['https:\/\/www.googleapis.com\/auth\/analytics.readonly']);\r\n        $analytics = new Google_Service_AnalyticsReporting($client);\r\n\r\n        \/\/ \u65e5\u4ed8\u306e\u7bc4\u56f2\u6307\u5b9a\r\n        $dateRange = new Google_Service_AnalyticsReporting_DateRange();\r\n        $dateRange-&gt;setStartDate('2011-01-01');\r\n        $dateRange-&gt;setEndDate('today');\r\n\r\n        \/\/ \u30e1\u30c8\u30ea\u30af\u30b9\u6307\u5b9a\r\n        $metrics = [];\r\n        $configureMetrics = ['ga:uniquePageviews'];\r\n        foreach ($configureMetrics as $metric) {\r\n            $rMetric = new Google_Service_AnalyticsReporting_Metric();\r\n            $rMetric-&gt;setExpression($metric);\r\n\r\n            $metrics[] = $rMetric;\r\n        }\r\n\r\n        \/\/ \u30c7\u30a3\u30e1\u30f3\u30b7\u30e7\u30f3\u6307\u5b9a\r\n        $dimension = new Google_Service_AnalyticsReporting_Dimension();\r\n        $dimension-&gt;setName('ga:pagePath');\r\n\r\n        \/\/ \u30bd\u30fc\u30c8\u9806\u306e\u8a2d\u5b9a\r\n        $orderBy = new Google_Service_AnalyticsReporting_OrderBy();\r\n        $orderBy-&gt;setFieldName('ga:uniquePageviews');\r\n        $orderBy-&gt;setSortOrder('DESCENDING');\r\n\r\n        \/\/ \u30ea\u30af\u30a8\u30b9\u30c8\u69cb\u7bc9\r\n        $request = new Google_Service_AnalyticsReporting_ReportRequest();\r\n        $request-&gt;setViewId(VIEW_ID);\r\n        $request-&gt;setDateRanges($dateRange);\r\n        $request-&gt;setMetrics($metrics);\r\n        $request-&gt;setDimensions($dimension);\r\n        $request-&gt;setOrderBys($orderBy);\r\n        $request-&gt;setPageSize(GET_COUNT);\r\n\r\n        \/\/ GA\u306b\u554f\u3044\u5408\u308f\u305b\r\n        $body = new Google_Service_AnalyticsReporting_GetReportsRequest();\r\n        $body-&gt;setReportRequests([$request]);\r\n\r\n        $result = $analytics-&gt;reports-&gt;batchGet($body);\r\n\r\n        \/\/ \u30c7\u30fc\u30bf\u53d6\u5f97\r\n        \/\/ getReports()\u306e\u7d50\u679c\u914d\u5217\u306f1\u3064\u3057\u304b\u306a\u3044\u306e\u3067[0]\u3092\u6307\u5b9a\r\n        $report = $result-&gt;getReports()[0]-&gt;getData()-&gt;getRows();\r\n\r\n        \/\/ \u52a0\u5de5\r\n        foreach ($report as $r) {\r\n            \/\/ \u30c7\u30a3\u30e1\u30f3\u30b7\u30e7\u30f3\u3092\u3068\u3063\u3066\u304f\u308b\r\n            \/\/ 1\u3064\u3057\u304b\u306a\u3044\u306e\u3067[0]\u56fa\u5b9a\u3067\u6307\u5b9a\r\n            $uri = $r-&gt;getDimensions()[0];\r\n\r\n            \/\/ URL\u3092\u5206\u89e3\u3057\u3066\u30015\u756a\u76ee\u306e\u8981\u7d20(\u6295\u7a3f\u540d)\u304b\u3089\u6295\u7a3f\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\r\n            $params = explode('\/', $uri);\r\n            $posts = get_page_by_path($params[4], 'OBJECT', 'post');\r\n\r\n            \/\/ \u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092\u5c55\u958b\u3001\u53ca\u3073\u305d\u308c\u3092\u5229\u7528\u3057\u3066\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1\u3084\u30d1\u30fc\u30de\u30ea\u30f3\u30af\u3092\u518d\u53d6\u5f97\r\n            \/\/ \u305d\u308c\u3089\u3092\u7d50\u679c\u5909\u6570\u3078\u8a2d\u7f6e\r\n            $ret[] = [\r\n                'title' =&gt; $posts-&gt;post_title,\r\n                'post_thumbnail' =&gt; get_the_post_thumbnail_url($posts-&gt;ID),\r\n                'permalink' =&gt; get_permalink($posts-&gt;ID)\r\n            ];\r\n        }\r\n\r\n        \/\/ \u6700\u7d42\u53d6\u5f97\u6642\u9593\u3068\u30ad\u30e3\u30c3\u30b7\u30e5\u30c7\u30fc\u30bf\u3092\u66f4\u65b0\r\n        update_option('pp_posts_data', $ret);\r\n        update_option('pp_update_time', time());\r\n    } else {\r\n        \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u53d6\u5f97\r\n        $ret = get_option('pp_posts_data');\r\n    }\r\n\r\n    return $ret;\r\n}<\/pre>\n<p>\u3042\u3068\u306f\u30b3\u30d4\u30da\u3057\u3066\u9802\u3044\u3066\u7d42\u308f\u308a\u3067\u3082\u826f\u3044\u306e\u3067\u3059\u304c\u3001\u305b\u3063\u304b\u304f\u3067\u3059\u306e\u3067\u4e0a\u304b\u3089\u89e3\u8aac\u3092\u5165\u308c\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\/*\r\nPlugin Name: PopularPosts\r\nDescription: GoogleAnalytics\u304b\u3089\u4eba\u6c17\u306e\u6295\u7a3f\u3092\u53d6\u5f97\u3059\u308b\u30d7\u30e9\u30b0\u30a4\u30f3\r\nVersion: 1.0\r\nAuthor: SRIA\r\nAuthor URI: https:\/\/www.sria.co.jp\/\r\n*\/<\/pre>\n<p>\u3053\u3053\u306f\u3001WordPress\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u3067\u3042\u308b\u4e8b\u3092\u793a\u3057\u3066\u3044\u308b\u30b3\u30e1\u30f3\u30c8\u3067\u3059\u3002<br \/>\n\u8a73\u3057\u3044\u5185\u5bb9\u306f<a href=\"https:\/\/wpdocs.osdn.jp\/%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E3%81%AE%E4%BD%9C%E6%88%90\">Codex\u306b\u8f09\u3063\u3066\u3044\u307e\u3059<\/a>\u304c\u3001\u6700\u4f4e\u9650\u306fPlugin Name\u306e\u307f\u3067\u3082\u826f\u3044\u3088\u3046\u3067\u3059\u3002<br \/>\n\u305f\u3060\u3001\u305d\u308c\u3060\u3068\u30d7\u30e9\u30b0\u30a4\u30f3\u753b\u9762\u304c\u5bc2\u3057\u3044\u306e\u3067\u3001\u5bc2\u3057\u304f\u306a\u3089\u306a\u3044\u7a0b\u5ea6\u306e\u60c5\u5831\u3092\u5165\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\/\/ \u8a3c\u660e\u66f8\u30c7\u30fc\u30bf\r\ndefine('KEY_LOCATION', __DIR__ . '\/auth\/\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305fJSON.json');\r\n\/\/ \u53d6\u5f97\u3059\u308b\u30d3\u30e5\u30fcID\r\ndefine('VIEW_ID', YOUR_VIEW_ID);\r\n\/\/ \u53d6\u5f97\u3059\u308b\u6295\u7a3f\u6570\r\ndefine('GET_COUNT', 4);\r\n\/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u6642\u9593(\u79d2)\r\ndefine('CACHE_TIME', 3600);<\/pre>\n<p>\u3053\u306e\u8fba\u3067\u306f\u5b9a\u6570\u3092\u5229\u7528\u3057\u3066\u5404\u7a2e\u8a2d\u5b9a\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u5185\u5bb9\u306f\u30b3\u30e1\u30f3\u30c8\u306b\u3042\u308b\u901a\u308a\u3067\u3001CACHE_TIME\u304c\u79d2\u63db\u7b97\u306a\u306e\u3067\u305d\u3053\u3060\u3051\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<br \/>\n\u307e\u305f\u3001\u300cYOUR_VIEW_ID\u300d\u306e\u90e8\u5206\u306f\u53d6\u5f97\u3057\u305f\u3044\u30c7\u30fc\u30bf\u306e\u542b\u307e\u308c\u308b\u30d3\u30e5\u30fc\u306eID\u306b\u7f6e\u63db\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305d\u306e\u30d3\u30e5\u30fc\u306b\u5bfe\u3057\u3066\u3001\u4f5c\u6210\u3057\u305f\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u6a29\u9650\u304c\u4ed8\u4e0e\u3055\u308c\u3066\u3044\u308b\u4e8b\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\/\/ \u30c6\u30fc\u30de\u304b\u3089\u4f7f\u7528\u3059\u308b\u95a2\u6570\r\nfunction pp_get_popularposts()\r\n{<\/pre>\n<p>\u3044\u3088\u3044\u3088\u672c\u5b9f\u88c5\u306e\u90e8\u5206\u306b\u5165\u308a\u307e\u3059\u3002\u3053\u306e\u95a2\u6570\u3092\u30c6\u30fc\u30de\u304b\u3089\u547c\u3073\u51fa\u3059\u3053\u3068\u3067\u3001\u53d6\u5f97\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">    \/\/ \u6700\u7d42\u53d6\u5f97\u6642\u9593\u3092\u53d6\u5f97\r\n    $updateTime = get_option('pp_update_time');\r\n\r\n    \/\/ \u30c7\u30fc\u30bf\u304c\u7121\u3044\u304b\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u6642\u9593\u3092\u7d4c\u904e\u3057\u3066\u3044\u305f\u3089\u53d6\u5f97\r\n    \/\/ \u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u53d6\u5f97\r\n    if (!$updateTime || $updateTime + CACHE_TIME &lt;= time()) {<\/pre>\n<p>\u307e\u305a\u306f\u3001get_option()\u3092\u5229\u7528\u3057\u3066\u3001&#8221;pp_update_time&#8221;\u3068\u3044\u3046\u5024\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002\u3053\u306e\u8a2d\u5b9a\u306b\u306f\u3001\u300c\u6700\u5f8c\u306b\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u305f\u6642\u523b(unixtime)\u300d\u304c\u5165\u3063\u3066\u3044\u308b\u60f3\u5b9a\u3067\u3059\u3002<br \/>\n\u76f4\u5f8c\u306eif\u6587\u3067\u3001\u300c\u305d\u3082\u305d\u3082\u8a2d\u5b9a\u304c\u5165\u3063\u3066\u306a\u3044 or \u898f\u5b9a\u79d2\u6570\u3092\u8d85\u3048\u3066\u3044\u308b\u300d\u3068\u3044\u3046\u5834\u5408\u306b\u30a2\u30ca\u30ea\u30c6\u30a3\u30af\u30b9\u304b\u3089\u306e\u53d6\u5f97\u51e6\u7406\u3092\u884c\u3046\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">        \/\/ \u30af\u30e9\u30b9\u306e\u521d\u671f\u5316\u3068API\u521d\u671f\u5316\r\n        $client = new Google_Client();\r\n        $client-&gt;setApplicationName('Analytics Reporting');\r\n        $client-&gt;setAuthConfig(KEY_LOCATION);\r\n        $client-&gt;setScopes(['https:\/\/www.googleapis.com\/auth\/analytics.readonly']);\r\n        $analytics = new Google_Service_AnalyticsReporting($client);<\/pre>\n<p>\u5148\u307b\u3069\u306eif\u6587\u3092\u901a\u904e\u3057\u305f\u5834\u5408\u306e\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\n\u307e\u305a\u306fAPI\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u521d\u671f\u5316\u51e6\u7406\u3092\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u3053\u3053\u3067\u30b9\u30b3\u30fc\u30d7\u3084\u53d6\u5f97\u3057\u305f\u6a29\u9650\u60c5\u5831\u306e\u30d1\u30b9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<br \/>\nsetApplicationName()\u306f\u4efb\u610f\u306e\u540d\u524d\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">        \/\/ \u65e5\u4ed8\u306e\u7bc4\u56f2\u6307\u5b9a\r\n        $dateRange = new Google_Service_AnalyticsReporting_DateRange();\r\n        $dateRange-&gt;setStartDate('2011-01-01');\r\n        $dateRange-&gt;setEndDate('today');<\/pre>\n<p>\u6b21\u306b\u30ec\u30dd\u30fc\u30c8\u53d6\u5f97\u306b\u5fc5\u8981\u306a\u6761\u4ef6\u306e\u6307\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\n\u6700\u521d\u306bGoogle_Service_AnalyticsReporting_DateRange\u3092\u5229\u7528\u3057\u3066\u65e5\u4ed8\u306e\u7bc4\u56f2\u6307\u5b9a\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n\u8981\u4ef6\u306b\u5408\u308f\u305b\u3066\u3001setStartDate\u3068setEndDate\u3092\u7bc4\u56f2\u3067\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">        \/\/ \u30e1\u30c8\u30ea\u30af\u30b9\u6307\u5b9a\r\n        $metrics = [];\r\n        $configureMetrics = ['ga:uniquePageviews'];\r\n        foreach ($configureMetrics as $metric) {\r\n            $rMetric = new Google_Service_AnalyticsReporting_Metric();\r\n            $rMetric-&gt;setExpression($metric);\r\n\r\n            $metrics[] = $rMetric;\r\n        }<\/pre>\n<p>\u7d9a\u3051\u3066\u30e1\u30c8\u30ea\u30af\u30b9\u3067\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u30e6\u30cb\u30fc\u30afPV\u6570\u3092\u5229\u7528\u3059\u308b\u306e\u3067\u3001ga:uniquePageviews\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u8907\u6570\u6307\u5b9a\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u305d\u306e\u5206\u3060\u3051Google_Service_AnalyticsReporting_Metric\u3092\u5897\u3084\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u306f\u305d\u308c\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u305d\u306e\u307e\u307e\u4f7f\u3046\u5834\u5408\u306f$configureMetrics\u306e\u4e2d\u8eab\u3092\u5897\u3084\u305b\u3070\u8907\u6570\u306e\u30e1\u30c8\u30ea\u30af\u30b9\u306b\u5bfe\u5fdc\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">        \/\/ \u30c7\u30a3\u30e1\u30f3\u30b7\u30e7\u30f3\u6307\u5b9a\r\n        $dimension = new Google_Service_AnalyticsReporting_Dimension();\r\n        $dimension-&gt;setName('ga:pagePath');<\/pre>\n<p>\u305d\u3057\u3066\u30c7\u30a3\u30e1\u30f3\u30b7\u30e7\u30f3\u3002<br \/>\n\u5f8c\u306e\u51e6\u7406\u3067\u30d1\u30b9\u3092\u5229\u7528\u3059\u308b\u306e\u3067\u3001ga:pagePath\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u3082\u8907\u6570\u6307\u5b9a\u3057\u305f\u3044\u5834\u5408\u306fGoogle_Service_AnalyticsReporting_Dimension\u3092\u5897\u3084\u3057\u307e\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u30c7\u30a3\u30e1\u30f3\u30b7\u30e7\u30f3\u3068\u30e1\u30c8\u30ea\u30af\u30b9\u3092\u63a2\u3059\u306e\u306f\u300c<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/reporting\/core\/dimsmets\">Dimensions &amp; Metrics Explorer<\/a>\u300d\u304c\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">        \/\/ \u30bd\u30fc\u30c8\u9806\u306e\u8a2d\u5b9a\r\n        $orderBy = new Google_Service_AnalyticsReporting_OrderBy();\r\n        $orderBy-&gt;setFieldName('ga:uniquePageviews');\r\n        $orderBy-&gt;setSortOrder('DESCENDING');<\/pre>\n<p>\u6700\u5f8c\u306b\u30bd\u30fc\u30c8\u9806\u3067\u3059\u3002<br \/>\n\u30e6\u30cb\u30fc\u30afPV\u6570(ga:uniquePageviews)\u306e\u591a\u3044\u9806(DECENDING)\u306a\u306e\u3067\u3001\u3053\u3093\u306a\u611f\u3058\u306e\u6307\u5b9a\u3092\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u307e\u3067\u3067\u306f\u65e5\u4ed8\u30fb\u30e1\u30c8\u30ea\u30af\u30b9\u30fb\u30c7\u30a3\u30e1\u30f3\u30b7\u30e7\u30f3\u30fb\u30bd\u30fc\u30c8\u9806\u306e\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3057\u305f\u304c\u3001\u4ed6\u306b\u3082\u69d8\u3005\u306a\u6307\u5b9a\u304c\u53ef\u80fd\u3067\u3059\u3002(\u4f8b\u3048\u3070\u3001\u30c7\u30a3\u30e1\u30f3\u30b7\u30e7\u30f3\u306e\u7d5e\u308a\u8fbc\u307f(DimensionFilter)\u3068\u304b)<br \/>\n<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/reporting\/core\/v4\/rest\/v4\/reports\/batchGet\">\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u3092\u898b\u308b\u3068<\/a>\u8272\u3005\u8f09\u3063\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u7528\u9014\u306b\u5408\u308f\u305b\u3066\u63a2\u3057\u3066\u307f\u308b\u3068\u826f\u3044\u3067\u3057\u3087\u3046\u3002<br \/>\n\u9805\u76ee\u540d\u306b\u5408\u308f\u305b\u305f\u30af\u30e9\u30b9(Goole_Service_AnalyticsReporting_\u25cb\u25cb)\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">        \/\/ \u30ea\u30af\u30a8\u30b9\u30c8\u69cb\u7bc9\r\n        $request = new Google_Service_AnalyticsReporting_ReportRequest();\r\n        $request-&gt;setViewId(VIEW_ID);\r\n        $request-&gt;setDateRanges($dateRange);\r\n        $request-&gt;setMetrics($metrics);\r\n        $request-&gt;setDimensions($dimension);\r\n        $request-&gt;setOrderBys($orderBy);\r\n        $request-&gt;setPageSize(GET_COUNT);<\/pre>\n<p>\u3053\u3053\u307e\u3067\u4f5c\u6210\u3057\u305f\u6761\u4ef6\u3092\u5229\u7528\u3057\u3066\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n\u6700\u521d\u306b\u8a2d\u5b9a\u3057\u305f\u30d3\u30e5\u30fc\u306eID\u3084\u53d6\u5f97\u3059\u308b\u4ef6\u6570\u3092\u3053\u3053\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">        \/\/ GA\u306b\u554f\u3044\u5408\u308f\u305b\r\n        $body = new Google_Service_AnalyticsReporting_GetReportsRequest();\r\n        $body-&gt;setReportRequests([$request]);\r\n\r\n        $result = $analytics-&gt;reports-&gt;batchGet($body);\r\n\r\n        \/\/ \u30c7\u30fc\u30bf\u53d6\u5f97\r\n        \/\/ getReports()\u306e\u7d50\u679c\u914d\u5217\u306f1\u3064\u3057\u304b\u306a\u3044\u306e\u3067[0]\u3092\u6307\u5b9a\r\n        $report = $result-&gt;getReports()[0]-&gt;getData()-&gt;getRows();<\/pre>\n<p>\u305d\u3057\u3066\u3001\u30a2\u30ca\u30ea\u30c6\u30a3\u30af\u30b9\u3078\u306e\u554f\u3044\u5408\u308f\u305b\u3067\u3059\u3002<br \/>\n\u7d50\u679c\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u8fd4\u3063\u3066\u304d\u307e\u3059\u304c\u3001\u305f\u3060\u5358\u306b\u30d1\u30b9\u3092\u53d6\u308a\u51fa\u3057\u305f\u3044\u3051\u306a\u306e\u306b\u4e2d\u3005\u6df1\u3044\u968e\u5c64\u306b\u3042\u308b\u306e\u3067\u5927\u5909\u3067\u3059\u3002<br \/>\n\u4eca\u56de\u306e\u5834\u5408\u306fgetReports()\u306f\u914d\u5217\u304c1\u3064\u3057\u304b\u306a\u3044\u524d\u63d0\u306a\u306e\u3067[0]\u3092\u76f4\u306b\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u6761\u4ef6\u306b\u3088\u3063\u3066\u5909\u308f\u308b\u306e\u3067\u7f6e\u304d\u5909\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"lang:default decode:true\">        \/\/ \u52a0\u5de5\r\n        foreach ($report as $r) {\r\n            \/\/ \u30c7\u30a3\u30e1\u30f3\u30b7\u30e7\u30f3\u3092\u3068\u3063\u3066\u304f\u308b\r\n            \/\/ 1\u3064\u3057\u304b\u306a\u3044\u306e\u3067[0]\u56fa\u5b9a\u3067\u6307\u5b9a\r\n            $uri = $r-&gt;getDimensions()[0];\r\n\r\n            \/\/ URL\u3092\u5206\u89e3\u3057\u3066\u30015\u756a\u76ee\u306e\u8981\u7d20(\u6295\u7a3f\u540d)\u304b\u3089\u6295\u7a3f\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\r\n            $params = explode('\/', $uri);\r\n            $posts = get_page_by_path($params[4], 'OBJECT', 'post');\r\n\r\n            \/\/ \u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092\u5c55\u958b\u3001\u53ca\u3073\u305d\u308c\u3092\u5229\u7528\u3057\u3066\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1\u3084\u30d1\u30fc\u30de\u30ea\u30f3\u30af\u3092\u518d\u53d6\u5f97\r\n            \/\/ \u305d\u308c\u3089\u3092\u7d50\u679c\u5909\u6570\u3078\u8a2d\u7f6e\r\n            $ret[] = [\r\n                'title' =&gt; $posts-&gt;post_title,\r\n                'post_thumbnail' =&gt; get_the_post_thumbnail_url($posts-&gt;ID),\r\n                'permalink' =&gt; get_permalink($posts-&gt;ID)\r\n            ];\r\n        }<\/pre>\n<p>\u30c7\u30a3\u30e1\u30f3\u30b7\u30e7\u30f3\u306b\u30d1\u30b9\u306e\u307f\u53d6\u5f97\u3059\u308b\u3088\u3046\u6307\u5b9a\u3057\u307e\u3057\u305f\u306e\u3067\u3001\u30d1\u30b9\u3057\u304b\u53d6\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u307e\u3041\u5f53\u305f\u308a\u524d\u3067\u3059\u306d\u3002<br \/>\n\u3053\u308c\u3092\u5143\u306b\u30bf\u30a4\u30c8\u30eb\u3084\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1\u306eURL\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<p>\u9577\u3044\u306e\u3067\u7b87\u6761\u66f8\u304d\u306b\u3059\u308b\u3068\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n<ul>\n<li>getDimensons()\u3067\u30c7\u30a3\u30e1\u30f3\u30b7\u30e7\u30f3\u3092\u53d6\u5f97\n<ul>\n<li>\u30c7\u30a3\u30e1\u30f3\u30b7\u30e7\u30f3\u306f\u4eca\u56de1\u3064\u3057\u304b\u6307\u5b9a\u3057\u3066\u3044\u307e\u305b\u3093\u306e\u3067\u3001[0]\u3092\u76f4\u306b\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059<\/li>\n<\/ul>\n<\/li>\n<li>explode()\u3067\u300c\/\u300d\u3067\u5206\u89e3\n<ul>\n<li>\u300c\/blog\/\u5e74\/\u6708\/\u6295\u7a3f\u540d\u300d\u3068\u3044\u3046URL\u69cb\u9020\u306e\u305f\u3081\u3001\u3053\u308c\u3067\u6295\u7a3f\u540d\u3092\u53d6\u5f97\u3057\u307e\u3059<\/li>\n<\/ul>\n<\/li>\n<li>\u6295\u7a3f\u540d\u3092\u5229\u7528\u3057\u3066\u3001get_page_by_path()\u3067\u8a18\u4e8b\u30c7\u30fc\u30bf\u3092\u53d6\u5f97<\/li>\n<li>\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092\u5143\u306b\u3001\u30bf\u30a4\u30c8\u30eb\u3084\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1\u306a\u3069\u306e\u60c5\u5831\u3092\u53d6\u5f97\u3057\u3066\u914d\u5217\u306b\u5165\u308c\u308b<\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u51e6\u7406\u3092URL\u6bce\u306b\u884c\u3044\u307e\u3059\u3002<\/p>\n<p>\u30d1\u30fc\u30de\u30ea\u30f3\u30af\u306b\u6295\u7a3f\u8005\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u5834\u5408\u306f\u3053\u306e\u51e6\u7406\u3068\u306a\u308a\u307e\u3059\u304c\u3001\u3082\u3057\u57fa\u672c\u3084\u6570\u5b57\u30d9\u30fc\u30b9\u306e\u8a2d\u5b9a\u306b\u306a\u3063\u3066\u3044\u308b\u5834\u5408\u306fURL\u672b\u5c3e\u306e\u6570\u5b57\u304c\u8a18\u4e8bID\u306a\u306e\u3067\u3001\u305d\u306e\u6570\u5b57\u3092\u5229\u7528\u3057\u3066get_post()\u3067\u53d6\u5f97\u3059\u308b\u51e6\u7406\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">        \/\/ \u6700\u7d42\u53d6\u5f97\u6642\u9593\u3068\u30ad\u30e3\u30c3\u30b7\u30e5\u30c7\u30fc\u30bf\u3092\u66f4\u65b0\r\n        update_option('pp_posts_data', $ret);\r\n        update_option('pp_update_time', time());<\/pre>\n<p>\u6700\u5f8c\u306b\u3001\u53d6\u5f97\u3057\u305f\u6587\u5b57\u5217\u3068\u51e6\u7406\u6642\u9593\u3092\u3001\u305d\u308c\u305e\u308c&#8221;pp_posts_data&#8221;\u3068&#8221;pp_update_time&#8221;\u306bupdate_option()\u3067\u66f8\u304d\u8fbc\u307f\u307e\u3059\u3002<br \/>\n\u3053\u3053\u307e\u3067\u3067\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u5229\u7528\u3057\u306a\u3044\u5834\u5408\u306e\u51e6\u7406\u306f\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">    } else {\r\n        \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u53d6\u5f97\r\n        $ret = get_option('pp_posts_data');\r\n    }<\/pre>\n<p>\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u5229\u7528\u3059\u308b\u5834\u5408(\u6700\u521d\u306eif\u3067\u6761\u4ef6\u306b\u5408\u81f4\u3057\u306a\u304b\u3063\u305f\u5834\u5408)\u306f\u3001get_option()\u3067\u524d\u56de\u306e\u53d6\u5f97\u7d50\u679c\u3092\u53d6\u3063\u3066\u304d\u3066\u5909\u6570\u306b\u5165\u308c\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>\u6700\u5f8c\u306b\u3001\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092return\u3057\u3066\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<p>\u5f8c\u306f\u3001WordPress\u306e\/wp-content\/plugins\/\u4ee5\u4e0b\u3078\u5c55\u958b\u3057\u3001\u7ba1\u7406\u753b\u9762\u304b\u3089\u6709\u52b9\u306b\u3057\u3066\u30c6\u30fc\u30de\u304b\u3089\u53d6\u5f97\u3059\u308b\u51e6\u7406\u3092\u66f8\u304d\u8fbc\u307f\u307e\u3059\u3002<br \/>\n\u5b9f\u884c\u7d50\u679c\u306f\u914d\u5217\u3068\u306a\u308a\u307e\u3059\u306e\u3067\u3001foreach()\u3067\u56de\u3059\u3068\u3044\u3044\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u304a\u308f\u308a<\/h2>\n<p>\u3068\u3044\u3046\u4e8b\u3067\u3001\u30a2\u30ca\u30ea\u30c6\u30a3\u30af\u30b9\u304b\u3089\u30e9\u30f3\u30ad\u30f3\u30b0\u3092\u53d6\u5f97\u3057\u3066\u8868\u793a\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u4f5c\u308a\u65b9\u3054\u7d39\u4ecb\u3067\u3057\u305f\u3002<br \/>\n\u4f5c\u3063\u3066\u307f\u305f\u611f\u60f3\u3068\u3057\u3066\u306f\u3001\u3042\u307e\u308a\u4f7f\u308f\u306a\u3044\u7528\u8a9e(\u30e1\u30c8\u30ea\u30af\u30b9\u3068\u304b)\u304c\u3042\u308b\u306e\u3067\u3001\u305d\u306e\u8fba\u306e\u7406\u89e3\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u305f\u308a\u3001\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u304c\u8a00\u3046\u307b\u3069\u5145\u5b9f\u3057\u3066\u306a\u3044\u306e\u3067\u30b5\u30f3\u30d7\u30eb\u3092\u898b\u306a\u304c\u3089\u3068\u304b\u8abf\u3079\u306a\u304c\u3089\u3068\u3044\u3046\u306e\u304c\u3042\u3063\u305f\u306e\u3067\u5c11\u3057\u82e6\u52b4\u3057\u307e\u3057\u305f&#8230;\u3002<br \/>\n\u3068\u306f\u3044\u3048\u3001\u51e6\u7406\u81ea\u4f53\u306f\u8907\u96d1\u3067\u306f\u306a\u3044\u306e\u3067\u6163\u308c\u3066\u3057\u307e\u3048\u3070\u7c21\u5358\u306b\u4f5c\u308c\u305d\u3046\u306a\u6c17\u304c\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u4f7f\u3046\u3068\u8868\u73fe\u306e\u81ea\u7531\u5ea6\u304c\u591a\u5c11\u4e0a\u304c\u308a\u307e\u3059\u306e\u3067\u3001\u3082\u3046\u5c11\u3057\u5e45\u3092\u6301\u305f\u305b\u3066\u307f\u305f\u3044\u306a\u3068\u3044\u3046\u65b9\u306f\u662f\u975e\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3002 \u8a18\u4e8b\u306e\u4e2d\u306b\u6d41\u884c\u308a\u306e\u30cd\u30bf(\u3059\u3054\u30fc\u3044\uff01\u3068\u304b)\u3092\u5165\u308c\u3066\u307f\u3088\u3046\u3068\u601d\u3063\u305f\u3051\u3069\u3001\u7121\u7406\u77e2\u7406\u611f\u304c\u51c4\u3044\u306e\u3067\u8ae6\u3081\u3066\u3057\u307e\u3063\u305f\u6728\u6751\u3067\u3059\u3002 \u3055\u3066\u3001\u304a\u6c17\u3065\u304d\u306e\u65b9\u3082\u3044\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u304c\u30014\u67081\u65e5\u306b\u30db\u30fc\u30e0\u30da\u30fc\u30b8\u3068\u30d6\u30ed\u30b0\u304c\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u3057\u307e\u3057\u305f&#8230;<\/p>\n","protected":false},"author":5,"featured_media":327,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,18,8],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts\/2818"}],"collection":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/comments?post=2818"}],"version-history":[{"count":27,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts\/2818\/revisions"}],"predecessor-version":[{"id":3094,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts\/2818\/revisions\/3094"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/media\/327"}],"wp:attachment":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/media?parent=2818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/categories?post=2818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/tags?post=2818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}