diff --git a/changelog.txt b/changelog.txt index cdbf3b8..9bdc054 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,5 @@ - MyArcadePlugin Lite - + * Tweak - Improved stats tracking v5.4.0 - 2017-09-08 - Based on MyArcadePlugin Pro 5.30.0 * New - GameDistribution feed integration (http://www.gamedistribution.com/games/) diff --git a/includes/class-myarcade-stats.php b/includes/class-myarcade-stats.php index 5b49f52..7d02f4e 100644 --- a/includes/class-myarcade-stats.php +++ b/includes/class-myarcade-stats.php @@ -12,48 +12,62 @@ class MyArcade_Stats { /** * Get the play count for a time period * - * @version 5.30.0 + * @version 5.31.0 * @since 5.30.0 * @static * @access public - * @param string $time_period Number of days or 'total' - * @param boolean $daily True if daily stats over the given period should be returned - * @return integer Play count + * @param string $time_period Number of days or 'total' + * @param integer $min_duration It allows to count games by minimal play duration in seconds + * @return integer Play count */ - public static function get_plays( $time_period ) { + public static function get_plays( $time_period, $min_duration = 0 ) { global $wpdb; + $result = 0; + $query = ''; + + if ( $min_duration ) { + $duration_query = "AND WHERE duration >= '".intval( $min_duration )."'"; + } + else { + $duration_query = ""; + } + switch ( $time_period ) { case 'today': { - $result = $wpdb->get_var( "SELECT COUNT(1) FROM {$wpdb->prefix}myarcade_plays WHERE DATE_FORMAT( `date`, '%Y-%m-%d' ) = '".self::get_date()."'" ); + $query = "SELECT COUNT(1) FROM {$wpdb->prefix}myarcade_plays WHERE DATE_FORMAT( `date`, '%Y-%m-%d' ) = '".self::get_date()."' {$duration_query}"; } break; case 'yesterday': { - $result = $wpdb->get_var( "SELECT COUNT(1) FROM {$wpdb->prefix}myarcade_plays WHERE DATE_FORMAT( `date`, '%Y-%m-%d' ) = '".self::get_date( '-1' )."'" ); + $query = "SELECT COUNT(1) FROM {$wpdb->prefix}myarcade_plays WHERE DATE_FORMAT( `date`, '%Y-%m-%d' ) = '".self::get_date( '-1' )."' {$duration_query}"; } break; case 'week': { - $result = $wpdb->get_var( "SELECT COUNT(1) FROM {$wpdb->prefix}myarcade_plays WHERE DATE_FORMAT( `date`, '%Y-%m-%d' ) BETWEEN '".self::get_date( '-7' )."' AND '".self::get_date()."'" ); + $query = "SELECT COUNT(1) FROM {$wpdb->prefix}myarcade_plays WHERE DATE_FORMAT( `date`, '%Y-%m-%d' ) BETWEEN '".self::get_date( '-7' )."' AND '".self::get_date()."' {$duration_query}"; } break; case 'month': { - $result = $wpdb->get_var( "SELECT COUNT(1) FROM {$wpdb->prefix}myarcade_plays WHERE DATE_FORMAT( `date`, '%Y-%m-%d' ) BETWEEN '".self::get_date( '-30' )."' AND '".self::get_date()."'" ); + $query = "SELECT COUNT(1) FROM {$wpdb->prefix}myarcade_plays WHERE DATE_FORMAT( `date`, '%Y-%m-%d' ) BETWEEN '".self::get_date( '-30' )."' AND '".self::get_date()."' {$duration_query}"; } break; case 'year': { - $result = $wpdb->get_var( "SELECT COUNT(1) FROM {$wpdb->prefix}myarcade_plays WHERE DATE_FORMAT( `date`, '%Y-%m-%d' ) BETWEEN '".self::get_date( '-365' )."' AND '".self::get_date()."'" ); + $query = "SELECT COUNT(1) FROM {$wpdb->prefix}myarcade_plays WHERE DATE_FORMAT( `date`, '%Y-%m-%d' ) BETWEEN '".self::get_date( '-365' )."' AND '".self::get_date()."' {$duration_query}"; } break; case 'total': { - $result = get_option( 'myarcade_site_plays' ); + return intval( get_option( 'myarcade_site_plays' ) ); } break; default: { - $result = $wpdb->get_var( "SELECT COUNT(1) FROM {$wpdb->prefix}myarcade_plays WHERE DATE_FORMAT( `date`, '%Y-%m-%d' ) = '".self::get_date( $time_period )."'" ); + $query = "SELECT COUNT(1) FROM {$wpdb->prefix}myarcade_plays WHERE DATE_FORMAT( `date`, '%Y-%m-%d' ) = '".self::get_date( $time_period )."' {$duration_query}"; } break; } + if ( $query ) { + $result = $wpdb->get_var( $query ); + } + return intval( $result ); } diff --git a/includes/class-myarcade-tracker.php b/includes/class-myarcade-tracker.php index d6858bf..d183d5d 100644 --- a/includes/class-myarcade-tracker.php +++ b/includes/class-myarcade-tracker.php @@ -71,13 +71,13 @@ private static function get_last_send_time() { /** * Get all the tracking data * - * @version 5.30.0 + * @version 5.31.0 * @since 5.30.0 * @static - * @access private + * @access protected * @return array Array of tracking data */ - private static function get_tracking_data() { + protected static function get_tracking_data() { $data = array(); @@ -106,8 +106,12 @@ private static function get_tracking_data() { // Get game plays so we can show a top list of MyArcadePlugin sites $data['total_plays'] = self::get_total_plays(); + // All game plays $data['plays'] = self::get_plays(); + // Games with minium play duration of 30 seconds + $data['plays_duration'] = self::get_plays(30); + return $data; } @@ -140,7 +144,7 @@ private static function get_theme_info() { * MyArcadePlugin memory usage and to know which older WP versions * we still need to support. * - * @version 5.30.0 + * @version 5.31.0 * @since 5.30.0 * @static * @access private @@ -148,10 +152,12 @@ private static function get_theme_info() { */ private static function get_wordpress_info() { - $wp_data = array(); - $wp_data['locale'] = get_locale(); - $wp_data['version'] = get_bloginfo( 'version' ); - $wp_data['multisite'] = is_multisite() ? 'Yes' : 'No'; + $wp_data = array( + 'name' => get_bloginfo( 'name' ), + 'locale' => get_locale(), + 'version' => get_bloginfo( 'version' ), + 'multisite' => is_multisite() ? 'Yes' : 'No', + ); return $wp_data; } @@ -255,18 +261,19 @@ private static function get_total_plays() { /** * Get plays by date * - * @version 5.30.0 + * @version 5.31.0 * @since 5.30.0 * @static * @access private + * @param int $min_duration Time in seconds (minimal play duration) * @return array Array of dates and play count */ - private static function get_plays() { + private static function get_plays( $min_duration = 0 ) { // We only want to collect plays history to be able to create a top list of myarcadeplugin sites $plays = array( 'date' => MyArcade_Stats::get_date( '-1' ), - 'impressions' => MyArcade_Stats::get_plays( 'yesterday' ) + 'impressions' => MyArcade_Stats::get_plays( 'yesterday', $min_duration ) ); return $plays;