Changeset 179801
- Timestamp:
- 12/05/2009 02:46:32 AM (16 years ago)
- Location:
- google-analyticator/trunk
- Files:
-
- 2 edited
-
google-analyticator.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
google-analyticator/trunk/google-analyticator.php
r179569 r179801 870 870 } 871 871 872 /** 873 * EXPERIMENTAL: Retrieve Google's visits for the given page 874 * More work needs to be done. Needs caching, needs to be less resource intensive, and 875 * needs an automated way to determine the page. 876 * Function may/will change in future releases. Only use if you know what you're doing. 877 * 878 * @param url - the page url, missing the domain information 879 * @param days - the number of days to get 880 * @return the number of visits 881 **/ 882 function get_analytics_visits_by_page($page, $days = 31) 883 { 884 require_once('class.analytics.stats.php'); 885 886 # Create a new API object 887 $api = new GoogleAnalyticsStats(); 888 889 # Get the current accounts accounts 890 $accounts = ga_get_analytics_accounts(); 891 892 # Verify accounts exist 893 if ( count($accounts) <= 0 ) 894 return 0; 895 896 # Loop throught the account and return the current account 897 foreach ( $accounts AS $account ) 898 { 899 # Check if the UID matches the selected UID 900 if ( $account['ga:webPropertyId'] == get_option('ga_uid') ) 901 { 902 $api->setAccount($account['id']); 903 break; 904 } 905 } 906 907 # Encode the page url 908 $page = urlencode($page); 909 910 # Get the metric information from Google 911 $before = date('Y-m-d', strtotime('-' . $days . ' days')); 912 $yesterday = date('Y-m-d', strtotime('-1 day')); 913 $stats = $api->getMetrics('ga:visits', $before, $yesterday, 'ga:pagePath', false, 'ga:pagePath%3D%3D' . $page, 1); 914 915 # Check the size of the stats array 916 if ( count($stats) <= 0 || !is_array($stats) ) { 917 return 0; 918 } else { 919 # Loop through each stat for display 920 foreach ( $stats AS $stat ) { 921 return $stat['ga:visits']; 922 } 923 } 924 } 925 872 926 ?> -
google-analyticator/trunk/readme.txt
r179569 r179801 54 54 * Switches current tracking script (ga.js) to the new awesome async tracking script. In laymen's terms: updates to the latest tracking code, the tracking script will load faster, and tracking will be more reliable. 55 55 * Removes settings made obsolete due to the new async tracking (footer tracking and http/https). 56 * Fixes the (not set) pages in the Top Pages section of the dashboard widget. Pages containing the title (not set) will be combined with the correct page and corresponding title. Note that I am still trying to get this bug fixed in the API; this is just a hold over until the bug is fixed.56 * Fixes the (not set) pages in the Top Pages section of the dashboard widget. Pages containing the title (not set) will be combined with the correct page and corresponding title. Note that I am still trying to get this bug fixed in the Google Analytics API; this is just a hold over until the bug is fixed. 57 57 * Adds a link to Google Analytics on the dashboard widget for quick access to view full stat reports. 58 58 * Fixes a Javascript error that prevented the dashboard widget from collapsing. 59 59 * Corrects a uid undefined error message that appeared if error reporting was set too high. 60 60 * Updates the included jQuery sparklines plugin to the latest version, 1.4.3. 61 * Adds an experimental function to retrieve page visitors stats for theme developers. This function is not final and only provided for advanced users who know what they're doing. Future versions will improve on the code already in place. Find the get_analytics_visits_by_page in google-analyticator.php to learn how to use. Use at your own risk. 61 62 * Removes references to Spiral Web Consulting. Google Analyticator is now being developed exclusively by Ronald Heft. 62 63
Note: See TracChangeset
for help on using the changeset viewer.