PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/google-analyticator/google-analyticator.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 1037 lines | 839 code | 109 blank | 89 comment | 138 complexity | dda34250c358e580cc01262f35b95d5e MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /*
  3. * Plugin Name: Google Analyticator
  4. * Version: 6.2
  5. * Plugin URI: http://ronaldheft.com/code/analyticator/
  6. * Description: Adds the necessary JavaScript code to enable <a href="http://www.google.com/analytics/">Google's Analytics</a>. After enabling this plugin visit <a href="options-general.php?page=google-analyticator.php">the settings page</a> and enter your Google Analytics' UID and enable logging.
  7. * Author: Ronald Heft
  8. * Author URI: http://ronaldheft.com/
  9. * Text Domain: google-analyticator
  10. */
  11. define('GOOGLE_ANALYTICATOR_VERSION', '6.2');
  12. // Constants for enabled/disabled state
  13. define("ga_enabled", "enabled", true);
  14. define("ga_disabled", "disabled", true);
  15. // Defaults, etc.
  16. define("key_ga_uid", "ga_uid", true);
  17. define("key_ga_status", "ga_status", true);
  18. define("key_ga_admin", "ga_admin_status", true);
  19. define("key_ga_admin_disable", "ga_admin_disable", true);
  20. define("key_ga_admin_role", "ga_admin_role", true);
  21. define("key_ga_dashboard_role", "ga_dashboard_role", true);
  22. define("key_ga_adsense", "ga_adsense", true);
  23. define("key_ga_extra", "ga_extra", true);
  24. define("key_ga_extra_after", "ga_extra_after", true);
  25. define("key_ga_event", "ga_event", true);
  26. define("key_ga_outbound", "ga_outbound", true);
  27. define("key_ga_outbound_prefix", "ga_outbound_prefix", true);
  28. define("key_ga_downloads", "ga_downloads", true);
  29. define("key_ga_downloads_prefix", "ga_downloads_prefix", true);
  30. define("key_ga_widgets", "ga_widgets", true);
  31. define("key_ga_sitespeed", "ga_sitespeed", true);
  32. define("ga_uid_default", "XX-XXXXX-X", true);
  33. define("ga_status_default", ga_disabled, true);
  34. define("ga_admin_default", ga_enabled, true);
  35. define("ga_admin_disable_default", 'remove', true);
  36. define("ga_adsense_default", "", true);
  37. define("ga_extra_default", "", true);
  38. define("ga_extra_after_default", "", true);
  39. define("ga_event_default", ga_enabled, true);
  40. define("ga_outbound_default", ga_enabled, true);
  41. define("ga_outbound_prefix_default", 'outgoing', true);
  42. define("ga_downloads_default", "", true);
  43. define("ga_downloads_prefix_default", "download", true);
  44. define("ga_widgets_default", ga_enabled, true);
  45. define("ga_sitespeed_default", ga_enabled, true);
  46. // Create the default key and status
  47. add_option(key_ga_status, ga_status_default, '');
  48. add_option(key_ga_uid, ga_uid_default, '');
  49. add_option(key_ga_admin, ga_admin_default, '');
  50. add_option(key_ga_admin_disable, ga_admin_disable_default, '');
  51. add_option(key_ga_admin_role, array('administrator'), '');
  52. add_option(key_ga_dashboard_role, array('administrator'), '');
  53. add_option(key_ga_adsense, ga_adsense_default, '');
  54. add_option(key_ga_extra, ga_extra_default, '');
  55. add_option(key_ga_extra_after, ga_extra_after_default, '');
  56. add_option(key_ga_event, ga_event_default, '');
  57. add_option(key_ga_outbound, ga_outbound_default, '');
  58. add_option(key_ga_outbound_prefix, ga_outbound_prefix_default, '');
  59. add_option(key_ga_downloads, ga_downloads_default, '');
  60. add_option(key_ga_downloads_prefix, ga_downloads_prefix_default, '');
  61. add_option('ga_profileid', '', '');
  62. add_option(key_ga_widgets, ga_widgets_default, '');
  63. add_option('ga_google_token', '', '');
  64. add_option('ga_compatibility', 'off', '');
  65. add_option(key_ga_sitespeed, ga_sitespeed_default, '');
  66. # Check if we have a version of WordPress greater than 2.8
  67. if ( function_exists('register_widget') ) {
  68. # Check if widgets are enabled
  69. if ( get_option(key_ga_widgets) == 'enabled' ) {
  70. # Include Google Analytics Stats widget
  71. require_once('google-analytics-stats-widget.php');
  72. # Include the Google Analytics Summary widget
  73. require_once('google-analytics-summary-widget.php');
  74. $google_analytics_summary = new GoogleAnalyticsSummary();
  75. }
  76. }
  77. // Create a option page for settings
  78. add_action('admin_init', 'ga_admin_init');
  79. add_action('admin_menu', 'add_ga_option_page');
  80. // Initialize the options
  81. function ga_admin_init() {
  82. # Load the localization information
  83. $plugin_dir = basename(dirname(__FILE__));
  84. load_plugin_textdomain('google-analyticator', 'wp-content/plugins/' . $plugin_dir . '/localizations', $plugin_dir . '/localizations');
  85. }
  86. # Add the core Google Analytics script, with a high priority to ensure last script for async tracking
  87. add_action('wp_head', 'add_google_analytics', 999999);
  88. add_action('login_head', 'add_google_analytics', 999999);
  89. # Initialize outbound link tracking
  90. add_action('init', 'ga_outgoing_links');
  91. // Hook in the options page function
  92. function add_ga_option_page() {
  93. $plugin_page = add_options_page(__('Google Analyticator Settings', 'google-analyticator'), 'Google Analytics', 'manage_options', basename(__FILE__), 'ga_options_page');
  94. # Include javascript on the GA settings page
  95. add_action('admin_head-' . $plugin_page, 'ga_admin_ajax');
  96. }
  97. add_action('plugin_action_links_' . plugin_basename(__FILE__), 'ga_filter_plugin_actions');
  98. // Add settings option
  99. function ga_filter_plugin_actions($links) {
  100. $new_links = array();
  101. $new_links[] = '<a href="options-general.php?page=google-analyticator.php">' . __('Settings', 'google-analyticator') . '</a>';
  102. return array_merge($new_links, $links);
  103. }
  104. add_filter('plugin_row_meta', 'ga_filter_plugin_links', 10, 2);
  105. // Add FAQ and support information
  106. function ga_filter_plugin_links($links, $file)
  107. {
  108. if ( $file == plugin_basename(__FILE__) )
  109. {
  110. $links[] = '<a href="http://forums.ronaldheft.com/viewforum.php?f=5">' . __('FAQ', 'google-analyticator') . '</a>';
  111. $links[] = '<a href="http://forums.ronaldheft.com/viewforum.php?f=6">' . __('Support', 'google-analyticator') . '</a>';
  112. $links[] = '<a href="http://ronaldheft.com/code/donate/">' . __('Donate', 'google-analyticator') . '</a>';
  113. }
  114. return $links;
  115. }
  116. function ga_options_page() {
  117. // If we are a postback, store the options
  118. if (isset($_POST['info_update'])) {
  119. # Verify nonce
  120. check_admin_referer('google-analyticator-update_settings');
  121. // Update the status
  122. $ga_status = $_POST[key_ga_status];
  123. if (($ga_status != ga_enabled) && ($ga_status != ga_disabled))
  124. $ga_status = ga_status_default;
  125. update_option(key_ga_status, $ga_status);
  126. // Update the UID
  127. $ga_uid = $_POST[key_ga_uid];
  128. if ($ga_uid == '')
  129. $ga_uid = ga_uid_default;
  130. update_option(key_ga_uid, $ga_uid);
  131. // Update the admin logging
  132. $ga_admin = $_POST[key_ga_admin];
  133. if (($ga_admin != ga_enabled) && ($ga_admin != ga_disabled))
  134. $ga_admin = ga_admin_default;
  135. update_option(key_ga_admin, $ga_admin);
  136. // Update the admin disable setting
  137. $ga_admin_disable = $_POST[key_ga_admin_disable];
  138. if ( $ga_admin_disable == '' )
  139. $ga_admin_disable = ga_admin_disable_default;
  140. update_option(key_ga_admin_disable, $ga_admin_disable);
  141. // Update the admin level
  142. if ( array_key_exists(key_ga_admin_role, $_POST) ) {
  143. $ga_admin_role = $_POST[key_ga_admin_role];
  144. } else {
  145. $ga_admin_role = "";
  146. }
  147. update_option(key_ga_admin_role, $ga_admin_role);
  148. // Update the dashboard level
  149. if ( array_key_exists(key_ga_dashboard_role, $_POST) ) {
  150. $ga_dashboard_role = $_POST[key_ga_dashboard_role];
  151. } else {
  152. $ga_dashboard_role = "";
  153. }
  154. update_option(key_ga_dashboard_role, $ga_dashboard_role);
  155. // Update the extra tracking code
  156. $ga_extra = $_POST[key_ga_extra];
  157. update_option(key_ga_extra, $ga_extra);
  158. // Update the extra after tracking code
  159. $ga_extra_after = $_POST[key_ga_extra_after];
  160. update_option(key_ga_extra_after, $ga_extra_after);
  161. // Update the adsense key
  162. $ga_adsense = $_POST[key_ga_adsense];
  163. update_option(key_ga_adsense, $ga_adsense);
  164. // Update the event tracking
  165. $ga_event = $_POST[key_ga_event];
  166. if (($ga_event != ga_enabled) && ($ga_event != ga_disabled))
  167. $ga_event = ga_event_default;
  168. update_option(key_ga_event, $ga_event);
  169. // Update the outbound tracking
  170. $ga_outbound = $_POST[key_ga_outbound];
  171. if (($ga_outbound != ga_enabled) && ($ga_outbound != ga_disabled))
  172. $ga_outbound = ga_outbound_default;
  173. update_option(key_ga_outbound, $ga_outbound);
  174. // Update the outbound prefix
  175. $ga_outbound_prefix = $_POST[key_ga_outbound_prefix];
  176. if ($ga_outbound_prefix == '')
  177. $ga_outbound_prefix = ga_outbound_prefix_default;
  178. update_option(key_ga_outbound_prefix, $ga_outbound_prefix);
  179. // Update the download tracking code
  180. $ga_downloads = $_POST[key_ga_downloads];
  181. update_option(key_ga_downloads, $ga_downloads);
  182. // Update the download prefix
  183. $ga_downloads_prefix = $_POST[key_ga_downloads_prefix];
  184. if ($ga_downloads_prefix == '')
  185. $ga_downloads_prefix = ga_downloads_prefix_default;
  186. update_option(key_ga_downloads_prefix, $ga_downloads_prefix);
  187. // Update the profile id
  188. update_option('ga_profileid', $_POST['ga_profileid']);
  189. // Update the widgets option
  190. $ga_widgets = $_POST[key_ga_widgets];
  191. if (($ga_widgets != ga_enabled) && ($ga_widgets != ga_disabled))
  192. $ga_widgets = ga_widgets_default;
  193. update_option(key_ga_widgets, $ga_widgets);
  194. // Update the compatibility options
  195. $ga_compatibility = $_POST['ga_compatibility'];
  196. if ( $ga_compatibility == '' )
  197. $ga_compatibility = 'off';
  198. update_option('ga_compatibility', $ga_compatibility);
  199. // Update the sitespeed option
  200. $ga_sitespeed = $_POST[key_ga_sitespeed];
  201. if (($ga_sitespeed != ga_enabled) && ($ga_sitespeed != ga_disabled))
  202. $ga_sitespeed = ga_widgets_default;
  203. update_option(key_ga_sitespeed, $ga_sitespeed);
  204. // Give an updated message
  205. echo "<div class='updated fade'><p><strong>" . __('Google Analyticator settings saved.', 'google-analyticator') . "</strong></p></div>";
  206. }
  207. // Output the options page
  208. ?>
  209. <div class="wrap">
  210. <h2><?php _e('Google Analyticator Settings', 'google-analyticator'); ?></h2>
  211. <p><em>Like Google Analyticator? Help support it <a href="http://ronaldheft.com/code/donate/">by donating to the developer</a>. This helps cover the cost of maintaining the plugin and development time toward new features. Every donation, no matter how small, is appreciated.</em></p>
  212. <form method="post" action="options-general.php?page=google-analyticator.php">
  213. <?php
  214. # Add a nonce
  215. wp_nonce_field('google-analyticator-update_settings');
  216. ?>
  217. <h3><?php _e('Basic Settings', 'google-analyticator'); ?></h3>
  218. <?php if (get_option(key_ga_status) == ga_disabled) { ?>
  219. <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
  220. <?php _e('Google Analytics integration is currently <strong>DISABLED</strong>.', 'google-analyticator'); ?>
  221. </div>
  222. <?php } ?>
  223. <?php if ((get_option(key_ga_uid) == "XX-XXXXX-X") && (get_option(key_ga_status) != ga_disabled)) { ?>
  224. <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
  225. <?php _e('Google Analytics integration is currently enabled, but you did not enter a UID. Tracking will not occur.', 'google-analyticator'); ?>
  226. </div>
  227. <?php } ?>
  228. <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
  229. <tr>
  230. <th width="30%" valign="top" style="padding-top: 10px;">
  231. <label for="<?php echo key_ga_status ?>"><?php _e('Google Analytics logging is', 'google-analyticator'); ?>:</label>
  232. </th>
  233. <td>
  234. <?php
  235. echo "<select name='".key_ga_status."' id='".key_ga_status."'>\n";
  236. echo "<option value='".ga_enabled."'";
  237. if(get_option(key_ga_status) == ga_enabled)
  238. echo " selected='selected'";
  239. echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
  240. echo "<option value='".ga_disabled."'";
  241. if(get_option(key_ga_status) == ga_disabled)
  242. echo" selected='selected'";
  243. echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
  244. echo "</select>\n";
  245. ?>
  246. </td>
  247. </tr>
  248. <?php
  249. # Check if we have a version of WordPress greater than 2.8, and check if we have the memory to use the api
  250. if ( function_exists('register_widget') ) {
  251. ?>
  252. <tr>
  253. <th width="30%" valign="top" style="padding-top: 10px;">
  254. <label><?php _e('Authenticate with Google', 'google-analyticator'); ?>:</label>
  255. </th>
  256. <td>
  257. <?php if ( ( trim(get_option('ga_google_token')) == '' && !isset($_GET['token']) ) || ( isset($_GET['token']) && $_GET['token'] == 'deauth' ) ) { ?>
  258. <p style="margin-top: 7px;"><a href="https://www.google.com/accounts/AuthSubRequest?<?php echo http_build_query(array( 'next' => admin_url('/options-general.php?page=google-analyticator.php'),
  259. 'scope' => 'https://www.google.com/analytics/feeds/',
  260. 'secure' => 0,
  261. 'session' => 1,
  262. 'hd' => 'default'
  263. )); ?>"><?php _e('Click here to login to Google, thus authenticating Google Analyticator with your Analytics account.', 'google-analyticator'); ?></a></p>
  264. <?php } else { ?>
  265. <p style="margin-top: 7px;"><?php _e('Currently authenticated with Google.', 'google-analyticator'); ?> <a href="<?php echo admin_url('/options-general.php?page=google-analyticator.php&token=deauth'); ?>"><?php _e('Deauthorize Google Analyticator.', 'google-analyticator'); ?></a></p>
  266. <?php if ( isset($_GET['token']) && $_GET['token'] != 'deauth' ) { ?>
  267. <p style="color: red; display: none;" id="ga_connect_error"><?php _e('Failed to authenticate with Google. <a href="http://forums.ronaldheft.com/viewtopic.php?f=5&t=851">Read this support article</a> on Analyticator\'s support forums for help.', 'google-analyticator'); ?></p>
  268. <?php } ?>
  269. <?php } ?>
  270. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Clicking the above link will authenticate Google Analyticator with Google. Authentication with Google is needed for use with the stats widget. In addition, authenticating will enable you to select your Analytics account through a drop-down instead of searching for your UID. If you are not going to use the stat widget, <strong>authenticating with Google is optional</strong>.', 'google-analyticator'); ?></p>
  271. </td>
  272. </tr>
  273. <?php } ?>
  274. <tr id="ga_ajax_accounts">
  275. <th valign="top" style="padding-top: 10px;">
  276. <label for="<?php echo key_ga_uid; ?>"><?php _e('Google Analytics UID', 'google-analyticator'); ?>:</label>
  277. </th>
  278. <td>
  279. <?php
  280. echo "<input type='text' size='50' ";
  281. echo "name='".key_ga_uid."' ";
  282. echo "id='".key_ga_uid."' ";
  283. echo "value='".get_option(key_ga_uid)."' />\n";
  284. ?>
  285. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter your Google Analytics\' UID in this box (<a href="http://forums.ronaldheft.com/viewtopic.php?f=5&amp;t=6">where can I find my UID?</a>). The UID is needed for Google Analytics to log your website stats.', 'google-analyticator'); ?> <strong><?php if ( function_exists('register_widget') ) _e('If you are having trouble finding your UID, authenticate with Google in the above field. After returning from Google, you will be able to select your account through a drop-down box.', 'google-analyticator'); ?></strong></p>
  286. </td>
  287. </tr>
  288. </table>
  289. <h3><?php _e('Advanced Settings', 'google-analyticator'); ?></h3>
  290. <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
  291. <tr>
  292. <th width="30%" valign="top" style="padding-top: 10px;">
  293. <label for="<?php echo key_ga_admin ?>"><?php _e('Track all logged in WordPress users', 'google-analyticator'); ?>:</label>
  294. </th>
  295. <td>
  296. <?php
  297. echo "<select name='".key_ga_admin."' id='".key_ga_admin."'>\n";
  298. echo "<option value='".ga_enabled."'";
  299. if(get_option(key_ga_admin) == ga_enabled)
  300. echo " selected='selected'";
  301. echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
  302. echo "<option value='".ga_disabled."'";
  303. if(get_option(key_ga_admin) == ga_disabled)
  304. echo" selected='selected'";
  305. echo ">" . __('No', 'google-analyticator') . "</option>\n";
  306. echo "</select>\n";
  307. ?>
  308. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Selecting "no" to this option will prevent logged in WordPress users from showing up on your Google Analytics reports. This setting will prevent yourself or other users from showing up in your Analytics reports. Use the next setting to determine what user groups to exclude.', 'google-analyticator'); ?></p>
  309. </td>
  310. </tr>
  311. <tr>
  312. <th width="30%" valign="top" style="padding-top: 10px;">
  313. <label for="<?php echo key_ga_admin_role ?>"><?php _e('User roles to not track', 'google-analyticator'); ?>:</label>
  314. </th>
  315. <td>
  316. <?php
  317. global $wp_roles;
  318. $roles = $wp_roles->get_names();
  319. $selected_roles = get_option(key_ga_admin_role);
  320. if ( !is_array($selected_roles) ) $selected_roles = array();
  321. # Loop through the roles
  322. foreach ( $roles AS $role => $name ) {
  323. echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_admin_role . '[]"';
  324. if ( in_array($role, $selected_roles) )
  325. echo " checked='checked'";
  326. $name_pos = strpos($name, '|');
  327. $name = ( $name_pos ) ? substr($name, 0, $name_pos) : $name;
  328. echo ' /> ' . _x($name, 'User role') . '<br />';
  329. }
  330. ?>
  331. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Specifies the user roles to not include in your WordPress Analytics report. If a user is logged into WordPress with one of these roles, they will not show up in your Analytics report.', 'google-analyticator'); ?></p>
  332. </td>
  333. </tr>
  334. <tr>
  335. <th width="30%" valign="top" style="padding-top: 10px;">
  336. <label for="<?php echo key_ga_admin_disable ?>"><?php _e('Method to prevent tracking', 'google-analyticator'); ?>:</label>
  337. </th>
  338. <td>
  339. <?php
  340. echo "<select name='".key_ga_admin_disable."' id='".key_ga_admin_disable."'>\n";
  341. echo "<option value='remove'";
  342. if(get_option(key_ga_admin_disable) == 'remove')
  343. echo " selected='selected'";
  344. echo ">" . __('Remove', 'google-analyticator') . "</option>\n";
  345. echo "<option value='admin'";
  346. if(get_option(key_ga_admin_disable) == 'admin')
  347. echo" selected='selected'";
  348. echo ">" . __('Use \'admin\' variable', 'google-analyticator') . "</option>\n";
  349. echo "</select>\n";
  350. ?>
  351. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Selecting the "Remove" option will physically remove the tracking code from logged in users. Selecting the "Use \'admin\' variable" option will assign a variable called \'admin\' to logged in users. This option will allow Google Analytics\' site overlay feature to work, but you will have to manually configure Google Analytics to exclude tracking from pageviews with the \'admin\' variable.', 'google-analyticator'); ?></p>
  352. </td>
  353. </tr>
  354. <tr>
  355. <th width="30%" valign="top" style="padding-top: 10px;">
  356. <label for="<?php echo key_ga_sitespeed ?>"><?php _e('Site speed tracking', 'google-analyticator'); ?>:</label>
  357. </th>
  358. <td>
  359. <?php
  360. echo "<select name='".key_ga_sitespeed."' id='".key_ga_sitespeed."'>\n";
  361. echo "<option value='".ga_enabled."'";
  362. if(get_option(key_ga_sitespeed) == ga_enabled)
  363. echo " selected='selected'";
  364. echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
  365. echo "<option value='".ga_disabled."'";
  366. if(get_option(key_ga_sitespeed) == ga_disabled)
  367. echo" selected='selected'";
  368. echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
  369. echo "</select>\n";
  370. ?>
  371. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Disabling this option will turn off the tracking required for <a href="http://www.google.com/support/analyticshelp/bin/answer.py?hl=en&answer=1205784&topic=1120718&utm_source=gablog&utm_medium=blog&utm_campaign=newga-blog&utm_content=sitespeed">Google Analytics\' Site Speed tracking report</a>.', 'google-analyticator'); ?></p>
  372. </td>
  373. </tr>
  374. <tr>
  375. <th width="30%" valign="top" style="padding-top: 10px;">
  376. <label for="<?php echo key_ga_outbound ?>"><?php _e('Outbound link tracking', 'google-analyticator'); ?>:</label>
  377. </th>
  378. <td>
  379. <?php
  380. echo "<select name='".key_ga_outbound."' id='".key_ga_outbound."'>\n";
  381. echo "<option value='".ga_enabled."'";
  382. if(get_option(key_ga_outbound) == ga_enabled)
  383. echo " selected='selected'";
  384. echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
  385. echo "<option value='".ga_disabled."'";
  386. if(get_option(key_ga_outbound) == ga_disabled)
  387. echo" selected='selected'";
  388. echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
  389. echo "</select>\n";
  390. ?>
  391. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Disabling this option will turn off the tracking of outbound links. It\'s recommended not to disable this option unless you\'re a privacy advocate (now why would you be using Google Analytics in the first place?) or it\'s causing some kind of weird issue.', 'google-analyticator'); ?></p>
  392. </td>
  393. </tr>
  394. <tr>
  395. <th width="30%" valign="top" style="padding-top: 10px;">
  396. <label for="<?php echo key_ga_event ?>"><?php _e('Event tracking', 'google-analyticator'); ?>:</label>
  397. </th>
  398. <td>
  399. <?php
  400. echo "<select name='".key_ga_event."' id='".key_ga_event."'>\n";
  401. echo "<option value='".ga_enabled."'";
  402. if(get_option(key_ga_event) == ga_enabled)
  403. echo " selected='selected'";
  404. echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
  405. echo "<option value='".ga_disabled."'";
  406. if(get_option(key_ga_event) == ga_disabled)
  407. echo" selected='selected'";
  408. echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
  409. echo "</select>\n";
  410. ?>
  411. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enabling this option will treat outbound links and downloads as events instead of pageviews. Since the introduction of <a href="http://code.google.com/apis/analytics/docs/tracking/eventTrackerOverview.html">event tracking in Analytics</a>, this is the recommended way to track these types of actions. Only disable this option if you must use the old pageview tracking method.', 'google-analyticator'); ?></p>
  412. </td>
  413. </tr>
  414. <tr>
  415. <th valign="top" style="padding-top: 10px;">
  416. <label for="<?php echo key_ga_downloads; ?>"><?php _e('Download extensions to track', 'google-analyticator'); ?>:</label>
  417. </th>
  418. <td>
  419. <?php
  420. echo "<input type='text' size='50' ";
  421. echo "name='".key_ga_downloads."' ";
  422. echo "id='".key_ga_downloads."' ";
  423. echo "value='".stripslashes(get_option(key_ga_downloads))."' />\n";
  424. ?>
  425. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter any extensions of files you would like to be tracked as a download. For example to track all MP3s and PDFs enter <strong>mp3,pdf</strong>. <em>Outbound link tracking must be enabled for downloads to be tracked.</em>', 'google-analyticator'); ?></p>
  426. </td>
  427. </tr>
  428. <tr>
  429. <th valign="top" style="padding-top: 10px;">
  430. <label for="<?php echo key_ga_outbound_prefix; ?>"><?php _e('Prefix external links with', 'google-analyticator'); ?>:</label>
  431. </th>
  432. <td>
  433. <?php
  434. echo "<input type='text' size='50' ";
  435. echo "name='".key_ga_outbound_prefix."' ";
  436. echo "id='".key_ga_outbound_prefix."' ";
  437. echo "value='".stripslashes(get_option(key_ga_outbound_prefix))."' />\n";
  438. ?>
  439. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter a name for the section tracked external links will appear under. This option has no effect if event tracking is enabled.', 'google-analyticator'); ?></em></p>
  440. </td>
  441. </tr>
  442. <tr>
  443. <th valign="top" style="padding-top: 10px;">
  444. <label for="<?php echo key_ga_downloads_prefix; ?>"><?php _e('Prefix download links with', 'google-analyticator'); ?>:</label>
  445. </th>
  446. <td>
  447. <?php
  448. echo "<input type='text' size='50' ";
  449. echo "name='".key_ga_downloads_prefix."' ";
  450. echo "id='".key_ga_downloads_prefix."' ";
  451. echo "value='".stripslashes(get_option(key_ga_downloads_prefix))."' />\n";
  452. ?>
  453. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter a name for the section tracked download links will appear under. This option has no effect if event tracking is enabled.', 'google-analyticator'); ?></em></p>
  454. </td>
  455. </tr>
  456. <tr>
  457. <th valign="top" style="padding-top: 10px;">
  458. <label for="<?php echo key_ga_adsense; ?>"><?php _e('Google Adsense ID', 'google-analyticator'); ?>:</label>
  459. </th>
  460. <td>
  461. <?php
  462. echo "<input type='text' size='50' ";
  463. echo "name='".key_ga_adsense."' ";
  464. echo "id='".key_ga_adsense."' ";
  465. echo "value='".get_option(key_ga_adsense)."' />\n";
  466. ?>
  467. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter your Google Adsense ID assigned by Google Analytics in this box. This enables Analytics tracking of Adsense information if your Adsense and Analytics accounts are linked.', 'google-analyticator'); ?></p>
  468. </td>
  469. </tr>
  470. <tr>
  471. <th valign="top" style="padding-top: 10px;">
  472. <label for="<?php echo key_ga_extra; ?>"><?php _e('Additional tracking code', 'google-analyticator'); ?><br />(<?php _e('before tracker initialization', 'google-analyticator'); ?>):</label>
  473. </th>
  474. <td>
  475. <?php
  476. echo "<textarea cols='50' rows='8' ";
  477. echo "name='".key_ga_extra."' ";
  478. echo "id='".key_ga_extra."'>";
  479. echo stripslashes(get_option(key_ga_extra))."</textarea>\n";
  480. ?>
  481. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter any additional lines of tracking code that you would like to include in the Google Analytics tracking script. The code in this section will be displayed <strong>before</strong> the Google Analytics tracker is initialized. Read <a href="http://www.google.com/analytics/InstallingGATrackingCode.pdf">Google Analytics tracker manual</a> to learn what code goes here and how to use it.', 'google-analyticator'); ?></p>
  482. </td>
  483. </tr>
  484. <tr>
  485. <th valign="top" style="padding-top: 10px;">
  486. <label for="<?php echo key_ga_extra_after; ?>"><?php _e('Additional tracking code', 'google-analyticator'); ?><br />(<?php _e('after tracker initialization', 'google-analyticator'); ?>):</label>
  487. </th>
  488. <td>
  489. <?php
  490. echo "<textarea cols='50' rows='8' ";
  491. echo "name='".key_ga_extra_after."' ";
  492. echo "id='".key_ga_extra_after."'>";
  493. echo stripslashes(get_option(key_ga_extra_after))."</textarea>\n";
  494. ?>
  495. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter any additional lines of tracking code that you would like to include in the Google Analytics tracking script. The code in this section will be displayed <strong>after</strong> the Google Analytics tracker is initialized. Read <a href="http://www.google.com/analytics/InstallingGATrackingCode.pdf">Google Analytics tracker manual</a> to learn what code goes here and how to use it.', 'google-analyticator'); ?></p>
  496. </td>
  497. </tr>
  498. <?php
  499. # Check if we have a version of WordPress greater than 2.8
  500. if ( function_exists('register_widget') ) {
  501. ?>
  502. <tr>
  503. <th valign="top" style="padding-top: 10px;">
  504. <label for="ga_profileid"><?php _e('Google Analytics profile ID', 'google-analyticator'); ?>:</label>
  505. </th>
  506. <td>
  507. <?php
  508. echo "<input type='text' size='50' ";
  509. echo "name='ga_profileid' ";
  510. echo "id='ga_profileid' ";
  511. echo "value='".get_option('ga_profileid')."' />\n";
  512. ?>
  513. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter your Google Analytics\' profile ID in this box. Entering your profile ID is optional, and is only useful if you have multiple profiles associated with a single UID. By entering your profile ID, the dashboard widget will display stats based on the profile ID you specify.', 'google-analyticator'); ?></p>
  514. </td>
  515. </tr>
  516. <tr>
  517. <th width="30%" valign="top" style="padding-top: 10px;">
  518. <label for="<?php echo key_ga_dashboard_role ?>"><?php _e('User roles that can see the dashboard widget', 'google-analyticator'); ?>:</label>
  519. </th>
  520. <td>
  521. <?php
  522. global $wp_roles;
  523. $roles = $wp_roles->get_names();
  524. $selected_roles = get_option(key_ga_dashboard_role);
  525. if ( !is_array($selected_roles) ) $selected_roles = array();
  526. # Loop through the roles
  527. foreach ( $roles AS $role => $name ) {
  528. echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_dashboard_role . '[]"';
  529. if ( in_array($role, $selected_roles) )
  530. echo " checked='checked'";
  531. $name_pos = strpos($name, '|');
  532. $name = ( $name_pos ) ? substr($name, 0, $name_pos) : $name;
  533. echo ' /> ' . _x($name, 'User role') . '<br />';
  534. }
  535. ?>
  536. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Specifies the user roles that can see the dashboard widget. If a user is not in one of these role groups, they will not see the dashboard widget.', 'google-analyticator'); ?></p>
  537. </td>
  538. </tr>
  539. <tr>
  540. <th width="30%" valign="top" style="padding-top: 10px;">
  541. <label for="<?php echo key_ga_widgets; ?>"><?php _e('Include widgets', 'google-analyticator'); ?>:</label>
  542. </th>
  543. <td>
  544. <?php
  545. echo "<select name='".key_ga_widgets."' id='".key_ga_widgets."'>\n";
  546. echo "<option value='".ga_enabled."'";
  547. if(get_option(key_ga_widgets) == ga_enabled)
  548. echo " selected='selected'";
  549. echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
  550. echo "<option value='".ga_disabled."'";
  551. if(get_option(key_ga_widgets) == ga_disabled)
  552. echo" selected='selected'";
  553. echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
  554. echo "</select>\n";
  555. ?>
  556. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Disabling this option will completely remove the Dashboard Summary widget and the theme Stats widget. Use this option if you would prefer to not see the widgets.', 'google-analyticator'); ?></p>
  557. </td>
  558. </tr>
  559. <tr>
  560. <th width="30%" valign="top" style="padding-top: 10px;">
  561. <label for="ga_compatibility"><?php _e('Authentication compatibility', 'google-analyticator'); ?>:</label>
  562. </th>
  563. <td>
  564. <?php
  565. echo "<select name='ga_compatibility' id='ga_compatibility'>\n";
  566. echo "<option value='off'";
  567. if(get_option('ga_compatibility') == 'off')
  568. echo " selected='selected'";
  569. echo ">" . __('Off', 'google-analyticator') . "</option>\n";
  570. echo "<option value='level1'";
  571. if(get_option('ga_compatibility') == 'level1')
  572. echo " selected='selected'";
  573. echo ">" . __('Disable cURL', 'google-analyticator') . "</option>\n";
  574. echo "<option value='level2'";
  575. if(get_option('ga_compatibility') == 'level2')
  576. echo " selected='selected'";
  577. echo ">" . __('Disable cURL and PHP Streams', 'google-analyticator') . "</option>\n";
  578. echo "</select>\n";
  579. ?>
  580. <p style="margin: 5px 10px;" class="setting-description"><?php _e('If you\'re having trouble authenticating with Google for use with the stats widgets, try setting these compatibility modes. Try disabling cURL first and re-authenticate. If that fails, try disabling cURL and PHP Streams.', 'google-analyticator'); ?></p>
  581. </td>
  582. </tr>
  583. <?php } ?>
  584. </table>
  585. <p class="submit">
  586. <input type="submit" name="info_update" value="<?php _e('Save Changes', 'google-analyticator'); ?>" />
  587. </p>
  588. </div>
  589. </form>
  590. <?php
  591. }
  592. /**
  593. * Adds AJAX to the GA settings page
  594. **/
  595. function ga_admin_ajax()
  596. {
  597. if ( function_exists('register_widget') ) {
  598. # Only attempt to replace code if we're authenticated or attempting to authenticate
  599. if ( ( isset($_REQUEST['token']) && $_REQUEST['token'] != '' ) || ( trim(get_option('ga_google_token')) != '' ) ) {
  600. ?>
  601. <script type="text/javascript">
  602. jQuery(document).ready(function(){
  603. // Grab the widget data
  604. jQuery.ajax({
  605. type: 'post',
  606. url: 'admin-ajax.php',
  607. data: {
  608. action: 'ga_ajax_accounts',
  609. _ajax_nonce: '<?php echo wp_create_nonce("google-analyticator-accounts_get"); ?>'<?php if ( isset($_GET['token']) ) { ?>,
  610. token: '<?php echo esc_js($_GET["token"]); ?>'
  611. <?php } ?>
  612. },
  613. success: function(html) {
  614. if ( html != '' )
  615. jQuery('#ga_ajax_accounts').html(html);
  616. else
  617. jQuery('#ga_connect_error').show();
  618. }
  619. });
  620. });
  621. </script>
  622. <?php
  623. }
  624. }
  625. }
  626. # Look for the ajax list call
  627. add_action('wp_ajax_ga_ajax_accounts', 'ga_ajax_accounts');
  628. /**
  629. * An AJAX function to get a list of accounts in a drop down
  630. **/
  631. function ga_ajax_accounts()
  632. {
  633. # Check the ajax widget
  634. check_ajax_referer('google-analyticator-accounts_get');
  635. # Get the list of accounts if available
  636. $ga_accounts = ga_get_analytics_accounts();
  637. if ( $ga_accounts !== false ) {
  638. ?>
  639. <th valign="top" style="padding-top: 10px;">
  640. <label for="<?php echo key_ga_uid; ?>"><?php _e('Google Analytics account', 'google-analyticator'); ?>:</label>
  641. </th>
  642. <td>
  643. <?php
  644. // sort the $ga_accounts array by ga:accountName and then title
  645. $sorted_ga_accounts = array();
  646. foreach ($ga_accounts as $ga_account) {
  647. $sorted_ga_accounts[$ga_account['ga:accountName']][] = $ga_account;
  648. }
  649. foreach( $sorted_ga_accounts as $id => $sorted_ga_account) {
  650. usort($sorted_ga_accounts[$id], 'ga_sort_account_list');
  651. }
  652. # Create a select box
  653. echo '<select name="' . key_ga_uid . '" id="' . key_ga_uid . '">';
  654. echo '<option value="XX-XXXXX-X">' . __('Select an Account', 'google-analyticator') . '</option>';
  655. # The list of accounts
  656. foreach ( $sorted_ga_accounts AS $account_name => $account_list ) {
  657. echo "<optgroup label='".htmlentities($account_name)."'>\n";
  658. foreach( $account_list as $account) {
  659. $select = ( get_option(key_ga_uid) == $account['ga:webPropertyId'] ) ? ' selected="selected"' : '';
  660. echo '<option value="' . $account['ga:webPropertyId'] . '"' . $select . '>' . $account['title'] . '</option>';
  661. }
  662. echo "</optgroup>\n";
  663. }
  664. # Close the select box
  665. echo '</select>';
  666. ?>
  667. <p style="margin: 5px 10px;" class="setting-description"><?php _e('Select the Analytics account you wish to enable tracking for. An account must be selected for tracking to occur.', 'google-analyticator'); ?></p>
  668. </td>
  669. <?php
  670. }
  671. die();
  672. }
  673. function ga_sort_account_list($a, $b) {
  674. return strcmp($a['title'],$b['title']);
  675. }
  676. /**
  677. * Checks if the WordPress API is a valid method for selecting an account
  678. *
  679. * @return a list of accounts if available, false if none available
  680. **/
  681. function ga_get_analytics_accounts()
  682. {
  683. $accounts = array();
  684. # Get the class for interacting with the Google Analytics
  685. require_once('class.analytics.stats.php');
  686. # Create a new Gdata call
  687. if ( isset($_POST['token']) && $_POST['token'] != '' )
  688. $stats = new GoogleAnalyticsStats($_POST['token']);
  689. elseif ( trim(get_option('ga_google_token')) != '' )
  690. $stats = new GoogleAnalyticsStats();
  691. else
  692. return false;
  693. # Check if Google sucessfully logged in
  694. if ( ! $stats->checkLogin() )
  695. return false;
  696. # Get a list of accounts
  697. $accounts = $stats->getAnalyticsAccounts();
  698. # Return the account array if there are accounts
  699. if ( count($accounts) > 0 )
  700. return $accounts;
  701. else
  702. return false;
  703. }
  704. /**
  705. * Add http_build_query if it doesn't exist already
  706. **/
  707. if ( !function_exists('http_build_query') ) {
  708. function http_build_query($params, $key = null)
  709. {
  710. $ret = array();
  711. foreach( (array) $params as $name => $val ) {
  712. $name = urlencode($name);
  713. if ( $key !== null )
  714. $name = $key . "[" . $name . "]";
  715. if ( is_array($val) || is_object($val) )
  716. $ret[] = http_build_query($val, $name);
  717. elseif ($val !== null)
  718. $ret[] = $name . "=" . urlencode($val);
  719. }
  720. return implode("&", $ret);
  721. }
  722. }
  723. /**
  724. * Echos out the core Analytics tracking code
  725. **/
  726. function add_google_analytics()
  727. {
  728. # Fetch variables used in the tracking code
  729. $uid = stripslashes(get_option(key_ga_uid));
  730. $extra = stripslashes(get_option(key_ga_extra));
  731. $extra_after = stripslashes(get_option(key_ga_extra_after));
  732. $extensions = str_replace (",", "|", get_option(key_ga_downloads));
  733. # Determine if the GA is enabled and contains a valid UID
  734. if ( ( get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
  735. {
  736. # Determine if the user is an admin, and should see the tracking code
  737. if ( ( get_option(key_ga_admin) == ga_enabled || !ga_current_user_is(get_option(key_ga_admin_role)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
  738. {
  739. # Disable the tracking code on the post preview page
  740. if ( !function_exists("is_preview") || ( function_exists("is_preview") && !is_preview() ) )
  741. {
  742. # Add the notice that Google Analyticator tracking is enabled
  743. echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
  744. # Add the Adsense data if specified
  745. if ( get_option(key_ga_adsense) != '' )
  746. echo '<script type="text/javascript">window.google_analytics_uacct = "' . get_option(key_ga_adsense) . "\";</script>\n";
  747. # Include the file types to track
  748. $extensions = explode(',', stripslashes(get_option(key_ga_downloads)));
  749. $ext = "";
  750. foreach ( $extensions AS $extension )
  751. $ext .= "'$extension',";
  752. $ext = substr($ext, 0, -1);
  753. # Include the link tracking prefixes
  754. $outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix));
  755. $downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix));
  756. $event_tracking = get_option(key_ga_event);
  757. ?>
  758. <script type="text/javascript">
  759. var analyticsFileTypes = [<?php echo strtolower($ext); ?>];
  760. <?php if ( $event_tracking != 'enabled' ) { ?>
  761. var analyticsOutboundPrefix = '/<?php echo $outbound_prefix; ?>/';
  762. var analyticsDownloadsPrefix = '/<?php echo $downloads_prefix; ?>/';
  763. <?php } ?>
  764. var analyticsEventTracking = '<?php echo $event_tracking; ?>';
  765. </script>
  766. <?php
  767. # Add the first part of the core tracking code
  768. ?>
  769. <script type="text/javascript">
  770. var _gaq = _gaq || [];
  771. _gaq.push(['_setAccount', '<?php echo $uid; ?>']);
  772. <?php
  773. # Add any tracking code before the trackPageview
  774. do_action('google_analyticator_extra_js_before');
  775. if ( '' != $extra )
  776. echo " $extra\n";
  777. # Add the track pageview function
  778. echo " _gaq.push(['_trackPageview']);\n";
  779. # Add the site speed tracking
  780. if ( get_option(key_ga_sitespeed) == ga_enabled )
  781. echo " _gaq.push(['_trackPageLoadTime']);\n";
  782. # Disable page tracking if admin is logged in
  783. if ( ( get_option(key_ga_admin) == ga_disabled ) && ( ga_current_user_is(get_option(key_ga_admin_role)) ) )
  784. echo " _gaq.push(['_setCustomVar', 'admin']);\n";
  785. # Add any tracking code after the trackPageview
  786. do_action('google_analyticator_extra_js_after');
  787. if ( '' != $extra_after )
  788. echo " $extra_after\n";
  789. # Add the final section of the tracking code
  790. ?>
  791. (function() {
  792. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  793. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  794. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  795. })();
  796. </script>
  797. <?php
  798. }
  799. } else {
  800. # Add the notice that Google Analyticator tracking is enabled
  801. echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
  802. echo " <!-- " . __('Tracking code is hidden, since the settings specify not to track admins. Tracking is occurring for non-admins.', 'google-analyticator') . " -->\n";
  803. }
  804. }
  805. }
  806. /**
  807. * Adds outbound link tracking to Google Analyticator
  808. **/
  809. function ga_outgoing_links()
  810. {
  811. # Fetch the UID
  812. $uid = stripslashes(get_option(key_ga_uid));
  813. # If GA is enabled and has a valid key
  814. if ( (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
  815. {
  816. # If outbound tracking is enabled
  817. if ( get_option(key_ga_outbound) == ga_enabled )
  818. {
  819. # If this is not an admin page
  820. if ( !is_admin() )
  821. {
  822. # Display page tracking if user is not an admin
  823. if ( ( get_option(key_ga_admin) == ga_enabled || !ga_current_user_is(get_option(key_ga_admin_role)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
  824. {
  825. add_action('wp_print_scripts', 'ga_external_tracking_js');
  826. }
  827. }
  828. }
  829. }
  830. }
  831. /**
  832. * Adds the scripts required for outbound link tracking
  833. **/
  834. function ga_external_tracking_js()
  835. {
  836. wp_enqueue_script('ga-external-tracking', plugins_url('/google-analyticator/external-tracking.min.js'), array('jquery'), GOOGLE_ANALYTICATOR_VERSION);
  837. }
  838. /**
  839. * Determines if a specific user fits a role
  840. **/
  841. function ga_current_user_is($roles)
  842. {
  843. if ( !$roles ) return false;
  844. global $current_user;
  845. get_currentuserinfo();
  846. $user_id = intval( $current_user->ID );
  847. if ( !$user_id ) {
  848. return false;
  849. }
  850. $user = new WP_User($user_id); // $user->roles
  851. foreach ( $roles as $role )
  852. if ( in_array($role, $user->roles) ) return true;
  853. return false;
  854. }
  855. /**
  856. * EXPERIMENTAL: Retrieve Google's visits for the given page
  857. * More work needs to be done. Needs caching, needs to be less resource intensive, and
  858. * needs an automated way to determine the page.
  859. * Function may/will change in future releases. Only use if you know what you're doing.
  860. *
  861. * @param url - the page url, missing the domain information
  862. * @param days - the number of days to get
  863. * @return the number of visits
  864. **/
  865. function get_analytics_visits_by_page($page, $days = 31)
  866. {
  867. require_once('class.analytics.stats.php');
  868. # Create a new API object
  869. $api = new GoogleAnalyticsStats();
  870. # Get the current accounts accounts
  871. $accounts = ga_get_analytics_accounts();
  872. # Verify accounts exist
  873. if ( count($accounts) <= 0 )
  874. return 0;
  875. # Loop throught the account and return the current account
  876. foreach ( $accounts AS $account )
  877. {
  878. # Check if the UID matches the selected UID
  879. if ( $account['ga:webPropertyId'] == get_option('ga_uid') )
  880. {
  881. $api->setAccount($account['id']);
  882. break;
  883. }
  884. }
  885. # Encode the page url
  886. $page = urlencode($page);
  887. # Get the metric information from Google
  888. $before = date('Y-m-d', strtotime('-' . $days . ' days'));
  889. $yesterday = date('Y-m-d', strtotime('-1 day'));
  890. $stats = $api->getMetrics('ga:visits', $before, $yesterday, 'ga:pagePath', false, 'ga:pagePath%3D%3D' . $page, 1);
  891. # Check the size of the stats array
  892. if ( count($stats) <= 0 || !is_array($stats) ) {
  893. return 0;
  894. } else {
  895. # Loop through each stat for display
  896. foreach ( $stats AS $stat ) {
  897. return $stat['ga:visits'];
  898. }
  899. }
  900. }
  901. ?>