gglnltcs_get_statistic

The BestWebSoft Google Analytics gglnltcs get statistic function.

Description

Parameters (4)

0. $analytics
The analytics.
1. $post_data
The post data.
2. $gglnltcs_metrics_data
The gglnltcs metrics data.
3. $gglnltcs_dimensions_data
The gglnltcs dimensions data.

Usage

  1. if ( !function_exists( 'gglnltcs_get_statistic' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bestwebsoft-google-analytics/bws-google-analytics.php'; 
  3.  
  4. // The analytics. 
  5. $analytics = null; 
  6.  
  7. // The post data. 
  8. $post_data = null; 
  9.  
  10. // The gglnltcs metrics data. 
  11. $gglnltcs_metrics_data = null; 
  12.  
  13. // The gglnltcs dimensions data. 
  14. $gglnltcs_dimensions_data = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = gglnltcs_get_statistic($analytics, $post_data, $gglnltcs_metrics_data, $gglnltcs_dimensions_data); 
  18.  

Defined (1)

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

/bws-google-analytics.php  
  1. function gglnltcs_get_statistic( $analytics, $post_data, $gglnltcs_metrics_data, $gglnltcs_dimensions_data ) { 
  2. $metrics = $dimensions = array(); 
  3. /** Create a comma-separated list of Analytics metrics. E.g., 'ga:visits, ga:pageviews'. */ 
  4. foreach ( $gglnltcs_metrics_data as $metric ) { 
  5. if ( isset( $post_data[ $metric['name'] ] ) ) { 
  6. $metrics[] = $post_data[ $metric['name'] ]; 
  7. $metrics = implode( ', ', $metrics ); 
  8. /** Create a comma-separated list of dimensions that determine the sort order for Analytics data. */ 
  9. foreach ( $gglnltcs_dimensions_data as $dimension ) { 
  10. if ( isset( $post_data[ $dimension['name'] ] ) ) { 
  11. $dimensions[] = $post_data[ $dimension['name'] ]; 
  12. $dimensions = implode( ', ', $dimensions ); 
  13. /** Do not delete the comment below! */ 
  14. /** $dimensions = array( 'dimensions' => $dimensions ); */?> 
  15. <div id="gglnltcs-results-wrapper"><?php 
  16. /** Get Analytics data for a view (profile). 
  17. * https://developers.google.com/analytics/devguides/reporting/core/v3/coreDevguide */ 
  18. try {  
  19. $dimensions = array( 'dimensions' => 'ga:year, ga:month, ga:day' ); 
  20. $results = $analytics->data_ga->get( $post_data['gglnltcs_view_id'], $post_data['gglnltcs_start_date'], $post_data['gglnltcs_end_date'], $metrics, $dimensions ); 
  21. $results = gglnltcs_print_results( $results, $gglnltcs_metrics_data, $gglnltcs_dimensions_data ); 
  22. echo $results[0], $results[1]; 
  23.  
  24. $dimensions = array( 'dimensions' => 'ga:year, ga:month' ); 
  25. $results = $analytics->data_ga->get( $post_data['gglnltcs_view_id'], $post_data['gglnltcs_start_date'], $post_data['gglnltcs_end_date'], $metrics, $dimensions );  
  26. $results = gglnltcs_print_results( $results, $gglnltcs_metrics_data, $gglnltcs_dimensions_data ); 
  27. echo $results[0], $results[1]; 
  28.  
  29. $dimensions = array( 'dimensions' => 'ga:year' ); 
  30. $results = $analytics->data_ga->get( $post_data['gglnltcs_view_id'], $post_data['gglnltcs_start_date'], $post_data['gglnltcs_end_date'], $metrics, $dimensions );  
  31. $results = gglnltcs_print_results( $results, $gglnltcs_metrics_data, $gglnltcs_dimensions_data ); 
  32. echo $results[0], $results[1]; ?> 
  33. <div id="gglnltcs-group-by-Y-M-D"> 
  34. <span><?php _e( 'Group by', 'gglnltcs' ); ?></span> 
  35. <div> 
  36. <input type="button" class="button-secondary" value="<?php _ex( 'Year', 'group-by', 'gglnltcs' ); ?>"> 
  37. <input type="button" class="button-secondary" value="<?php _ex( 'Month', 'group-by', 'gglnltcs' ); ?>"> 
  38. <input type="button" class="button-secondary gglnltcs-selected" value="<?php _ex( 'Day', 'group-by', 'gglnltcs' ); ?>"> 
  39. </div> 
  40. </div><?php 
  41. } catch ( Google_ServiceException $e ) { ?> 
  42. <table class="gglnltcs gglnltcs-results"> 
  43. <tr> 
  44. <th><h3><?php _e( 'Results', 'gglnltcs' ); ?></h3></th> 
  45. <td><div class="gglnltcs-bad-results gglnltcs-unsuccess-message"><?php _e( 'Invalid Date Range', 'gglnltcs' ); ?><div></td> 
  46. </tr> 
  47. </table><?php 
  48. } /** close catch.*/ ?> 
  49. </div><?php