Viewing 1 replies (of 1 total)
  • Thread Starter DareDevil73

    (@daredevil73)

    i didn’ìt get any answer from you, so I customized the plugin on my own.

    Here is the changes for the file “google-analytics-stats-widget.php”.

    function getUniqueVisitors($account, $time = 1)
    
    	{
    
                // IF we have a cached version, return that, if not, continue on.
    
                if ( get_transient( 'google_stats_uniques' ) )
    
                    return get_transient( 'google_stats_uniques' );
    
                # Get the class for interacting with the Google Analytics
    
                require_once('class.analytics.stats.php');
    
                # Create a new Gdata call
    
                $stats = new GoogleAnalyticsStats();
    
                # Check if Google sucessfully logged in
    
                if ( ! $stats->checkLogin() )
    
                        return false;
    
                $account = $stats->getSingleProfile();
    
                $account = $account[0]['id'];
    
                # Set the account to the one requested
    
                $stats->setAccount($account);
    
                # Get the latest stats
    
                $before = date('Y-m-d', strtotime('-' . $time . ' days'));
    
                $yesterday = date('Y-m-d', strtotime('-1 day'));
    
                try{
    
                    //AP $result = $stats->getMetrics('ga:visitors', $before, $yesterday);
    
                    $result = $stats->getMetrics('ga:visits', $before, $yesterday);
    
                }
    
                catch(Exception $e){
    
                    print 'GA Widget - there was a service error ' . $e->getCode() . ':' . $e->getMessage();
    
                }
    
                //AP $uniques = number_format($result->totalsForAllResults['ga:visitors']);
    
                $uniques = number_format($result->totalsForAllResults['ga:visits']);
    
                # Store the array
    
                //AP set_transient( 'google_stats_uniques', $uniques, 60*60*12 ); // 12 ore
    
                set_transient( 'google_stats_uniques', $uniques, 60*60 ); // 1 ora
    
                # Return the visits
    
                return $uniques;
    
    	}
Viewing 1 replies (of 1 total)
  • The topic ‘Widget total sessions’ is closed to new replies.