get_results( yourls_apply_filter( 'stat_query_all', $query ) ); $referrers = array(); $direct = $notdirect = 0; $countries = array(); $dates = array(); $list_of_days = array(); $list_of_months = array(); $list_of_years = array(); $last_24h = array(); // Loop through all results and build list of referrers, countries and hits per day foreach( (array)$hits as $hit ) { extract( (array)$hit ); if ( isset( $country_code ) && $country_code ) { if( !array_key_exists( $country_code, $countries ) ) $countries[$country_code] = 0; $countries[$country_code]++; } if( isset( $referrer ) ) { if ( $referrer == 'direct' ) { $direct++; } else { $notdirect++; $host = yourls_get_domain( $referrer ); if( !array_key_exists( $host, $referrers ) ) $referrers[$host] = array( ); if( !array_key_exists( $referrer, $referrers[$host] ) ) $referrers[$host][$referrer] = 0; $referrers[$host][$referrer]++; } } if( isset( $click_time ) ) { $now = intval( date('U') ); preg_match('/(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/', $click_time, $matches); list( $temp, $year, $month, $day, $hour, $min, $sec ) = $matches; unset( $matches ); // Build array of $dates[$year][$month][$day] = number of clicks if( !array_key_exists( $year, $dates ) ) $dates[$year] = array(); if( !array_key_exists( $month, $dates[$year] ) ) $dates[$year][$month] = array(); if( !array_key_exists( $day, $dates[$year][$month] ) ) $dates[$year][$month][$day] = 0; $dates[$year][$month][$day]++; // Build array of last 24 hours $last_24h[$hour] = number of click $then = strtotime( $click_time); if( ( $now >= $then ) && ( ( $now - $then ) < ( 24 * 60 * 60 ) ) ) { $year = sprintf( "%02d", substr($year, -2) ); // 2009 -> 09 $diff = $now - strtotime( $click_time); if( !array_key_exists( "$year-$month-$day-$hour", $last_24h ) ) $last_24h["$year-$month-$day-$hour"] = 0; $last_24h["$year-$month-$day-$hour"]++; } } } // Sort dates, chronologically from [2007][12][24] to [2009][02][19] ksort( $dates ); foreach( $dates as $year=>$months ) { ksort( $dates[$year] ); foreach( $months as $month=>$day ) { ksort( $dates[$year][$month] ); } } // Get $list_of_days, $list_of_months, $list_of_years reset($dates); $first_year = key( $dates ); $last_year = end( array_keys($dates) ); if( $dates ) { extract( yourls_build_list_of_days( $dates ) ); // If the $last_24h doesn't have all the hours, insert missing hours with value 0 for ($i = 23; $i >= 0; $i--) { $h = date('y-m-d-H', $now - ($i * 60 * 60) ); if( !array_key_exists( $h, $last_24h ) ) { $last_24h[$h] = 0; } } ksort( $last_24h ); } // Sort countries, most frequent first if ( $countries ) arsort( $countries ); // Sort referrers. $referrer_sort is a array of most frequent domains arsort( $referrers ); $referrer_sort = array(); $number_of_sites = count( array_keys( $referrers ) ); foreach( $referrers as $site => $urls ) { if( count($urls) > 1 || $number_of_sites == 1 ) $referrer_sort[$site] = array_sum( $urls ); } arsort($referrer_sort); // Filter all this junk if applicable. Be warned, some are possibly huge datasets. $referrers = yourls_apply_filter( 'pre_yourls_info_referrers', $referrers ); $referrer_sort = yourls_apply_filter( 'pre_yourls_info_referrer_sort', $referrer_sort ); $direct = yourls_apply_filter( 'pre_yourls_info_direct', $direct ); $notdirect = yourls_apply_filter( 'pre_yourls_info_notdirect', $notdirect ); $dates = yourls_apply_filter( 'pre_yourls_info_dates', $dates ); $list_of_days = yourls_apply_filter( 'pre_yourls_info_list_of_days', $list_of_days ); $list_of_months = yourls_apply_filter( 'pre_yourls_info_list_of_months', $list_of_months ); $list_of_years = yourls_apply_filter( 'pre_yourls_info_list_of_years', $list_of_years ); $last_24h = yourls_apply_filter( 'pre_yourls_info_last_24h', $last_24h ); $countries = yourls_apply_filter( 'pre_yourls_info_countries', $countries ); /** echo "
";
	echo "referrers: "; print_r( $referrers );
	echo "referrer sort: "; print_r( $referrer_sort );
	echo "direct: $direct\n";
	echo "notdirect: $notdirect\n";
	echo "dates: "; print_r( $dates );
	echo "list of days: "; print_r( $list_of_days );
	echo "list_of_months: "; print_r( $list_of_months );
	echo "list_of_years: "; print_r( $list_of_years );
	echo "last_24h: "; print_r( $last_24h );
	echo "countries: "; print_r( $countries );
	die();
	/**/

}

yourls_html_head( 'infos', 'Statistics for '.YOURLS_SITE.'/'.$keyword );
yourls_html_logo();
yourls_html_menu();
?>

Short URL: 1 ) echo ' '; } ?>

Long URL:

Traffic statistics

'Last 24 hours', '7' => 'Last 7 days', '30' => 'Last 30 days', 'all'=> 'All time' ); // Which graph to generate ? $do_all = $do_30 = $do_7 = $do_24 = false; $hits_all = array_sum( $list_of_days ); $hits_30 = array_sum( array_slice( $list_of_days, -30 ) ); $hits_7 = array_sum( array_slice( $list_of_days, -7 ) ); $hits_24 = array_sum( $last_24h ); if( $hits_all > 0 ) $do_all = true; // graph for all days range if( $hits_30 > 0 && count( array_slice( $list_of_days, -30 ) ) == 30 ) $do_30 = true; // graph for last 30 days if( $hits_7 > 0 && count( array_slice( $list_of_days, -7 ) ) == 7 ) $do_7 = true; // graph for last 7 days if( $hits_24 > 0 ) $do_24 = true; // graph for last 24 hours // Which graph to display ? $display_all = $display_30 = $display_7 = $display_24 = false; if( $do_24 ) { $display_24 = true; } elseif ( $do_7 ) { $display_7 = true; } elseif ( $do_30 ) { $display_30 = true; } elseif ( $do_all ) { $display_all = true; } ?>
$graphtitle ) { if( ${'do_'.$graph} == true ) { $display = ( ${'display_'.$graph} === true ? 'display:block' : 'display:none' ); echo "
"; $labels_1 = $labels_2 = array(); switch( $graph ) { case '24': // each key of $last_24h is of type "yy-mm-dd-hh" $first_key = current( array_keys( $last_24h ) ); $last_key = end( array_keys( $last_24h ) ); // Get "dd/mm" of first and last key $first_label = preg_replace( '/\d\d-(\d\d)-(\d\d)-\d\d/', '$2/$1', $first_key ); $last_label = preg_replace( '/\d\d-(\d\d)-(\d\d)-\d\d/', '$2/$1', $last_key ); $labels_2 = array( $first_label, $last_label); // Get hh of each key foreach( $last_24h as $k=>$v ) { $labels_1[] = end( explode( '-', $k ) ); // 'hh' } echo "

Number of hits : $graphtitle

"; yourls_stats_line( $last_24h, $labels_1, $labels_2 ); break; case '7': case '30': // each key of $list_of_days is of type "yyyy-mm-dd" $slice = array_slice( $list_of_days, intval( $graph ) * -1 ); foreach( $slice as $k=>$v ) { // get "dd" $labels_1[] = preg_replace( '/\d\d\d\d-\d\d-(\d\d)/', '$1', $k ); } $first_key = current( array_keys( $slice ) ); $last_key = end( array_keys( $slice ) ); // Get "dd/mm" of first and last key $first_label = preg_replace( '/\d\d\d\d-(\d\d)-(\d\d)/', '$2/$1', $first_key ); $last_label = preg_replace( '/\d\d\d\d-(\d\d)-(\d\d)/', '$2/$1', $last_key ); $labels_2 = array( $first_label, $last_label); echo "

Number of hits : $graphtitle

"; yourls_stats_line( $slice, $labels_1, $labels_2 ); unset( $slice ); break; case 'all': // get "yy-mm" foreach( $list_of_days as $k=>$v ) { $labels_1[] = preg_replace( '/\d\d(\d\d)-(\d\d)-\d\d/', '$1-$2', $k ); } // take out duplicates $labels_1 = array_unique( $labels_1 ); // now get "mm" only so we have all different month foreach( $labels_1 as $k=>$v ) { $labels_1[$k] = preg_replace( '/\d\d-(\d\d)/', '$1', $v ); } echo "

Number of hits : $graphtitle

"; $labels_1 = yourls_array_granularity( $labels_1, 30, false ); $labels_2 = yourls_array_granularity( $list_of_years, 30, false ); yourls_stats_line( $list_of_days, $labels_1, $labels_2 ); break; } echo "
\n"; } } ?>

Historical click count

Short URL created on

    $graphtitle ) { if ( ${'do_'.$graph} ) { $link = "$graphtitle"; } else { $link = $graphtitle; } $stat = ''; if( ${'do_'.$graph} ) { switch( $graph ) { case '7': case '30': $stat = round( ( ${'hits_'.$graph} / intval( $graph ) ) * 100 ) / 100 . ' per day'; break; case '24': $stat = round( ( ${'hits_'.$graph} / 24 ) * 100 ) / 100 . ' per hour'; break; case 'all': if( $ago > 0 ) $stat = round( ( ${'hits_'.$graph} / $ago ) * 100 ) / 100 . ' per day'; } } $hits = yourls_plural( 'hit', ${'hits_'.$graph} ); echo "
  • $link ${'hits_'.$graph} $hits $stat
  • \n"; } ?>

Best day

on . Click for more details

No traffic yet. Get some clicks first!

"; } ?>

Traffic location

Top 5 countries

Click for more details

Overall traffic

No country data.

"; } ?>

Traffic Sources

Referrer shares

1 ) $referrer_sort['Others'] = count( $referrers ); yourls_stats_pie( $referrer_sort, 5, '440x220' ); unset( $referrer_sort['Others'] ); ?>

Referrers

    $count ) { $i++; $favicon = yourls_get_favicon_url( $site ); echo "
  • $site: $count (details)
  • \n"; echo "\n"; unset( $referrers[$site] ); } // Any referrer left? Group in "various" if ( $referrers ) { echo "
  • Various: ". count( $referrers ). " (details)
  • \n"; echo "\n"; } ?>

Direct vs Referrer Traffic

$direct, 'Referrers'=> $notdirect), 5, '440x220' ); ?>

Direct traffic:

Referrer traffic:

No referrer data.

"; } ?>

Share

Short link', '

Quick Share

'); ?>