google_analytics_master_admin_statistics_7_days

The Google Analytics Master google analytics master admin statistics 7 days function.

Description

google_analytics_master_admin_statistics_7_days(); 

Usage

  1. if ( !function_exists( 'google_analytics_master_admin_statistics_7_days' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-analytics-master/includes/google-analytics-master-admin-statistics-7-days.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = google_analytics_master_admin_statistics_7_days(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/google-analytics-master-admin-statistics-7-days.php  
  1. function google_analytics_master_admin_statistics_7_days() { 
  2. ?> 
  3. <div class="wrap"> 
  4. <h2>Statistics 7 Days</h2> 
  5. <br> 
  6.  
  7. <!-- This code snippet checks if Client Id is set in wordpress --> 
  8. <?php  
  9. if(is_multisite()) { 
  10. $google_analytics_master_name = get_site_option('google_analytics_master_name'); 
  11. $google_analytics_master_client_id = get_site_option('google_analytics_master_client_id'); 
  12. if(empty($google_analytics_master_client_id)) { 
  13. echo '<div class="notice notice-error is-dismissible">'; 
  14. printf (__('<h3>Warning!!!</h3><p> Go to '.$google_analytics_master_name.' -> Settings page and insert your Google Client ID.</p>')); 
  15. echo '<p><a href="https://console.developers.google.com" target="_blank">Get Google Analytics OAuth 2.0 Credentials -> Client ID</a></p><br>'; 
  16. echo '</div>'; 
  17. else{ 
  18. $google_analytics_master_name = get_option('google_analytics_master_name'); 
  19. $google_analytics_master_client_id = get_option('google_analytics_master_client_id'); 
  20. if(empty($google_analytics_master_client_id)) { 
  21. echo '<div class="notice notice-error is-dismissible">'; 
  22. printf (__('<h3>Warning!!!</h3><p> Go to '.$google_analytics_master_name.' -> Settings page and insert your Google Client ID.</p>')); 
  23. echo '<p><a href="https://console.developers.google.com" target="_blank">Get Google Analytics OAuth 2.0 Credentials -> Client ID</a></p><br>'; 
  24. echo '</div>'; 
  25.  
  26. if(!empty($google_analytics_master_client_id)) { 
  27. ?> 
  28. <!-- START ANALYTICS EMBED --> 
  29. <!DOCTYPE html> 
  30. <meta charset="utf-8"> 
  31.  
  32. <script> 
  33. (function(w, d, s, g, js, fs) { 
  34. g=w.gapi||(w.gapi={});g.analytics={q:[], ready:function(f) {this.q.push(f);}}; 
  35. js=d.createElement(s);fs=d.getElementsByTagName(s)[0]; 
  36. js.src='https://apis.google.com/js/platform.js'; 
  37. fs.parentNode.insertBefore(js, fs);js.onload=function() {g.load('analytics');}; 
  38. }(window, document, 'script')); 
  39. </script> 
  40.  
  41. <div class="Dashboard Dashboard--full"> 
  42. <header class="Dashboard-header"> 
  43. <div id="embed-api-auth-container"></div> 
  44. <ul class="FlexGrid"> 
  45. <li class="FlexGrid-item"> 
  46. <div class="Titles"> 
  47. <h1 class="Titles-main" id="view-name">Select a View</h1> 
  48. <div class="Titles-sub">Various visualizations</div> 
  49. </div> 
  50. </li> 
  51. <li class="FlexGrid-item FlexGrid-item--fixed"> 
  52. <div id="active-users-container"></div> 
  53. </li> 
  54. </ul> 
  55. <div id="view-selector-container" style="display: flex;"></div> 
  56. </header> 
  57.  
  58. <ul class="FlexGrid FlexGrid--halves"> 
  59. <li class="FlexGrid-item"> 
  60. <header class="Titles"> 
  61. <h1 class="Titles-main">Sessions</h1> 
  62. <div class="Titles-sub">Last 7 days</div> 
  63. </header> 
  64. <div id="chart-container"></div> 
  65. </li> 
  66. <li class="FlexGrid-item"> 
  67. <div class="Chartjs"> 
  68. <header class="Titles"> 
  69. <h1 class="Titles-main">Top Countries by Sessions</h1> 
  70. <div class="Titles-sub">Last 7 days</div> 
  71. </header> 
  72. <figure class="Chartjs-figure" id="chart-1-container"></figure> 
  73. <ol class="Chartjs-legend" id="legend-1-container"></ol> 
  74. </div> 
  75. </li> 
  76. <li class="FlexGrid-item"> 
  77. <div class="Chartjs"> 
  78. <header class="Titles"> 
  79. <h1 class="Titles-main">Top Operating Systems</h1> 
  80. <div class="Titles-sub">Last 7 days</div> 
  81. </header> 
  82. <figure class="Chartjs-figure" id="os-chart-container"></figure> 
  83. <ol class="Chartjs-legend" id="legend-2-container"></ol> 
  84. </div> 
  85. </li> 
  86. <li class="FlexGrid-item"> 
  87. <div class="Chartjs"> 
  88. <header class="Titles"> 
  89. <h1 class="Titles-main">Top Referals</h1> 
  90. <div class="Titles-sub">Last 7 days</div> 
  91. </header> 
  92. <figure class="Chartjs-figure" id="referer-chart-container"></figure> 
  93. <ol class="Chartjs-legend" id="legend-3-container"></ol> 
  94. </div> 
  95. </li> 
  96. <li class="FlexGrid-item"> 
  97. <div class="Chartjs"> 
  98. <header class="Titles"> 
  99. <h1 class="Titles-main">Top Browsers</h1> 
  100. <div class="Titles-sub">Last 7 days</div> 
  101. </header> 
  102. <figure class="Chartjs-figure" id="main-chart-container"></figure> 
  103. <ol class="Chartjs-legend" id="legend-4-container"></ol> 
  104. </div> 
  105. </li> 
  106. <li class="FlexGrid-item"> 
  107. <div class="Chartjs"> 
  108. <header class="Titles"> 
  109. <h1 class="Titles-main">Top Languages</h1> 
  110. <div class="Titles-sub">Last 7 days</div> 
  111. </header> 
  112. <figure class="Chartjs-figure" id="lang-chart-container"></figure> 
  113. <ol class="Chartjs-legend" id="legend-5-container"></ol> 
  114. </div> 
  115. </li> 
  116. </ul> 
  117.  
  118. <div style="z-index: 1; position: relative;"><h3>Want to customize the display or add more metrics? Get in touch with us via <a href="https://wordpress.techgasp.com/support" target="_blank" title="Visit Website">Ticket</a></h3></div> 
  119.  
  120. </div> 
  121.  
  122. <!-- Include the ViewSelector2 component script. --> 
  123. <script src="<?php echo plugins_url('public/javascript/embed-api/components/view-selector2.js', __FILE__); ?>"></script> 
  124.  
  125. <!-- Include the DateRangeSelector component script. --> 
  126. <script src="<?php echo plugins_url('public/javascript/embed-api/components/date-range-selector.js', __FILE__); ?>"></script> 
  127.  
  128. <!-- Include the ActiveUsers component script. --> 
  129. <script src="<?php echo plugins_url('public/javascript/embed-api/components/active-users.js', __FILE__); ?>"></script> 
  130.  
  131. <!-- Include the CSS that styles the charts. --> 
  132. <link rel="stylesheet" href="<?php echo plugins_url('public/css/index.css', __FILE__); ?>"> 
  133. <link rel="stylesheet" href="<?php echo plugins_url('public/css/normalize.css', __FILE__); ?>"> 
  134. <link rel="stylesheet" href="<?php echo plugins_url('public/css/chartjs-visualizations.css', __FILE__); ?>"> 
  135.  
  136. <script> 
  137.  
  138. // == NOTE == 
  139. // This code uses ES6 promises. If you want to use this code in a browser 
  140. // that doesn't supporting promises natively, you'll have to include a polyfill. 
  141.  
  142. gapi.analytics.ready(function() { 
  143.  
  144. /** 
  145. * Authorize the user immediately if the user has already granted access. 
  146. * If no access has been created, render an authorize button inside the 
  147. * element with the ID "embed-api-auth-container". 
  148. */ 
  149. gapi.analytics.auth.authorize({ 
  150. container: 'embed-api-auth-container',  
  151. clientid: '<?php  
  152. if(is_multisite()) { 
  153. echo get_site_option('google_analytics_master_client_id'); 
  154. else{ 
  155. echo get_option('google_analytics_master_client_id'); 
  156. ?>',  
  157. }); 
  158.  
  159.  
  160. /** 
  161. * Create a new ViewSelector instance to be rendered inside of an 
  162. * element with the id "view-selector-container". 
  163. */ 
  164. var viewSelector = new gapi.analytics.ViewSelector({ 
  165. container: 'view-selector-container' 
  166. }); 
  167.  
  168. // Render the view selector to the page. 
  169. viewSelector.execute(); 
  170.  
  171.  
  172. /** 
  173. * Create a new DataChart instance with the given query parameters 
  174. * and Google chart options. It will be rendered inside an element 
  175. * with the id "chart-container". 
  176. */ 
  177. var dataChart = new gapi.analytics.googleCharts.DataChart({ 
  178. query: { 
  179. metrics: 'ga:sessions',  
  180. dimensions: 'ga:date',  
  181. 'start-date': '7daysAgo',  
  182. 'end-date': 'yesterday' 
  183. },  
  184. chart: { 
  185. container: 'chart-container',  
  186. type: 'LINE',  
  187. options: { 
  188. width: '100%' 
  189. }); 
  190.  
  191. /** 
  192. * Create the first DataChart for top countries over the past 7 days. 
  193. * It will be rendered inside an element with the id "chart-1-container". 
  194. */ 
  195. var dataChart1 = new gapi.analytics.googleCharts.DataChart({ 
  196. query: { 
  197. metrics: 'ga:sessions',  
  198. dimensions: 'ga:country',  
  199. 'start-date': '7daysAgo',  
  200. 'end-date': 'yesterday',  
  201. 'max-results': 10,  
  202. sort: '-ga:sessions' 
  203. },  
  204. chart: { 
  205. container: 'chart-1-container',  
  206. type: 'PIE',  
  207. options: { 
  208. width: '100%',  
  209. pieHole: 4/9 
  210. }); 
  211.  
  212. /** 
  213. * Create a table chart showing top browsers for users to interact with. 
  214. * Clicking on a row in the table will update a second timeline chart with 
  215. * data from the selected browser. 
  216. */  
  217. var mainChart = new gapi.analytics.googleCharts.DataChart({ 
  218. query: { 
  219. 'dimensions': 'ga:browser',  
  220. 'metrics': 'ga:sessions',  
  221. 'start-date': '7daysAgo',  
  222. 'end-date': 'yesterday',  
  223. 'sort': '-ga:sessions',  
  224. 'max-results': '7' 
  225. },  
  226. chart: { 
  227. type: 'TABLE',  
  228. container: 'main-chart-container',  
  229. options: { 
  230. width: '100%' 
  231. }); 
  232.  
  233. var refererChart = new gapi.analytics.googleCharts.DataChart({ 
  234. query: { 
  235. 'dimensions': 'ga:fullReferrer',  
  236. 'metrics': 'ga:sessions',  
  237. 'start-date': '7daysAgo',  
  238. 'end-date': 'yesterday',  
  239. 'sort': '-ga:sessions',  
  240. 'max-results': '7' 
  241. },  
  242. chart: { 
  243. container: 'referer-chart-container',  
  244. type: 'PIE',  
  245. options: { 
  246. width: '100%',  
  247. pieHole: 4/9 
  248. }); 
  249.  
  250. var osChart = new gapi.analytics.googleCharts.DataChart({ 
  251. query: { 
  252. 'dimensions': 'ga:operatingSystem',  
  253. 'metrics': 'ga:sessions',  
  254. 'start-date': '7daysAgo',  
  255. 'end-date': 'yesterday',  
  256. 'sort': '-ga:sessions',  
  257. 'max-results': '7' 
  258. },  
  259. chart: { 
  260. type: 'TABLE',  
  261. container: 'os-chart-container',  
  262. options: { 
  263. width: '100%' 
  264. });  
  265.  
  266. var langChart = new gapi.analytics.googleCharts.DataChart({ 
  267. query: { 
  268. 'dimensions': 'ga:language',  
  269. 'metrics': 'ga:sessions',  
  270. 'start-date': '7daysAgo',  
  271. 'end-date': 'yesterday',  
  272. 'sort': '-ga:sessions',  
  273. 'max-results': '7' 
  274. },  
  275. chart: { 
  276. container: 'lang-chart-container',  
  277. type: 'PIE',  
  278. options: { 
  279. width: '100%',  
  280. pieHole: 4/9 
  281. }); 
  282.  
  283. /** 
  284. * Render the dataChart on the page whenever a new view is selected. 
  285. */ 
  286. viewSelector.on('change', function(ids) { 
  287. dataChart.set({query: {ids: ids}}).execute(); 
  288. dataChart1.set({query: {ids: ids}}).execute(); 
  289. mainChart.set({query: {ids: ids}}).execute(); 
  290. refererChart.set({query: {ids: ids}}).execute(); 
  291. osChart.set({query: {ids: ids}}).execute(); 
  292. langChart.set({query: {ids: ids}}).execute(); 
  293. }); 
  294.  
  295. }); 
  296. </script> 
  297.  
  298. <div style="clear:both"> 
  299. <br> 
  300. <h2>IMPORTANT: Makes no use of Javascript or Ajax to keep your website fast and conflicts free</h2> 
  301.  
  302. <div style="background: url(<?php echo plugins_url('../images/techgasp-hr.png', __FILE__); ?>) repeat-x; height: 10px"></div> 
  303.  
  304. <br> 
  305.  
  306. <p> 
  307. <a class="button-secondary" href="http://wordpress.techgasp.com" target="_blank" title="Visit Website">More TechGasp Plugins</a> 
  308. <a class="button-secondary" href="http://wordpress.techgasp.com/support/" target="_blank" title="Facebook Page">TechGasp Support</a> 
  309. <a class="button-primary" href="http://wordpress.techgasp.com/google-analytics-master/" target="_blank" title="Visit Website"><?php echo get_option('google_analytics_master_name'); ?> Info</a> 
  310. <a class="button-primary" href="http://wordpress.techgasp.com/google-analytics-master-documentation/" target="_blank" title="Visit Website"><?php echo get_option('google_analytics_master_name'); ?> Documentation</a> 
  311. <a class="button-primary" href="http://wordpress.org/plugins/google-analytics-master/" target="_blank" title="Visit Website">RATE US *****</a> 
  312. </p> 
  313. </div> 
  314.  
  315. <?php