public function tracking_code() { if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_track_exclude'], true) || $this->gadwp->config->options['ga_dash_excludesa'] && current_user_can('manage_network')) { return; } $traking_mode = $this->gadwp->config->options['ga_dash_tracking']; $traking_type = $this->gadwp->config->options['ga_dash_tracking_type']; if ($traking_mode > 0) { if (!$this->gadwp->config->options['ga_dash_tableid_jail']) { return; } if ($traking_type == "classic") { echo "\n<!-- BEGIN GADWP v" . GADWP_CURRENT_VERSION . " Classic Tracking - https://deconf.com/google-analytics-dashboard-wordpress/ -->\n"; if ($this->gadwp->config->options['ga_event_tracking']) { require_once 'tracking/events-classic.php'; } require_once 'tracking/code-classic.php'; echo "\n<!-- END GADWP Classic Tracking -->\n\n"; } else { echo "\n<!-- BEGIN GADWP v" . GADWP_CURRENT_VERSION . " Universal Tracking - https://deconf.com/google-analytics-dashboard-wordpress/ -->\n"; if ($this->gadwp->config->options['ga_event_tracking'] || $this->gadwp->config->options['ga_aff_tracking'] || $this->gadwp->config->options['ga_hash_tracking']) { require_once 'tracking/events-universal.php'; } require_once 'tracking/code-universal.php'; echo "\n<!-- END GADWP Universal Tracking -->\n\n"; } } }
public function __construct() { $this->gadwp = GADWP(); if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && 1 == $this->gadwp->config->options['dashboard_widget']) { add_action('wp_dashboard_setup', array($this, 'add_widget')); } }
/** * Styles & Scripts conditional loading * * @param * $hook */ public function load_styles_scripts() { $lang = get_bloginfo('language'); $lang = explode('-', $lang); $lang = $lang[0]; /* * Item reports Styles & Scripts */ if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_front']) && $this->gadwp->config->options['frontend_item_reports']) { wp_enqueue_style('gadwp-nprogress', GADWP_URL . 'common/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION); wp_enqueue_style('gadwp-frontend-item-reports', GADWP_URL . 'front/css/item-reports.css', null, GADWP_CURRENT_VERSION); $country_codes = GADWP_Tools::get_countrycodes(); if ($this->gadwp->config->options['ga_target_geomap'] && isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) { $region = $this->gadwp->config->options['ga_target_geomap']; } else { $region = false; } wp_enqueue_style("wp-jquery-ui-dialog"); if (!wp_script_is('googlejsapi')) { wp_register_script('googlejsapi', 'https://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22language%22%3A%22' . $lang . '%22%2C%22packages%22%3A%5B%22corechart%22%2C%20%22table%22%2C%20%22orgchart%22%2C%20%22geochart%22%5D%7D%5D%7D%27', array(), null); } wp_enqueue_script('gadwp-nprogress', GADWP_URL . 'common/nprogress/nprogress.js', array('jquery'), GADWP_CURRENT_VERSION); wp_enqueue_script('gadwp-frontend-item-reports', GADWP_URL . 'common/js/reports.js', array('gadwp-nprogress', 'googlejsapi', 'jquery', 'jquery-ui-dialog'), GADWP_CURRENT_VERSION); /* @formatter:off */ wp_localize_script('gadwp-frontend-item-reports', 'gadwpItemData', array('ajaxurl' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('gadwp_frontend_item_reports'), 'dateList' => array('today' => __("Today", 'google-analytics-dashboard-for-wp'), 'yesterday' => __("Yesterday", 'google-analytics-dashboard-for-wp'), '7daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 7), '14daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 14), '30daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 30), '90daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 90), '365daysAgo' => sprintf(_n("%s Year", "%s Years", 1, 'google-analytics-dashboard-for-wp'), __('One', 'google-analytics-dashboard-for-wp')), '1095daysAgo' => sprintf(_n("%s Year", "%s Years", 3, 'google-analytics-dashboard-for-wp'), __('Three', 'google-analytics-dashboard-for-wp'))), 'reportList' => array('uniquePageviews' => __("Unique Views", 'google-analytics-dashboard-for-wp'), 'users' => __("Users", 'google-analytics-dashboard-for-wp'), 'organicSearches' => __("Organic", 'google-analytics-dashboard-for-wp'), 'pageviews' => __("Page Views", 'google-analytics-dashboard-for-wp'), 'visitBounceRate' => __("Bounce Rate", 'google-analytics-dashboard-for-wp'), 'locations' => __("Location", 'google-analytics-dashboard-for-wp'), 'referrers' => __("Referrers", 'google-analytics-dashboard-for-wp'), 'searches' => __("Searches", 'google-analytics-dashboard-for-wp'), 'trafficdetails' => __("Traffic", 'google-analytics-dashboard-for-wp'), 'technologydetails' => __("Technology", 'google-analytics-dashboard-for-wp')), 'i18n' => array(__("A JavaScript Error is blocking plugin resources!", 'google-analytics-dashboard-for-wp'), __("Traffic Mediums", 'google-analytics-dashboard-for-wp'), __("Visitor Type", 'google-analytics-dashboard-for-wp'), __("Search Engines", 'google-analytics-dashboard-for-wp'), __("Social Networks", 'google-analytics-dashboard-for-wp'), __("Unique Views", 'google-analytics-dashboard-for-wp'), __("Users", 'google-analytics-dashboard-for-wp'), __("Page Views", 'google-analytics-dashboard-for-wp'), __("Bounce Rate", 'google-analytics-dashboard-for-wp'), __("Organic Search", 'google-analytics-dashboard-for-wp'), __("Pages/Session", 'google-analytics-dashboard-for-wp'), __("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'), __("Not enough data collected", 'google-analytics-dashboard-for-wp'), __("This report is unavailable", 'google-analytics-dashboard-for-wp'), __("report generated by", 'google-analytics-dashboard-for-wp'), __("This plugin needs an authorization:", 'google-analytics-dashboard-for-wp') . ' <strong>' . __("authorize the plugin", 'google-analytics-dashboard-for-wp') . '</strong>!', __("Browser", 'google-analytics-dashboard-for-wp'), __("Operating System", 'google-analytics-dashboard-for-wp'), __("Screen Resolution", 'google-analytics-dashboard-for-wp'), __("Mobile Brand", 'google-analytics-dashboard-for-wp')), 'colorVariations' => GADWP_Tools::variations($this->gadwp->config->options['ga_dash_style']), 'region' => $region, 'language' => get_bloginfo('language'), 'filter' => $_SERVER["REQUEST_URI"], 'viewList' => false, 'scope' => 'front-item')); /* @formatter:on */ } }
/** * Styles & Scripts conditional loading * * @param * $hook */ public function load_styles_scripts() { /* * GADWP main stylesheet */ wp_enqueue_style('ga_dash-front', GADWP_URL . 'front/css/item-reports.css', null, GADWP_CURRENT_VERSION); /* * Item reports Styles & Scripts */ if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_front']) && $this->gadwp->config->options['frontend_item_reports']) { wp_enqueue_style('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION); wp_enqueue_style('gadwp_frontend_item_reports', GADWP_URL . 'front/css/item-reports.css', null, GADWP_CURRENT_VERSION); $country_codes = GADWP_Tools::get_countrycodes(); if ($this->gadwp->config->options['ga_target_geomap'] && isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) { $region = $this->gadwp->config->options['ga_target_geomap']; } else { $region = false; } wp_enqueue_style("wp-jquery-ui-dialog"); if (!wp_script_is('googlejsapi')) { wp_register_script('googlejsapi', 'https://www.google.com/jsapi'); } wp_enqueue_script('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.js', array('jquery'), GADWP_CURRENT_VERSION); wp_enqueue_script('gadwp_frontend_item_reports', plugins_url('js/item-reports.js', __FILE__), array('gadwp-nprogress', 'googlejsapi', 'jquery', 'jquery-ui-dialog'), GADWP_CURRENT_VERSION); /* @formatter:off */ wp_localize_script('gadwp_frontend_item_reports', 'gadwp_item_data', array('ajaxurl' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('gadwp_frontend_item_reports'), 'dateList' => array('today' => __("Today", 'ga-dash'), 'yesterday' => __("Yesterday", 'ga-dash'), '7daysAgo' => __("Last 7 Days", 'ga-dash'), '30daysAgo' => __("Last 30 Days", 'ga-dash'), '90daysAgo' => __("Last 90 Days", 'ga-dash')), 'reportList' => array('uniquePageviews' => __("Unique Views", 'ga-dash'), 'users' => __("Users", 'ga-dash'), 'organicSearches' => __("Organic", 'ga-dash'), 'pageviews' => __("Page Views", 'ga-dash'), 'visitBounceRate' => __("Bounce Rate", 'ga-dash'), 'locations' => __("Location", 'ga-dash'), 'referrers' => __("Referrers", 'ga-dash'), 'searches' => __("Searches", 'ga-dash'), 'trafficdetails' => __("Traffic Details", 'ga-dash')), 'i18n' => array(__("A JavaScript Error is blocking plugin resources!", 'ga-dash'), __("Traffic Mediums", 'ga-dash'), __("Visitor Type", 'ga-dash'), __("Social Networks", 'ga-dash'), __("Search Engines", 'ga-dash'), __("Unique Views", 'ga-dash'), __("Users", 'ga-dash'), __("Page Views", 'ga-dash'), __("Bounce Rate", 'ga-dash'), __("Organic Search", 'ga-dash'), __("Pages/Session", 'ga-dash'), __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'), __("Not enough data collected", 'ga-dash'), __("This report is unavailable", 'ga-dash'), __("report generated by", 'ga-dash')), 'colorVariations' => GADWP_Tools::variations($this->gadwp->config->options['ga_dash_style']), 'region' => $region)); /* @formatter:on */ } }
/** * Ajax handler for storing JavaScript Errors * * @return json|int */ public function ajax_set_error() { if (!isset($_POST['gadwp_security_set_error']) || !(wp_verify_nonce($_POST['gadwp_security_set_error'], 'gadwp_backend_item_reports') || wp_verify_nonce($_POST['gadwp_security_set_error'], 'gadwp_frontend_item_reports'))) { wp_die(-40); } GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($_POST['response']), 24 * 60 * 60); wp_die(); }
function custom_adminbar_node($wp_admin_bar) { if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_front']) && $this->gadwp->config->options['frontend_item_reports']) { /* @formatter:off */ $args = array('id' => 'gadwp-1', 'title' => '<span class="ab-icon"></span><span class="">' . __("Analytics", 'ga-dash') . '</span>', 'href' => '#1'); /* @formatter:on */ $wp_admin_bar->add_node($args); } }
/** * Ajax handler for Item Reports * * @return json|int */ public function ajax_item_reports() { if (!isset($_REQUEST['gadwp_security_backend_item_reports']) || !wp_verify_nonce($_REQUEST['gadwp_security_backend_item_reports'], 'gadwp_backend_item_reports')) { wp_die(-30); } $from = $_REQUEST['from']; $to = $_REQUEST['to']; $query = $_REQUEST['query']; if (isset($_REQUEST['filter'])) { $filter_id = $_REQUEST['filter']; } else { $filter_id = false; } if (ob_get_length()) { ob_clean(); } if (!GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) || 0 == $this->gadwp->config->options['backend_item_reports']) { wp_die(-31); } if ($this->gadwp->config->options['ga_dash_token'] && $this->gadwp->config->options['ga_dash_tableid_jail'] && $from && $to) { if (null === $this->gadwp->gapi_controller) { $this->gadwp->gapi_controller = new GADWP_GAPI_Controller(); } } else { wp_die(-24); } $projectId = $this->gadwp->config->options['ga_dash_tableid_jail']; $profile_info = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $projectId); if (isset($profile_info[4])) { $this->gadwp->gapi_controller->timeshift = $profile_info[4]; } else { $this->gadwp->gapi_controller->timeshift = (int) current_time('timestamp') - time(); } if ($filter_id) { $uri_parts = explode('/', get_permalink($filter_id), 4); if (isset($uri_parts[3])) { $uri = '/' . $uri_parts[3]; } else { wp_die(-25); } // allow URL correction before sending an API request $filter = apply_filters('gadwp_backenditem_uri', $uri); $lastchar = substr($filter, -1); if (isset($profile_info[6]) && $profile_info[6] && $lastchar == '/') { $filter = $filter . $profile_info[6]; } // Encode URL $filter = rawurlencode(rawurldecode($filter)); } $queries = explode(',', $query); $results = array(); foreach ($queries as $value) { $results[] = $this->gadwp->gapi_controller->get($projectId, $value, $from, $to, $filter); } wp_send_json($results); }
public function __construct() { $this->gadwp = GADWP(); if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && 1 == $this->gadwp->config->options['backend_item_reports']) { // Add custom column in Posts List add_filter('manage_posts_columns', array($this, 'add_columns')); // Populate custom column in Posts List add_action('manage_posts_custom_column', array($this, 'add_icons'), 10, 2); // Add custom column in Pages List add_filter('manage_pages_columns', array($this, 'add_columns')); // Populate custom column in Pages List add_action('manage_pages_custom_column', array($this, 'add_icons'), 10, 2); } }
public static function uninstall() { global $wpdb; if (is_multisite()) { // Cleanup Network install foreach (wp_get_sites(array('limit' => apply_filters('gadwp_sites_limit', 100))) as $blog) { switch_to_blog($blog['blog_id']); $sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'gadwp_cache_%%'"); delete_option('gadash_options'); restore_current_blog(); } delete_site_option('gadash_network_options'); } else { // Cleanup Single install $sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'gadwp_cache_%%'"); delete_option('gadash_options'); } GADWP_Tools::unset_cookie('default_metric'); GADWP_Tools::unset_cookie('default_dimension'); GADWP_Tools::unset_cookie('default_view'); }
/** * Analytics data for backend reports (Real-Time) * * @param * $projectId * @return array|int */ private function get_realtime($projectId) { $metrics = 'rt:activeUsers'; $dimensions = 'rt:pagePath,rt:source,rt:keyword,rt:trafficType,rt:visitorType,rt:pageTitle'; try { $serial = 'qr_realtimecache_' . $this->get_serial($projectId); $transient = GADWP_Tools::get_cache($serial); if ($transient === false) { if ($this->gapi_errors_handler()) { return -23; } $data = $this->service->data_realtime->get('ga:' . $projectId, $metrics, array('dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId)); GADWP_Tools::set_cache($serial, $data, 55); $this->gadwp->config->options['api_backoff'] = 0; $this->gadwp->config->set_plugin_options(); } else { $data = $transient; } } catch (Google_Service_Exception $e) { GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout); GADWP_Tools::set_cache('gapi_errors', array($e->getCode(), (array) $e->getErrors()), $this->error_timeout); return $e->getCode(); } catch (Exception $e) { GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout); return $e->getCode(); } if ($data->getRows() < 1) { return -21; } $i = 0; $gadwp_data = $data; foreach ($data->getRows() as $row) { $gadwp_data->rows[$i] = array_map('esc_html', $row); $i++; } return $gadwp_data; }
public function dashboard_widget() { if (empty($this->gadwp->config->options['ga_dash_token'])) { echo '<p>' . __("This plugin needs an authorization:", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Authorize Plugin", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>'; return; } if (current_user_can('manage_options')) { if (isset($_REQUEST['gadwp_selected_profile'])) { $this->gadwp->config->options['ga_dash_tableid'] = $_REQUEST['gadwp_selected_profile']; } $profiles = $this->gadwp->config->options['ga_dash_profile_list']; $profile_switch = ''; if (!empty($profiles)) { if (!$this->gadwp->config->options['ga_dash_tableid']) { if ($this->gadwp->config->options['ga_dash_tableid_jail']) { $this->gadwp->config->options['ga_dash_tableid'] = $this->gadwp->config->options['ga_dash_tableid_jail']; } else { $this->gadwp->config->options['ga_dash_tableid'] = GADWP_Tools::guess_default_domain($profiles); } } else { if ($this->gadwp->config->options['switch_profile'] == 0 && $this->gadwp->config->options['ga_dash_tableid_jail']) { $this->gadwp->config->options['ga_dash_tableid'] = $this->gadwp->config->options['ga_dash_tableid_jail']; } } $profile_switch .= '<select id="gadwp_selected_profile" name="gadwp_selected_profile" onchange="this.form.submit()">'; foreach ($profiles as $profile) { if (!$this->gadwp->config->options['ga_dash_tableid']) { $this->gadwp->config->options['ga_dash_tableid'] = $profile[1]; } if (isset($profile[3])) { $profile_switch .= '<option value="' . esc_attr($profile[1]) . '" '; $profile_switch .= selected($profile[1], $this->gadwp->config->options['ga_dash_tableid'], false); $profile_switch .= ' title="' . __("View Name:", 'google-analytics-dashboard-for-wp') . ' ' . esc_attr($profile[0]) . '">' . esc_attr(GADWP_Tools::strip_protocol($profile[3])) . '</option>'; } } $profile_switch .= "</select>"; } else { echo '<p>' . __("Something went wrong while retrieving profiles list.", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("More details", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>'; return; } } $this->gadwp->config->set_plugin_options(); if (current_user_can('manage_options')) { if ($this->gadwp->config->options['switch_profile'] == 0) { if ($this->gadwp->config->options['ga_dash_tableid_jail']) { $projectId = $this->gadwp->config->options['ga_dash_tableid_jail']; } else { echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>'; return; } } else { echo $profile_switch; $projectId = $this->gadwp->config->options['ga_dash_tableid']; } } else { if ($this->gadwp->config->options['ga_dash_tableid_jail']) { $projectId = $this->gadwp->config->options['ga_dash_tableid_jail']; } else { echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>'; return; } } if (!$projectId) { echo '<p>' . __("Something went wrong while retrieving property data. You need to create and properly configure a Google Analytics account:", 'google-analytics-dashboard-for-wp') . '</p> <form action="https://deconf.com/how-to-set-up-google-analytics-on-your-website/" method="POST">' . get_submit_button(__("Find out more!", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>'; return; } ?> <div id="gadwp-window-1"></div> <?php }
/** * Analytics data for backend reports (location reports) * * @param * $projectId * @param * $from * @param * $to * @return array|int */ public function get_locations($projectId, $from, $to, $filter = '') { $metrics = 'ga:sessions'; $options = ""; $title = __("Countries", 'ga-dash'); $serial = 'gadash_qr7_' . $this->get_serial($projectId . $from . $filter); $dimensions = 'ga:country'; $local_filter = ''; if ($this->gadwp->config->options['ga_target_geomap']) { $dimensions = 'ga:city, ga:region'; $country_codes = GADWP_Tools::get_countrycodes(); if (isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) { $local_filter = 'ga:country==' . $country_codes[$this->gadwp->config->options['ga_target_geomap']]; $title = __("Cities from", 'ga-dash') . ' ' . __($country_codes[$this->gadwp->config->options['ga_target_geomap']]); $serial = 'gadash_qr7_' . $this->get_serial($projectId . $from . $this->gadwp->config->options['ga_target_geomap'] . $filter); } } $options = array('dimensions' => $dimensions, 'sort' => '-ga:sessions', 'quotaUser' => $this->managequota . 'p' . $projectId); if ($filter) { $options['filters'] = 'ga:pagePath==' . $filter; if ($local_filter) { $options['filters'] .= ';' . $local_filter; } } else { if ($local_filter) { $options['filters'] = $local_filter; } } $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial); if (is_numeric($data)) { return $data; } $ga_dash_data = array(array($title, __("Sessions", 'ga-dash'))); foreach ($data->getRows() as $row) { if (isset($row[2])) { $ga_dash_data[] = array(esc_html($row[0]) . ', ' . esc_html($row[1]), (int) $row[2]); } else { $ga_dash_data[] = array(esc_html($row[0]), (int) $row[1]); } } return $ga_dash_data; }
/** * Styles & Scripts conditional loading (based on current URI) * * @param * $hook */ public function load_styles_scripts($hook) { /* * GADWP main stylesheet */ wp_enqueue_style('gadwp', GADWP_URL . 'admin/css/gadwp.css', null, GADWP_CURRENT_VERSION); /* * Dashboard Widgets Styles & Scripts */ $widgets_hooks = array('index.php'); if (in_array($hook, $widgets_hooks)) { if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && $this->gadwp->config->options['dashboard_widget']) { wp_enqueue_style('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION); wp_enqueue_script('gadwp-admin-widgets', plugins_url('js/widgets.js', __FILE__), array('jquery'), GADWP_CURRENT_VERSION); if (!wp_script_is('googlejsapi')) { wp_register_script('googlejsapi', 'https://www.google.com/jsapi'); wp_enqueue_script('googlejsapi'); } wp_enqueue_script('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.js', array('jquery'), GADWP_CURRENT_VERSION); } } /* * Posts/Pages List Styles & Scripts */ $contentstats_hooks = array('edit.php'); if (in_array($hook, $contentstats_hooks)) { if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && $this->gadwp->config->options['item_reports']) { wp_enqueue_style('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION); wp_enqueue_style('gadwp_itemreports', GADWP_URL . 'admin/css/item-reports.css', null, GADWP_CURRENT_VERSION); $country_codes = GADWP_Tools::get_countrycodes(); if ($this->gadwp->config->options['ga_target_geomap'] && isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) { $region = $this->gadwp->config->options['ga_target_geomap']; } else { $region = false; } wp_enqueue_style("wp-jquery-ui-dialog"); if (!wp_script_is('googlejsapi')) { wp_register_script('googlejsapi', 'https://www.google.com/jsapi'); } wp_enqueue_script('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.js', array('jquery'), GADWP_CURRENT_VERSION); wp_enqueue_script('gadwp_itemreports', plugins_url('js/item-reports.js', __FILE__), array('gadwp-nprogress', 'googlejsapi', 'jquery', 'jquery-ui-dialog'), GADWP_CURRENT_VERSION); wp_localize_script('gadwp_itemreports', 'gadwp_item_data', array('ajaxurl' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('gadwp_get_itemreports'), 'dateList' => array('today' => __("Today", 'ga-dash'), 'yesterday' => __("Yesterday", 'ga-dash'), '7daysAgo' => __("Last 7 Days", 'ga-dash'), '30daysAgo' => __("Last 30 Days", 'ga-dash'), '90daysAgo' => __("Last 90 Days", 'ga-dash')), 'reportList' => array('uniquePageviews' => __("Unique Views", 'ga-dash'), 'users' => __("Users", 'ga-dash'), 'organicSearches' => __("Organic", 'ga-dash'), 'pageviews' => __("Page Views", 'ga-dash'), 'visitBounceRate' => __("Bounce Rate", 'ga-dash'), 'locations' => __("Location", 'ga-dash'), 'referrers' => __("Referrers", 'ga-dash'), 'searches' => __("Searches", 'ga-dash'), 'trafficdetails' => __("Traffic Details", 'ga-dash')), 'i18n' => array(__("A JavaScript Error is blocking plugin resources!", 'ga-dash'), __("Traffic Mediums", 'ga-dash'), __("Visitor Type", 'ga-dash'), __("Social Networks", 'ga-dash'), __("Search Engines", 'ga-dash'), __("Unique Views", 'ga-dash'), __("Users", 'ga-dash'), __("Page Views", 'ga-dash'), __("Bounce Rate", 'ga-dash'), __("Organic Search", 'ga-dash'), __("Pages/Session", 'ga-dash'), __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'), __("Not enough data collected", 'ga-dash'), __("This report is unavailable", 'ga-dash'), __("report generated by", 'ga-dash')), 'colorVariations' => GADWP_Tools::variations($this->gadwp->config->options['ga_dash_style']), 'region' => $region)); } } /* * Settings Styles & Scripts */ $settings_hooks = array('toplevel_page_gadash_settings', 'google-analytics_page_gadash_backend_settings', 'google-analytics_page_gadash_frontend_settings', 'google-analytics_page_gadash_tracking_settings', 'google-analytics_page_gadash_errors_debugging'); if (in_array($hook, $settings_hooks)) { wp_enqueue_style('wp-color-picker'); wp_enqueue_script('wp-color-picker'); wp_enqueue_script('wp-color-picker-script-handle', plugins_url('js/wp-color-picker-script.js', __FILE__), array('wp-color-picker'), false, true); wp_enqueue_script('gadwp-settings', plugins_url('js/settings.js', __FILE__), array('jquery'), GADWP_CURRENT_VERSION); } }
public function dashboard_widget() { if (empty($this->gadwp->config->options['ga_dash_token'])) { echo '<p>' . __("This plugin needs an authorization:", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Authorize Plugin", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>'; return; } if (current_user_can('manage_options')) { if (isset($_REQUEST['gadwp_selected_profile'])) { $this->gadwp->config->options['ga_dash_tableid'] = $_REQUEST['gadwp_selected_profile']; } $profiles = $this->gadwp->config->options['ga_dash_profile_list']; $profile_switch = ''; if (!empty($profiles)) { if (!$this->gadwp->config->options['ga_dash_tableid']) { if ($this->gadwp->config->options['ga_dash_tableid_jail']) { $this->gadwp->config->options['ga_dash_tableid'] = $this->gadwp->config->options['ga_dash_tableid_jail']; } else { $this->gadwp->config->options['ga_dash_tableid'] = GADWP_Tools::guess_default_domain($profiles); } } else { if ($this->gadwp->config->options['switch_profile'] == 0 && $this->gadwp->config->options['ga_dash_tableid_jail']) { $this->gadwp->config->options['ga_dash_tableid'] = $this->gadwp->config->options['ga_dash_tableid_jail']; } } $profile_switch .= '<select id="gadwp_selected_profile" name="gadwp_selected_profile" onchange="this.form.submit()">'; foreach ($profiles as $profile) { if (!$this->gadwp->config->options['ga_dash_tableid']) { $this->gadwp->config->options['ga_dash_tableid'] = $profile[1]; } if (isset($profile[3])) { $profile_switch .= '<option value="' . esc_attr($profile[1]) . '" '; $profile_switch .= selected($profile[1], $this->gadwp->config->options['ga_dash_tableid'], false); $profile_switch .= ' title="' . __("View Name:", 'google-analytics-dashboard-for-wp') . ' ' . esc_attr($profile[0]) . '">' . esc_attr(GADWP_Tools::strip_protocol($profile[3])) . '</option>'; } } $profile_switch .= "</select>"; } else { echo '<p>' . __("Something went wrong while retrieving profiles list.", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("More details", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>'; return; } } $this->gadwp->config->set_plugin_options(); ?> <form id="ga-dash" method="POST"> <?php if (current_user_can('manage_options')) { if ($this->gadwp->config->options['switch_profile'] == 0) { if ($this->gadwp->config->options['ga_dash_tableid_jail']) { $projectId = $this->gadwp->config->options['ga_dash_tableid_jail']; } else { echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>'; return; } } else { echo $profile_switch; $projectId = $this->gadwp->config->options['ga_dash_tableid']; } } else { if ($this->gadwp->config->options['ga_dash_tableid_jail']) { $projectId = $this->gadwp->config->options['ga_dash_tableid_jail']; } else { echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>'; return; } } if (!$projectId) { echo '<p>' . __("Something went wrong while retrieving property data. You need to create and properly configure a Google Analytics account:", 'google-analytics-dashboard-for-wp') . '</p> <form action="https://deconf.com/how-to-set-up-google-analytics-on-your-website/" method="POST">' . get_submit_button(__("Find out more!", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>'; return; } if (isset($_REQUEST['gadwpquery'])) { $query = $_REQUEST['gadwpquery']; } else { $default_metric = GADWP_Tools::get_cookie('default_metric'); $query = $default_metric ? $default_metric : 'sessions'; } if (isset($_REQUEST['gadwpperiod'])) { $period = $_REQUEST['gadwpperiod']; } else { $default_dimension = GADWP_Tools::get_cookie('default_dimension'); $period = $default_dimension ? $default_dimension : '30daysAgo'; } ?> <select id="ga_dash_period" name="gadwpperiod" onchange="this.form.submit()"> <option value="realtime" <?php selected("realtime", $period, true); ?> ><?php _e("Real-Time", 'google-analytics-dashboard-for-wp'); ?> </option> <option value="today" <?php selected("today", $period, true); ?> ><?php _e("Today", 'google-analytics-dashboard-for-wp'); ?> </option> <option value="yesterday" <?php selected("yesterday", $period, true); ?> ><?php _e("Yesterday", 'google-analytics-dashboard-for-wp'); ?> </option> <option value="7daysAgo" <?php selected("7daysAgo", $period, true); ?> ><?php printf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 7); ?> </option> <option value="14daysAgo" <?php selected("14daysAgo", $period, true); ?> ><?php printf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 14); ?> </option> <option value="30daysAgo" <?php selected("30daysAgo", $period, true); ?> ><?php printf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 30); ?> </option> <option value="90daysAgo" <?php selected("90daysAgo", $period, true); ?> ><?php printf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 90); ?> </option> <option value="365daysAgo" <?php selected("365daysAgo", $period, true); ?> ><?php printf(_n("%s Year", "%s Years", 1, 'google-analytics-dashboard-for-wp'), __('One', 'google-analytics-dashboard-for-wp')); ?> </option> <option value="1095daysAgo" <?php selected("1095daysAgo", $period, true); ?> ><?php printf(_n("%s Year", "%s Years", 3, 'google-analytics-dashboard-for-wp'), __('Three', 'google-analytics-dashboard-for-wp')); ?> </option> </select> <?php if ($period != 'realtime') { ?> <select id="ga_dash_query" name="gadwpquery" onchange="this.form.submit()"> <option value="sessions" <?php selected("sessions", $query, true); ?> ><?php _e("Sessions", 'google-analytics-dashboard-for-wp'); ?> </option> <option value="users" <?php selected("users", $query, true); ?> ><?php _e("Users", 'google-analytics-dashboard-for-wp'); ?> </option> <option value="organicSearches" <?php selected("organicSearches", $query, true); ?> ><?php _e("Organic", 'google-analytics-dashboard-for-wp'); ?> </option> <option value="pageviews" <?php selected("pageviews", $query, true); ?> ><?php _e("Page Views", 'google-analytics-dashboard-for-wp'); ?> </option> <option value="visitBounceRate" <?php selected("visitBounceRate", $query, true); ?> ><?php _e("Bounce Rate", 'google-analytics-dashboard-for-wp'); ?> </option> <option value="locations" <?php selected("locations", $query, true); ?> ><?php _e("Location", 'google-analytics-dashboard-for-wp'); ?> </option> <option value="contentpages" <?php selected("contentpages", $query, true); ?> ><?php _e("Pages", 'google-analytics-dashboard-for-wp'); ?> </option> <option value="referrers" <?php selected("referrers", $query, true); ?> ><?php _e("Referrers", 'google-analytics-dashboard-for-wp'); ?> </option> <option value="searches" <?php selected("searches", $query, true); ?> ><?php _e("Searches", 'google-analytics-dashboard-for-wp'); ?> </option> <option value="trafficdetails" <?php selected("trafficdetails", $query, true); ?> ><?php _e("Traffic Details", 'google-analytics-dashboard-for-wp'); ?> </option> </select> <?php } ?> </form> <div id="gadash-progressbar"></div> <?php switch ($period) { case 'today': $from = 'today'; $to = 'today'; $haxis = 4; break; case 'yesterday': $from = 'yesterday'; $to = 'yesterday'; $haxis = 4; break; case '7daysAgo': $from = '7daysAgo'; $to = 'yesterday'; $haxis = 2; break; case '14daysAgo': $from = '14daysAgo'; $to = 'yesterday'; $haxis = 3; break; case '90daysAgo': $from = '90daysAgo'; $to = 'yesterday'; $haxis = 16; break; case '365daysAgo': $from = '365daysAgo'; $to = 'yesterday'; $haxis = 5; break; case '1095daysAgo': $from = '1095daysAgo'; $to = 'yesterday'; $haxis = 5; break; default: $from = '30daysAgo'; $to = 'yesterday'; $haxis = 5; break; } if ($query == 'visitBounceRate') { $formater = "var formatter = new google.visualization.NumberFormat({\r\n\t\t\t\t suffix: '%',\r\n\t\t\t\t fractionDigits: 2\r\n\t\t\t\t});\r\n\r\n\t\t\t\tformatter.format(data, 1);\t"; } else { $formater = ''; } if (isset($this->gadwp->config->options['ga_dash_style'])) { $light_color = GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], 40); $dark_color = GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -20); $css = "colors:['" . $this->gadwp->config->options['ga_dash_style'] . "','" . GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -20) . "'],"; $color = $this->gadwp->config->options['ga_dash_style']; } else { $css = ""; $color = "#3366CC"; } if ($period == 'realtime') { wp_register_style('jquery-ui-tooltip-html', GADWP_URL . 'realtime/jquery/jquery.ui.tooltip.html.css'); wp_enqueue_style('jquery-ui-tooltip-html'); if (!wp_script_is('jquery')) { wp_enqueue_script('jquery'); } if (!wp_script_is('jquery-ui-tooltip')) { wp_enqueue_script("jquery-ui-tooltip"); } if (!wp_script_is('jquery-ui-core')) { wp_enqueue_script("jquery-ui-core"); } if (!wp_script_is('jquery-ui-position')) { wp_enqueue_script("jquery-ui-position"); } if (!wp_script_is('jquery-ui-position')) { wp_enqueue_script("jquery-ui-position"); } wp_register_script("jquery-ui-tooltip-html", GADWP_URL . 'realtime/jquery/jquery.ui.tooltip.html.js'); wp_enqueue_script("jquery-ui-tooltip-html"); } if ($period == 'realtime') { ?> <div class="realtime"> <div class="gadash-rt-box"> <div class='gadash-tdo-left'> <div class='gadash-online' id='gadash-online'>0</div> </div> <div class='gadash-tdo-right' id='gadash-tdo-right'> <div class="gadash-bigtext"> <div class="gadash-bleft"><?php _e("REFERRAL", 'google-analytics-dashboard-for-wp'); ?> </div> <div class="gadash-bright">0</div> </div> <div class="gadash-bigtext"> <div class="gadash-bleft"><?php _e("ORGANIC", 'google-analytics-dashboard-for-wp'); ?> </div> <div class="gadash-bright">0</div> </div> <div class="gadash-bigtext"> <div class="gadash-bleft"><?php _e("SOCIAL", 'google-analytics-dashboard-for-wp'); ?> </div> <div class="gadash-bright">0</div> </div> <div class="gadash-bigtext"> <div class="gadash-bleft"><?php _e("CAMPAIGN", 'google-analytics-dashboard-for-wp'); ?> </div> <div class="gadash-bright">0</div> </div> <div class="gadash-bigtext"> <div class="gadash-bleft"><?php _e("DIRECT", 'google-analytics-dashboard-for-wp'); ?> </div> <div class="gadash-bright">0</div> </div> <div class="gadash-bigtext"> <div class="gadash-bleft"><?php _e("NEW", 'google-analytics-dashboard-for-wp'); ?> </div> <div class="gadash-bright">0</div> </div> </div> </div> <div> <div id='gadash-pages' class='gadash-pages'> </div> </div> </div> <script type="text/javascript"> var focusFlag = 1; jQuery(document).ready(function(){ jQuery(window).bind("focus",function(event){ focusFlag = 1; }).bind("blur", function(event){ focusFlag = 0; }); }); jQuery(function() { jQuery('#gadash-widget *').tooltip(); }); function onlyUniqueValues(value, index, self) { return self.indexOf(value) === index; } function countsessions(data, searchvalue) { var count = 0; for ( var i = 0; i < data["rows"].length; i = i + 1 ) { if (jQuery.inArray(searchvalue, data["rows"][ i ])>-1){ count += parseInt(data["rows"][ i ][6]); } } return count; } function gadash_generatetooltip(data) { var count = 0; var table = ""; for ( var i = 0; i < data.length; i = i + 1 ) { count += parseInt(data[ i ].count); table += "<tr><td class='gadash-pgdetailsl'>"+data[i].value+"</td><td class='gadash-pgdetailsr'>"+data[ i ].count+"</td></tr>"; }; if (count){ return("<table>"+table+"</table>"); }else{ return(""); } } function gadash_pagedetails(data, searchvalue) { var newdata = []; for ( var i = 0; i < data["rows"].length; i = i + 1 ){ var sant=1; for ( var j = 0; j < newdata.length; j = j + 1 ){ if (data["rows"][i][0]+data["rows"][i][1]+data["rows"][i][2]+data["rows"][i][3]==newdata[j][0]+newdata[j][1]+newdata[j][2]+newdata[j][3]){ newdata[j][6] = parseInt(newdata[j][6]) + parseInt(data["rows"][i][6]); sant = 0; } } if (sant){ newdata.push(data["rows"][i].slice()); } } var countrfr = 0; var countkwd = 0; var countdrt = 0; var countscl = 0; var countcpg = 0; var tablerfr = ""; var tablekwd = ""; var tablescl = ""; var tablecpg = ""; var tabledrt = ""; for ( var i = 0; i < newdata.length; i = i + 1 ) { if (newdata[i][0] == searchvalue){ var pagetitle = newdata[i][5]; switch (newdata[i][3]){ case "REFERRAL": countrfr += parseInt(newdata[ i ][6]); tablerfr += "<tr><td class='gadash-pgdetailsl'>"+newdata[i][1]+"</td><td class='gadash-pgdetailsr'>"+newdata[ i ][6]+"</td></tr>"; break; case "ORGANIC": countkwd += parseInt(newdata[ i ][6]); tablekwd += "<tr><td class='gadash-pgdetailsl'>"+newdata[i][2]+"</td><td class='gadash-pgdetailsr'>"+newdata[ i ][6]+"</td></tr>"; break; case "SOCIAL": countscl += parseInt(newdata[ i ][6]); tablescl += "<tr><td class='gadash-pgdetailsl'>"+newdata[i][1]+"</td><td class='gadash-pgdetailsr'>"+newdata[ i ][6]+"</td></tr>"; break; case "CUSTOM": countcpg += parseInt(newdata[ i ][6]); tablecpg += "<tr><td class='gadash-pgdetailsl'>"+newdata[i][1]+"</td><td class='gadash-pgdetailsr'>"+newdata[ i ][6]+"</td></tr>"; break; case "DIRECT": countdrt += parseInt(newdata[ i ][6]); break; }; }; }; if (countrfr){ tablerfr = "<table><tr><td><?php _e("REFERRALS", 'google-analytics-dashboard-for-wp'); ?> ("+countrfr+")</td></tr>"+tablerfr+"</table><br />"; } if (countkwd){ tablekwd = "<table><tr><td><?php _e("KEYWORDS", 'google-analytics-dashboard-for-wp'); ?> ("+countkwd+")</td></tr>"+tablekwd+"</table><br />"; } if (countscl){ tablescl = "<table><tr><td><?php _e("SOCIAL", 'google-analytics-dashboard-for-wp'); ?> ("+countscl+")</td></tr>"+tablescl+"</table><br />"; } if (countcpg){ tablecpg = "<table><tr><td><?php _e("CAMPAIGN", 'google-analytics-dashboard-for-wp'); ?> ("+countcpg+")</td></tr>"+tablecpg+"</table><br />"; } if (countdrt){ tabledrt = "<table><tr><td><?php _e("DIRECT", 'google-analytics-dashboard-for-wp'); ?> ("+countdrt+")</td></tr></table><br />"; } return ("<p><center><strong>"+pagetitle+"</strong></center></p>"+tablerfr+tablekwd+tablescl+tablecpg+tabledrt); } function online_refresh(){ if (focusFlag){ jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: false,to: false,query: "realtime",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?> "}, function(results){ data = results[0]; if (jQuery.isNumeric(data) || typeof data === "undefined"){ data = []; data["totalsForAllResults"] = [] data["totalsForAllResults"]["rt:activeUsers"] = "0"; data["rows"]= []; } if (data["totalsForAllResults"]["rt:activeUsers"]!==document.getElementById("gadash-online").innerHTML){ jQuery("#gadash-online").fadeOut("slow"); jQuery("#gadash-online").fadeOut(500); jQuery("#gadash-online").fadeOut("slow", function() { if ((parseInt(data["totalsForAllResults"]["rt:activeUsers"]))<(parseInt(document.getElementById("gadash-online").innerHTML))){ jQuery("#gadash-online").css({'background-color' : '#FFE8E8'}); }else{ jQuery("#gadash-online").css({'background-color' : '#E0FFEC'}); } document.getElementById("gadash-online").innerHTML = data["totalsForAllResults"]["rt:activeUsers"]; }); jQuery("#gadash-online").fadeIn("slow"); jQuery("#gadash-online").fadeIn(500); jQuery("#gadash-online").fadeIn("slow", function() { jQuery("#gadash-online").css({'background-color' : '#FFFFFF'}); }); }; if (data["totalsForAllResults"]["rt:activeUsers"] == 0){ data["rows"]= []; }; var pagepath = []; var referrals = []; var keywords = []; var social = []; var visittype = []; var custom = []; for ( var i = 0; i < data["rows"].length; i = i + 1 ) { pagepath.push( data["rows"][ i ][0] ); if (data["rows"][i][3]=="REFERRAL"){ referrals.push( data["rows"][ i ][1] ); } if (data["rows"][i][3]=="ORGANIC"){ keywords.push( data["rows"][ i ][2] ); } if (data["rows"][i][3]=="SOCIAL"){ social.push( data["rows"][ i ][1] ); } if (data["rows"][i][3]=="CUSTOM"){ custom.push( data["rows"][ i ][1] ); } visittype.push( data["rows"][ i ][3] ); } var upagepathstats = []; var upagepath = pagepath.filter(onlyUniqueValues); for ( var i = 0; i < upagepath.length; i = i + 1 ) { upagepathstats[i]={"pagepath":upagepath[i],"count":countsessions(data,upagepath[i])}; } upagepathstats.sort( function(a,b){ return b.count - a.count } ); var pgstatstable = ""; for ( var i = 0; i < upagepathstats.length; i = i + 1 ) { if (i < <?php echo $this->gadwp->config->options['ga_realtime_pages']; ?> ){ pgstatstable += '<div class="gadash-pline"><div class="gadash-pleft"><a href="#" data-tooltip="'+gadash_pagedetails(data, upagepathstats[i].pagepath)+'">'+upagepathstats[i].pagepath.substring(0,70)+'</a></div><div class="gadash-pright">'+upagepathstats[i].count+'</div></div>'; } } document.getElementById("gadash-pages").innerHTML='<br /><div class="gadash-pg">'+pgstatstable+'</div>'; var ureferralsstats = []; var ureferrals = referrals.filter(onlyUniqueValues); for ( var i = 0; i < ureferrals.length; i = i + 1 ) { ureferralsstats[i]={"value":ureferrals[i],"count":countsessions(data,ureferrals[i])}; } ureferralsstats.sort( function(a,b){ return b.count - a.count } ); var ukeywordsstats = []; var ukeywords = keywords.filter(onlyUniqueValues); for ( var i = 0; i < ukeywords.length; i = i + 1 ) { ukeywordsstats[i]={"value":ukeywords[i],"count":countsessions(data,ukeywords[i])}; } ukeywordsstats.sort( function(a,b){ return b.count - a.count } ); var usocialstats = []; var usocial = social.filter(onlyUniqueValues); for ( var i = 0; i < usocial.length; i = i + 1 ) { usocialstats[i]={"value":usocial[i],"count":countsessions(data,usocial[i])}; } usocialstats.sort( function(a,b){ return b.count - a.count } ); var ucustomstats = []; var ucustom = custom.filter(onlyUniqueValues); for ( var i = 0; i < ucustom.length; i = i + 1 ) { ucustomstats[i]={"value":ucustom[i],"count":countsessions(data,ucustom[i])}; } ucustomstats.sort( function(a,b){ return b.count - a.count } ); var uvisittype = ["REFERRAL","ORGANIC","SOCIAL","CUSTOM"]; document.getElementById("gadash-tdo-right").innerHTML = '<div class="gadash-bigtext"><a href="#" data-tooltip="'+gadash_generatetooltip(ureferralsstats)+'"><div class="gadash-bleft">'+'<?php _e("REFERRAL", 'google-analytics-dashboard-for-wp'); ?> '+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[0])+'</div></div>'; document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><a href="#" data-tooltip="'+gadash_generatetooltip(ukeywordsstats)+'"><div class="gadash-bleft">'+'<?php _e("ORGANIC", 'google-analytics-dashboard-for-wp'); ?> '+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[1])+'</div></div>'; document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><a href="#" data-tooltip="'+gadash_generatetooltip(usocialstats)+'"><div class="gadash-bleft">'+'<?php _e("SOCIAL", 'google-analytics-dashboard-for-wp'); ?> '+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[2])+'</div></div>'; document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><a href="#" data-tooltip="'+gadash_generatetooltip(ucustomstats)+'"><div class="gadash-bleft">'+'<?php _e("CAMPAIGN", 'google-analytics-dashboard-for-wp'); ?> '+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[3])+'</div></div>'; var uvisitortype = ["DIRECT","NEW"]; document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><div class="gadash-bleft">'+'<?php _e("DIRECT", 'google-analytics-dashboard-for-wp'); ?> '+'</div><div class="gadash-bright">'+countsessions(data,uvisitortype[0])+'</div></div>'; document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><div class="gadash-bleft">'+'<?php _e("NEW", 'google-analytics-dashboard-for-wp'); ?> '+'</div><div class="gadash-bright">'+countsessions(data,uvisitortype[1])+'</div></div>'; }); }; }; online_refresh(); setInterval(online_refresh, 60000); </script> <?php } else { if (array_search($query, array('referrers', 'contentpages', 'searches')) !== false) { ?> <div id="gadash-trafficchannels"></div> <div id="gadash-prs"></div> <script type="text/javascript"> google.load("visualization", "1", {packages:["table","orgchart"]}); try { NProgress.configure({ parent: "#gadash-progressbar" }); NProgress.configure({ showSpinner: false }); NProgress.start(); } catch(e) { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'google-analytics-dashboard-for-wp'); ?> "); } jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "<?php echo 'trafficchannels,' . $query; ?> ",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?> "}, function(response){ if ( jQuery.isArray( response ) ) { if (!jQuery.isNumeric(response[0])){ if (jQuery.isArray(response[0])){ gadash_trafficchannels=response[0]; google.setOnLoadCallback(ga_dash_drawtrafficchannels(gadash_trafficchannels)); } else { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response[0]); } }else{ jQuery("#gadash-trafficchannels").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"}); jQuery("#gadash-trafficchannels").html("<?php _e("This report is unavailable", 'google-analytics-dashboard-for-wp'); ?> ("+response[0]+")"); } if (!jQuery.isNumeric(response[1])){ if (jQuery.isArray(response[1])){ gadash_prs=response[1]; google.setOnLoadCallback(ga_dash_drawprs(gadash_prs)); } else { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response[1]); } }else{ jQuery("#gadash-prs").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"}); jQuery("#gadash-prs").html("<?php _e("This report is unavailable", 'google-analytics-dashboard-for-wp'); ?> ("+response[1]+")"); } }else{ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response); } NProgress.done(); }); function ga_dash_drawprs(gadash_prs) { var data = google.visualization.arrayToDataTable(gadash_prs); var options = { page: 'enable', pageSize: 10, width: '100%', allowHtml: true }; var chart = new google.visualization.Table(document.getElementById('gadash-prs')); chart.draw(data, options); }; function ga_dash_drawtrafficchannels(gadash_trafficchannels) { var data = google.visualization.arrayToDataTable(gadash_trafficchannels); var options = { allowCollapse:true, allowHtml:true }; var chart = new google.visualization.OrgChart(document.getElementById('gadash-trafficchannels')); chart.draw(data, options); }; </script> <?php } else { if ($query == 'trafficdetails') { ?> <div id="gadash-trafficchannels"></div> <div class="gadash-floatwraper"> <div id="gadash-trafficmediums"></div> <div id="gadash-traffictype"></div> </div> <div class="gadash-floatwraper"> <div id="gadash-trafficorganic"></div> <div id="gadash-socialnetworks"></div> </div> <script type="text/javascript"> google.load("visualization", "1", {packages:["corechart","orgchart"]}); try { NProgress.configure({ parent: "#gadash-progressbar" }); NProgress.configure({ showSpinner: false }); NProgress.start(); } catch(e) { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'google-analytics-dashboard-for-wp'); ?> "); } jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "trafficchannels,medium,visitorType,source,socialNetwork",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?> "}, function(response){ if ( jQuery.isArray( response ) ) { if (!jQuery.isNumeric(response[0])){ if (jQuery.isArray(response[0])){ gadash_trafficchannels=response[0]; google.setOnLoadCallback(ga_dash_drawtrafficchannels(gadash_trafficchannels)); } else { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response[0]); } }else{ jQuery("#gadash-trafficchannels").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"}); jQuery("#gadash-trafficchannels").html("<?php _e("This report is unavailable", 'google-analytics-dashboard-for-wp'); ?> ("+response[0]+")"); } if (!jQuery.isNumeric(response[1])){ if (jQuery.isArray(response[1])){ gadash_trafficmediums=response[1]; google.setOnLoadCallback(ga_dash_drawtrafficmediums(gadash_trafficmediums)); } else { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response[1]); } }else{ jQuery("#gadash-trafficmediums").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"}); jQuery("#gadash-trafficmediums").html("<?php _e("This report is unavailable", 'google-analytics-dashboard-for-wp'); ?> ("+response[1]+")"); } if (!jQuery.isNumeric(response[2])){ if (jQuery.isArray(response[2])){ gadash_traffictype=response[2]; google.setOnLoadCallback(ga_dash_drawtraffictype(gadash_traffictype)); } else { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response[2]); } }else{ jQuery("#gadash-traffictype").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"}); jQuery("#gadash-traffictype").html("<?php _e("This report is unavailable", 'google-analytics-dashboard-for-wp'); ?> ("+response[2]+")"); } if (!jQuery.isNumeric(response[3])){ if (jQuery.isArray(response[3])){ gadash_trafficorganic=response[3]; google.setOnLoadCallback(ga_dash_drawtrafficorganic(gadash_trafficorganic)); } else { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response[3]); } }else{ jQuery("#gadash-trafficorganic").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"}); jQuery("#gadash-trafficorganic").html("<?php _e("This report is unavailable", 'google-analytics-dashboard-for-wp'); ?> ("+response[3]+")"); } if (!jQuery.isNumeric(response[4])){ if (jQuery.isArray(response[4])){ gadash_socialnetworks=response[4]; google.setOnLoadCallback(ga_dash_drawsocialnetworks(gadash_socialnetworks)); } else { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response[4]); } }else{ jQuery("#gadash-socialnetworks").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"}); jQuery("#gadash-socialnetworks").html("<?php _e("This report is unavailable", 'google-analytics-dashboard-for-wp'); ?> ("+response[4]+")"); } }else{ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response); } NProgress.done(); }); function ga_dash_drawtrafficmediums(gadash_trafficmediums) { var data = google.visualization.arrayToDataTable(gadash_trafficmediums); var options = { is3D: false, tooltipText: 'percentage', legend: 'none', chartArea: {width: '99%',height: '80%'}, title: '<?php _e("Traffic Mediums", 'google-analytics-dashboard-for-wp'); ?> ', colors:['<?php echo esc_html($this->gadwp->config->options['ga_dash_style']); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -10)); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], +20)); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], +10)); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -20)); ?> '] }; var chart = new google.visualization.PieChart(document.getElementById('gadash-trafficmediums')); chart.draw(data, options); }; function ga_dash_drawtraffictype(gadash_traffictype) { var data = google.visualization.arrayToDataTable(gadash_traffictype); var options = { is3D: false, tooltipText: 'percentage', legend: 'none', chartArea: {width: '99%',height: '80%'}, title: '<?php _e("Visitor Type", 'google-analytics-dashboard-for-wp'); ?> ', colors:['<?php echo esc_html($this->gadwp->config->options['ga_dash_style']); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -10)); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], +20)); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], +10)); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -20)); ?> '] }; var chart = new google.visualization.PieChart(document.getElementById('gadash-traffictype')); chart.draw(data, options); }; function ga_dash_drawsocialnetworks(gadash_socialnetworks) { var data = google.visualization.arrayToDataTable(gadash_socialnetworks); var options = { is3D: false, tooltipText: 'percentage', legend: 'none', chartArea: {width: '99%',height: '80%'}, title: '<?php _e("Social Networks", 'google-analytics-dashboard-for-wp'); ?> ', colors:['<?php echo esc_html($this->gadwp->config->options['ga_dash_style']); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -10)); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], +20)); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], +10)); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -20)); ?> '] }; var chart = new google.visualization.PieChart(document.getElementById('gadash-socialnetworks')); chart.draw(data, options); }; function ga_dash_drawtrafficorganic(gadash_trafficorganic) { var data = google.visualization.arrayToDataTable(gadash_trafficorganic); var options = { is3D: false, tooltipText: 'percentage', legend: 'none', chartArea: {width: '99%',height: '80%'}, title: '<?php _e("Search Engines", 'google-analytics-dashboard-for-wp'); ?> ', colors:['<?php echo esc_html($this->gadwp->config->options['ga_dash_style']); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -10)); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], +20)); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], +10)); ?> ','<?php echo esc_html(GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -20)); ?> '] }; var chart = new google.visualization.PieChart(document.getElementById('gadash-trafficorganic')); chart.draw(data, options); }; function ga_dash_drawtrafficchannels(gadash_trafficchannels) { var data = google.visualization.arrayToDataTable(gadash_trafficchannels); var options = { allowCollapse:true, allowHtml:true }; var chart = new google.visualization.OrgChart(document.getElementById('gadash-trafficchannels')); chart.draw(data, options); }; </script> <?php } else { if ($query == 'locations') { ?> <div id="gadash-map"></div> <div id="gadash-locations"></div> <script type="text/javascript"> google.load("visualization", "1", {packages:["geochart","table"]}); try { NProgress.configure({ parent: "#gadash-progressbar" }); NProgress.configure({ showSpinner: false }); NProgress.start(); } catch(e) { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'google-analytics-dashboard-for-wp'); ?> "); } jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "<?php echo $query; ?> ",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?> "}, function(response){ if ( jQuery.isArray( response ) ) { if (!jQuery.isNumeric(response[0])){ if (jQuery.isArray(response[0])){ gadash_locations=response[0]; google.setOnLoadCallback(ga_dash_drawmaplocations(gadash_locations)); google.setOnLoadCallback(ga_dash_drawlocations(gadash_locations)); } else { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response[0]); } }else{ jQuery("#gadash-map").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"}); jQuery("#gadash-map").html("<?php _e("This report is unavailable", 'google-analytics-dashboard-for-wp'); ?> ("+response[0]+")"); jQuery("#gadash-locations").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"}); jQuery("#gadash-locations").html("<?php _e("This report is unavailable", 'google-analytics-dashboard-for-wp'); ?> ("+response[0]+")"); } }else{ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response); } NProgress.done(); }); function ga_dash_drawmaplocations(gadash_locations) { var data = google.visualization.arrayToDataTable(gadash_locations); var options = { chartArea: {width: '99%',height: '90%'}, colors: ['<?php echo $light_color; ?> ', '<?php echo $dark_color; ?> '], <?php $country_codes = GADWP_Tools::get_countrycodes(); if ($this->gadwp->config->options['ga_target_geomap'] && isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) { ?> region : '<?php echo esc_html($this->gadwp->config->options['ga_target_geomap']); ?> ', displayMode : 'markers', datalessRegionColor : 'EFEFEF' <?php } ?> } var chart = new google.visualization.GeoChart(document.getElementById('gadash-map')); chart.draw(data, options); } function ga_dash_drawlocations(gadash_locations) { var data = google.visualization.arrayToDataTable(gadash_locations); var options = { page: 'enable', pageSize: 10, width: '100%' }; var chart = new google.visualization.Table(document.getElementById('gadash-locations')); chart.draw(data, options); }; </script> <?php } else { ?> <div id="gadash-mainchart"></div> <div id="gadash-bottomstats" class="gadash-wrapper"> <div class="inside"> <div class="small-box"> <h3><?php _e("Sessions", 'google-analytics-dashboard-for-wp'); ?> </h3> <p id="gdsessions"> </p> </div> <div class="small-box"> <h3><?php _e("Users", 'google-analytics-dashboard-for-wp'); ?> </h3> <p id="gdusers"> </p> </div> <div class="small-box"> <h3><?php _e("Page Views", 'google-analytics-dashboard-for-wp'); ?> </h3> <p id="gdpageviews"> </p> </div> <div class="small-box"> <h3><?php _e("Bounce Rate", 'google-analytics-dashboard-for-wp'); ?> </h3> <p id="gdbouncerate"> </p> </div> <div class="small-box"> <h3><?php _e("Organic Search", 'google-analytics-dashboard-for-wp'); ?> </h3> <p id="gdorganicsearch"> </p> </div> <div class="small-box"> <h3><?php _e("Pages/Session", 'google-analytics-dashboard-for-wp'); ?> </h3> <p id="gdpagespervisit"> </p> </div> </div> </div> <script type="text/javascript"> google.load("visualization", "1", {packages:["corechart"], 'language': '<?php echo get_bloginfo('language'); ?> '}); try { NProgress.configure({ parent: "#gadash-progressbar" }); NProgress.configure({ showSpinner: false }); NProgress.start(); } catch(e) { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'google-analytics-dashboard-for-wp'); ?> "); } jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "<?php echo $query . ',bottomstats'; ?> ",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?> "}, function(response){ if ( jQuery.isArray( response ) ) { if (!jQuery.isNumeric(response[0])){ if (jQuery.isArray(response[0])){ gadash_mainchart=response[0]; google.setOnLoadCallback(ga_dash_drawmainchart(gadash_mainchart)); } else { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response[0]); } }else{ jQuery("#gadash-mainchart").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"}); jQuery("#gadash-mainchart").html("<?php _e("This report is unavailable", 'google-analytics-dashboard-for-wp'); ?> ("+response[0]+")"); } if (!jQuery.isNumeric(response[1])){ if (jQuery.isArray(response[1])){ gadash_bottomstats=response[1]; ga_dash_drawbottomstats(gadash_bottomstats); } else { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response[1]); } }else{ jQuery("#gadash-bottomstats").css({"background-color":"#F7F7F7","height":"auto","padding-top":"40px","padding-bottom":"40px","color":"#000","text-align":"center","width": "98%"}); jQuery("#gadash-bottomstats").html("<?php _e("This report is unavailable", 'google-analytics-dashboard-for-wp'); ?> ("+response[1]+")"); } }else{ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'); ?> "); console.log("\n********************* GADWP Log ********************* \n\n"+response); } NProgress.done(); }); function ga_dash_drawbottomstats(gadash_bottomstats) { jQuery("#gadash-bottomstats #gdsessions").text(gadash_bottomstats[0]); jQuery("#gadash-bottomstats #gdusers").text(gadash_bottomstats[1]); jQuery("#gadash-bottomstats #gdpageviews").text(gadash_bottomstats[2]); jQuery("#gadash-bottomstats #gdbouncerate").text(gadash_bottomstats[3] + "%"); jQuery("#gadash-bottomstats #gdorganicsearch").text(gadash_bottomstats[4]); jQuery("#gadash-bottomstats #gdpagespervisit").text(gadash_bottomstats[5]); } function ga_dash_drawmainchart(gadash_mainchart) { var data = google.visualization.arrayToDataTable(gadash_mainchart); var options = { legend: {position: 'none'}, pointSize: 3,<?php echo $css; ?> chartArea: {width: '99%',height: '90%'}, vAxis: { textPosition: "in", minValue: 0}, hAxis: { textPosition: 'none' } }; <?php echo $formater; ?> var chart = new google.visualization.AreaChart(document.getElementById('gadash-mainchart')); chart.draw(data, options); }; </script> <?php } } } } }
public function add_content($content) { if (!GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_front']) || !($this->gadwp->config->options['ga_dash_frontend_stats'] || $this->gadwp->config->options['ga_dash_frontend_keywords'])) { return $content; } if ($this->gadwp->config->options['ga_dash_frontend_stats'] && $this->gadwp->config->options['ga_dash_frontend_keywords']) { $npcounter = 1; } else { $npcounter = 0; } if ((is_page() || is_single()) && !is_preview()) { $page_url = $_SERVER["REQUEST_URI"]; //Encode URL $page_url = rawurlencode($page_url); $content .= '<script type="text/javascript"> gadash_firstclick = true; function checknpcounter(max) { try { if (npcounter == max) { NProgress.done(); } else { npcounter++; NProgress.set((1/(max+1))*npcounter); } } catch(e) {} } npcounter = 0; jQuery(document).ready(function(){ jQuery("#gadwp-title").click(function(){ if (gadash_firstclick){ try { NProgress.configure({ parent: "#gadwp-progressbar" }); NProgress.configure({ showSpinner: false }); NProgress.start(); } catch(e) { jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"}); jQuery("#gadwp-progressbar").html("' . __("A JavaScript Error is blocking plugin resources!", 'ga-dash') . '"); } if(typeof ga_dash_drawpagesessions == "function"){ jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontend_pagereports",gadash_pageurl: "' . $page_url . '",query: "pageviews",gadash_security_pagereports: "' . wp_create_nonce('gadash_get_frontend_pagereports') . '"}, function(response){ if (!jQuery.isNumeric(response)){ if (jQuery.isArray(response)){ gadash_pagesessions = response; google.setOnLoadCallback(ga_dash_drawpagesessions(gadash_pagesessions)); } else { checknpcounter(0); jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"}); jQuery("#gadwp-progressbar").html("' . __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash') . '"); console.log("\\n********************* GADWP Log ********************* \\n\\n"+response); } }else{ jQuery("#gadwp-sessions").css({"background-color":"#F7F7F7","height":"auto","padding-top":"30px","padding-bottom":"30px","color":"#000","text-align":"center"}); jQuery("#gadwp-sessions").html("' . __("This report is unavailable", 'ga-dash') . ' ("+response+")"); checknpcounter(' . $npcounter . '); } }); } if(typeof ga_dash_drawpagesearches == "function"){ jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontend_pagereports",gadash_pageurl: "' . $page_url . '",query: "searches",gadash_security_pagereports: "' . wp_create_nonce('gadash_get_frontend_pagereports') . '"}, function(response){ if (!jQuery.isNumeric(response)){ if (jQuery.isArray(response)){ gadash_pagesearches = response; google.setOnLoadCallback(ga_dash_drawpagesearches(gadash_pagesearches)); } else { checknpcounter(0); jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"}); jQuery("#gadwp-progressbar").html("' . __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash') . '"); console.log("\\n********************* GADWP Log ********************* \\n\\n"+response); } }else{ jQuery("#gadwp-searches").css({"background-color":"#F7F7F7","height":"auto","padding-top":"30px","padding-bottom":"30px","color":"#000","text-align":"center"}); jQuery("#gadwp-searches").html("' . __("This report is unavailable", 'ga-dash') . ' ("+response+")"); checknpcounter(' . $npcounter . '); } }); } gadash_firstclick = false; } }); });'; if ($this->gadwp->config->options['ga_dash_frontend_stats']) { $title = __("Views vs UniqueViews", 'ga-dash'); if (isset($this->gadwp->config->options['ga_dash_style'])) { $css = "colors:['" . $this->gadwp->config->options['ga_dash_style'] . "','" . GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -20) . "'],"; $color = $this->gadwp->config->options['ga_dash_style']; } else { $css = ""; $color = "#3366CC"; } $content .= ' google.load("visualization", "1", {packages:["corechart"]}); function ga_dash_drawpagesessions(gadash_pagesessions) { var data = google.visualization.arrayToDataTable(gadash_pagesessions); var options = { legend: {position: "none"}, pointSize: 3,' . $css . ' title: "' . $title . '", vAxis: { textPosition: "in", minValue: 0}, chartArea: {width: "100%", height: "80%"}, hAxis: { textPosition: "none"} }; var chart = new google.visualization.AreaChart(document.getElementById("gadwp-sessions")); chart.draw(data, options); checknpcounter(' . $npcounter . '); }'; } if ($this->gadwp->config->options['ga_dash_frontend_keywords']) { $content .= ' google.load("visualization", "1", {packages:["table"]}) function ga_dash_drawpagesearches(gadash_pagesearches) { var datas = google.visualization.arrayToDataTable(gadash_pagesearches); var options = { page: "enable", pageSize: 6, width: "100%" }; var chart = new google.visualization.Table(document.getElementById("gadwp-searches")); chart.draw(datas, options); checknpcounter(' . $npcounter . '); }'; } $content .= "</script>"; $content .= '<p> <div id="gadwp"> <div id="gadwp-title"> <a href="#gadwp">' . __('Google Analytics Reports', "ga-dash") . ' <span id="gadwp-arrow">▼</span></a> </div> <div id="gadwp-progressbar"></div> <div id="gadwp-content"> ' . ($this->gadwp->config->options['ga_dash_frontend_stats'] ? '<div id="gadwp-sessions"></div>' : '') . ($this->gadwp->config->options['ga_dash_frontend_keywords'] ? '<div id="gadwp-searches" class="gadwp-spinner"></div>' : '') . ' </div> </div> </p>'; } return $content; }
<?php /** * Author: Alin Marcu * Author URI: https://deconf.com * License: GPLv2 or later * License URI: http://www.gnu.org/licenses/gpl-2.0.html */ // Exit if accessed directly if (!defined('ABSPATH')) { exit; } $profile = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $this->gadwp->config->options['ga_dash_tableid_jail']); ?> <script type="text/javascript"> var _gaq = _gaq || []; <?php if ($this->gadwp->config->options['ga_enhanced_links']) { ?> var pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js'; _gaq.push(['_require', 'inpage_linkid', pluginUrl]); <?php } ?> _gaq.push(['_setAccount', '<?php echo esc_html($profile[2]); ?> ']); _gaq.push(['_trackPageview']<?php if ($this->gadwp->config->options['ga_dash_anonim']) { ?>
public static function general_settings_network() { $gadwp = GADWP(); global $wp_version; if (!current_user_can('manage_network_options')) { return; } $options = self::update_options('network'); /* * Include GAPI */ echo '<div id="gapi-warning" class="updated"><p>' . __('Loading the required libraries. If this results in a blank screen or a fatal error, try this solution:', 'google-analytics-dashboard-for-wp') . ' <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_config&utm_medium=link&utm_content=general_screen&utm_campaign=gadwp">Library conflicts between WordPress plugins</a></p></div>'; if (null === $gadwp->gapi_controller) { $gadwp->gapi_controller = new GADWP_GAPI_Controller(); } echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>'; if (isset($_POST['ga_dash_code'])) { if (!stripos('x' . $_POST['ga_dash_code'], 'UA-', 1) == 1) { try { $gadwp->gapi_controller->client->authenticate($_POST['ga_dash_code']); $gadwp->config->options['ga_dash_token'] = $gadwp->gapi_controller->client->getAccessToken(); $gadwp->config->options['automatic_updates_minorversion'] = 1; $gadwp->config->set_plugin_options(true); $options = self::update_options('network'); $message = "<div class='updated'><p>" . __("Plugin authorization succeeded.", 'google-analytics-dashboard-for-wp') . "</p></div>"; if (is_multisite()) { // Cleanup errors on the entire network foreach (wp_get_sites(array('limit' => apply_filters('gadwp_sites_limit', 100))) as $blog) { switch_to_blog($blog['blog_id']); GADWP_Tools::delete_cache('gapi_errors'); restore_current_blog(); } } else { GADWP_Tools::delete_cache('gapi_errors'); } if ($gadwp->config->options['ga_dash_token'] && $gadwp->gapi_controller->client->getAccessToken()) { if (!empty($gadwp->config->options['ga_dash_profile_list'])) { $profiles = $gadwp->config->options['ga_dash_profile_list']; } else { $profiles = $gadwp->gapi_controller->refresh_profiles(); } if ($profiles) { $gadwp->config->options['ga_dash_profile_list'] = $profiles; if (isset($gadwp->config->options['ga_dash_tableid_jail']) && !$gadwp->config->options['ga_dash_tableid_jail']) { $profile = GADWP_Tools::guess_default_domain($profiles); $gadwp->config->options['ga_dash_tableid_jail'] = $profile; $gadwp->config->options['ga_dash_tableid'] = $profile; } $gadwp->config->set_plugin_options(true); $options = self::update_options('network'); } } } catch (Google_IO_Exception $e) { GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e), $gadwp->gapi_controller->error_timeout); return false; } catch (Google_Service_Exception $e) { GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $gadwp->gapi_controller->error_timeout); GADWP_Tools::set_cache('gapi_errors', $e->getErrors(), $gadwp->gapi_controller->error_timeout); return $e->getCode(); } catch (Exception $e) { GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e) . "\nResponseHttpCode:" . $e->getCode(), $gadwp->gapi_controller->error_timeout); $gadwp->gapi_controller->reset_token(false); } } else { $message = "<div class='error'><p>" . __("The access code is <strong>NOT</strong> your <strong>Tracking ID</strong> (UA-XXXXX-X). Try again, and use the red link to get your access code", 'google-analytics-dashboard-for-wp') . ".</p></div>"; } } if (isset($_POST['Refresh'])) { if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { $gadwp->config->options['ga_dash_profile_list'] = array(); $message = "<div class='updated'><p>" . __("Properties refreshed.", 'google-analytics-dashboard-for-wp') . "</p></div>"; $options = self::update_options('network'); if ($gadwp->config->options['ga_dash_token'] && $gadwp->gapi_controller->client->getAccessToken()) { if (!empty($gadwp->config->options['ga_dash_profile_list'])) { $profiles = $gadwp->config->options['ga_dash_profile_list']; } else { $profiles = $gadwp->gapi_controller->refresh_profiles(); } if ($profiles) { $gadwp->config->options['ga_dash_profile_list'] = $profiles; if (isset($gadwp->config->options['ga_dash_tableid_jail']) && !$gadwp->config->options['ga_dash_tableid_jail']) { $profile = GADWP_Tools::guess_default_domain($profiles); $gadwp->config->options['ga_dash_tableid_jail'] = $profile; $gadwp->config->options['ga_dash_tableid'] = $profile; } $gadwp->config->set_plugin_options(true); $options = self::update_options('network'); } } } else { $message = "<div class='error'><p>" . __("Cheating Huh?", 'google-analytics-dashboard-for-wp') . "</p></div>"; } } if (isset($_POST['Clear'])) { if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { GADWP_Tools::clear_cache(); $message = "<div class='updated'><p>" . __("Cleared Cache.", 'google-analytics-dashboard-for-wp') . "</p></div>"; } else { $message = "<div class='error'><p>" . __("Cheating Huh?", 'google-analytics-dashboard-for-wp') . "</p></div>"; } } if (isset($_POST['Reset'])) { if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { $gadwp->gapi_controller->reset_token(true); GADWP_Tools::clear_cache(); $message = "<div class='updated'><p>" . __("Token Reseted and Revoked.", 'google-analytics-dashboard-for-wp') . "</p></div>"; $options = self::update_options('Reset'); } else { $message = "<div class='error'><p>" . __("Cheating Huh?", 'google-analytics-dashboard-for-wp') . "</p></div>"; } } if (isset($_POST['options']['ga_dash_hidden']) && !isset($_POST['Clear']) && !isset($_POST['Reset']) && !isset($_POST['Refresh'])) { $message = "<div class='updated'><p>" . __("Settings saved.", 'google-analytics-dashboard-for-wp') . "</p></div>"; if (!(isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form'))) { $message = "<div class='error'><p>" . __("Cheating Huh?", 'google-analytics-dashboard-for-wp') . "</p></div>"; } } if (isset($_POST['Hide'])) { if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { $message = "<div class='updated'><p>" . __("All other domains/properties were removed.", 'google-analytics-dashboard-for-wp') . "</p></div>"; $lock_profile = GADWP_Tools::get_selected_profile($gadwp->config->options['ga_dash_profile_list'], $gadwp->config->options['ga_dash_tableid_jail']); $gadwp->config->options['ga_dash_profile_list'] = array($lock_profile); $options = self::update_options('network'); } else { $message = "<div class='error'><p>" . __("Cheating Huh?", 'google-analytics-dashboard-for-wp') . "</p></div>"; } } ?> <div class="wrap"> <?php echo "<h2>" . __("Google Analytics Settings", 'google-analytics-dashboard-for-wp') . "</h2>"; ?> <hr> </div> <div id="poststuff" class="gadwp"> <div id="post-body" class="metabox-holder columns-2"> <div id="post-body-content"> <div class="settings-wrapper"> <div class="inside"> <?php if ($gadwp->gapi_controller->gapi_errors_handler() || GADWP_Tools::get_cache('last_error')) { $message = sprintf('<div class="error"><p>%s</p></div>', sprintf(__('Something went wrong, check %1$s or %2$s.', 'google-analytics-dashboard-for-wp'), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_errors_debugging', false), __('Errors & Debug', 'google-analytics-dashboard-for-wp')), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_settings', false), __('authorize the plugin', 'google-analytics-dashboard-for-wp')))); } if (isset($_POST['Authorize'])) { GADWP_Tools::clear_cache(); $gadwp->gapi_controller->token_request(); echo "<div class='updated'><p>" . __("Use the red link (see below) to generate and get your access code!", 'google-analytics-dashboard-for-wp') . "</p></div>"; } else { if (isset($message)) { echo $message; } ?> <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?> "> <input type="hidden" name="options[ga_dash_hidden]" value="Y"> <?php wp_nonce_field('gadash_form', 'gadash_security'); ?> <table class="gadwp-settings-options"> <tr> <td colspan="2"><?php echo "<h2>" . __("Network Setup", 'google-analytics-dashboard-for-wp') . "</h2>"; ?> </td> </tr> <tr> <td colspan="2" class="gadwp-settings-title"> <div class="button-primary gadwp-settings-switchoo"> <input type="checkbox" name="options[ga_dash_network]" value="1" class="gadwp-settings-switchoo-checkbox" id="ga_dash_network" <?php checked($options['ga_dash_network'], 1); ?> onchange="this.form.submit()"> <label class="gadwp-settings-switchoo-label" for="ga_dash_network"> <div class="gadwp-settings-switchoo-inner"></div> <div class="gadwp-settings-switchoo-switch"></div> </label> </div> <div class="switch-desc"><?php echo " " . __("use a single Google Analytics account for the entire network", 'google-analytics-dashboard-for-wp'); ?> </div> </td> </tr> <?php if ($options['ga_dash_network']) { //Network Mode check ?> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2"><?php echo "<h2>" . __("Plugin Authorization", 'google-analytics-dashboard-for-wp') . "</h2>"; ?> </td> </tr> <tr> <td colspan="2" class="gadwp-settings-info"> <?php printf(__('You should watch the %1$s and read this %2$s before proceeding to authorization. This plugin requires a properly configured Google Analytics account!', 'google-analytics-dashboard-for-wp'), sprintf('<a href="%1$s" target="_blank">%2$s</a>', 'https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_config&utm_medium=link&utm_content=top_video&utm_campaign=gadwp', __("video", 'google-analytics-dashboard-for-wp')), sprintf('<a href="%1$s" target="_blank">%2$s</a>', 'https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_config&utm_medium=link&utm_content=top_tutorial&utm_campaign=gadwp', __("tutorial", 'google-analytics-dashboard-for-wp'))); ?> </td> </tr> <?php if (!$options['ga_dash_token'] || $options['ga_dash_userapi']) { ?> <tr> <td colspan="2" class="gadwp-settings-info"><input name="options[ga_dash_userapi]" type="checkbox" id="ga_dash_userapi" value="1" <?php checked($options['ga_dash_userapi'], 1); ?> onchange="this.form.submit()" /><?php echo " " . __("use your own API Project credentials", 'google-analytics-dashboard-for-wp'); ?> </td> </tr> <?php } if ($options['ga_dash_userapi']) { ?> <tr> <td class="gadwp-settings-title"><label for="options[ga_dash_apikey]"><?php _e("API Key:", 'google-analytics-dashboard-for-wp'); ?> </label></td> <td><input type="text" name="options[ga_dash_apikey]" value="<?php echo esc_attr($options['ga_dash_apikey']); ?> " size="40" required="required"></td> </tr> <tr> <td class="gadwp-settings-title"><label for="options[ga_dash_clientid]"><?php _e("Client ID:", 'google-analytics-dashboard-for-wp'); ?> </label></td> <td><input type="text" name="options[ga_dash_clientid]" value="<?php echo esc_attr($options['ga_dash_clientid']); ?> " size="40" required="required"></td> </tr> <tr> <td class="gadwp-settings-title"><label for="options[ga_dash_clientsecret]"><?php _e("Client Secret:", 'google-analytics-dashboard-for-wp'); ?> </label></td> <td><input type="text" name="options[ga_dash_clientsecret]" value="<?php echo esc_attr($options['ga_dash_clientsecret']); ?> " size="40" required="required"> <input type="hidden" name="options[ga_dash_hidden]" value="Y"> <?php wp_nonce_field('gadash_form', 'gadash_security'); ?> </td> </tr> <?php } if ($options['ga_dash_token']) { ?> <tr> <td colspan="2"><input type="submit" name="Reset" class="button button-secondary" value="<?php _e("Clear Authorization", 'google-analytics-dashboard-for-wp'); ?> " /> <input type="submit" name="Clear" class="button button-secondary" value="<?php _e("Clear Cache", 'google-analytics-dashboard-for-wp'); ?> " /> <input type="submit" name="Refresh" class="button button-secondary" value="<?php _e("Refresh Properties", 'google-analytics-dashboard-for-wp'); ?> " /></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2"><?php echo "<h2>" . __("Properties/Views Settings", 'google-analytics-dashboard-for-wp') . "</h2>"; ?> </td> </tr> <?php if (isset($options['ga_dash_tableid_network'])) { $options['ga_dash_tableid_network'] = json_decode(json_encode($options['ga_dash_tableid_network']), false); } foreach (wp_get_sites(array('limit' => apply_filters('gadwp_sites_limit', 100))) as $blog) { ?> <tr> <td class="gadwp-settings-title-s"><label for="ga_dash_tableid_network"><?php echo '<strong>' . $blog['domain'] . $blog['path'] . '</strong>: '; ?> </label></td> <td><select id="ga_dash_tableid_network" <?php disabled(!empty($options['ga_dash_profile_list']), false); ?> name="options[ga_dash_tableid_network][<?php echo $blog['blog_id']; ?> ]"> <?php if (!empty($options['ga_dash_profile_list'])) { foreach ($options['ga_dash_profile_list'] as $items) { if ($items[3]) { echo '<option value="' . esc_attr($items[1]) . '" ' . selected($items[1], isset($options['ga_dash_tableid_network']->{$blog}['blog_id']) ? $options['ga_dash_tableid_network']->{$blog}['blog_id'] : ''); echo ' title="' . __("View Name:", 'google-analytics-dashboard-for-wp') . ' ' . esc_attr($items[0]) . '">' . esc_html(GADWP_Tools::strip_protocol($items[3])) . ' ⇒ ' . esc_attr($items[0]) . '</option>'; } } } else { echo '<option value="">' . __("Property not found", 'google-analytics-dashboard-for-wp') . '</option>'; } ?> </select> <br /></td> </tr> <?php } ?> <tr> <td colspan="2"><?php echo "<h2>" . __("Automatic Updates", 'google-analytics-dashboard-for-wp') . "</h2>"; ?> </td> </tr> <tr> <td colspan="2" class="gadwp-settings-title"> <div class="button-primary gadwp-settings-switchoo"> <input type="checkbox" name="options[automatic_updates_minorversion]" value="1" class="gadwp-settings-switchoo-checkbox" id="automatic_updates_minorversion" <?php checked($options['automatic_updates_minorversion'], 1); ?> > <label class="gadwp-settings-switchoo-label" for="automatic_updates_minorversion"> <div class="gadwp-settings-switchoo-inner"></div> <div class="gadwp-settings-switchoo-switch"></div> </label> </div> <div class="switch-desc"><?php echo " " . __("automatic updates for minor versions (security and maintenance releases only)", 'google-analytics-dashboard-for-wp'); ?> </div> </td> </tr> <tr> <td colspan="2"><hr><?php echo "<h2>" . __("Exclude Tracking", 'google-analytics-dashboard-for-wp') . "</h2>"; ?> </td> </tr> <tr> <td colspan="2" class="gadwp-settings-title"> <div class="button-primary gadwp-settings-switchoo"> <input type="checkbox" name="options[ga_dash_excludesa]" value="1" class="gadwp-settings-switchoo-checkbox" id="ga_dash_excludesa"<?php checked($options['ga_dash_excludesa'], 1); ?> "> <label class="gadwp-settings-switchoo-label" for="ga_dash_excludesa"> <div class="gadwp-settings-switchoo-inner"></div> <div class="gadwp-settings-switchoo-switch"></div> </label> </div> <div class="switch-desc"><?php echo " " . __("exclude Super Admin tracking for the entire network", 'google-analytics-dashboard-for-wp'); ?> </div> </td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2" class="submit"><input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'google-analytics-dashboard-for-wp'); ?> " /></td> </tr> <?php } else { ?> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2"><input type="submit" name="Authorize" class="button button-secondary" id="authorize" value="<?php _e("Authorize Plugin", 'google-analytics-dashboard-for-wp'); ?> " /> <input type="submit" name="Clear" class="button button-secondary" value="<?php _e("Clear Cache", 'google-analytics-dashboard-for-wp'); ?> " /></td> </tr> <?php } //Network Mode check ?> <tr> <td colspan="2"><hr></td> </tr> </table> </form> <?php self::output_sidebar(); return; } ?> </table> </form> <?php } self::output_sidebar(); }
/** * Ajax handler for getting analytics data for frontend Widget * * @return string|int */ public function ajax_frontend_widget() { if (!isset($_POST['gadwp_number']) || !isset($_POST['gadwp_optionname']) || !is_active_widget(false, false, 'gadwp-frontwidget-report')) { wp_die(-30); } $widget_index = $_POST['gadwp_number']; $option_name = $_POST['gadwp_optionname']; $options = get_option($option_name); if (isset($options[$widget_index])) { $instance = $options[$widget_index]; } else { wp_die(-32); } switch ($instance['period']) { // make sure we have a valid request case '7daysAgo': $period = '7daysAgo'; break; case '14daysAgo': $period = '14daysAgo'; break; default: $period = '30daysAgo'; break; } if (ob_get_length()) { ob_clean(); } if ($this->gadwp->config->options['ga_dash_token'] && $this->gadwp->config->options['ga_dash_tableid_jail']) { if (null === $this->gadwp->gapi_controller) { $this->gadwp->gapi_controller = new GADWP_GAPI_Controller(); } } else { wp_die(-24); } $projectId = $this->gadwp->config->options['ga_dash_tableid_jail']; $profile_info = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $projectId); if (isset($profile_info[4])) { $this->gadwp->gapi_controller->timeshift = $profile_info[4]; } else { $this->gadwp->gapi_controller->timeshift = (int) current_time('timestamp') - time(); } wp_send_json($this->gadwp->gapi_controller->frontend_widget_stats($projectId, $period, (int) $instance['anonim'])); }
<?php // Exit if accessed directly if (!defined('ABSPATH')) { exit; } $domaindata = GADWP_Tools::get_root_domain(esc_html(get_option('siteurl'))); ?> <script type="text/javascript"> (function($){ $(window).load(function() { <?php if ($this->gadwp->config->options['ga_event_tracking']) { ?> //Track Downloads $('a').filter(function() { return this.href.match(/.*\.(<?php echo esc_js($this->gadwp->config->options['ga_event_downloads']); ?> )(\?.*)?$/); }).click(function(e) { ga('send','event', 'download', 'click', this.href<?php if (isset($this->gadwp->config->options['ga_event_bouncerate']) && $this->gadwp->config->options['ga_event_bouncerate']) { echo ", {'nonInteraction': 1}"; } ?> ); });
/** * Ajax handler for Admin Widget * * @return json|int */ public function ajax_widget_reports() { if (!isset($_REQUEST['gadash_security_widget_reports']) || !wp_verify_nonce($_REQUEST['gadash_security_widget_reports'], 'gadash_get_widgetreports')) { wp_die(-30); } $projectId = $_REQUEST['projectId']; $from = $_REQUEST['from']; $to = $_REQUEST['to']; $query = $_REQUEST['query']; if (ob_get_length()) { ob_clean(); } if (!GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) || 0 == $this->gadwp->config->options['dashboard_widget']) { wp_die(-31); } if ($this->gadwp->config->options['ga_dash_token'] && $projectId && $from && $to) { if (null === $this->gadwp->gapi_controller) { $this->gadwp->gapi_controller = new GADWP_GAPI_Controller(); } } else { wp_die(-24); } $profile_info = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $projectId); if (isset($profile_info[4])) { $this->gadwp->gapi_controller->timeshift = $profile_info[4]; } else { $this->gadwp->gapi_controller->timeshift = (int) current_time('timestamp') - time(); } $queries = explode(',', $query); $results = array(); foreach ($queries as $value) { $results[] = $this->gadwp->gapi_controller->get($projectId, $value, $from, $to); } wp_send_json($results); }
public static function clear_cache() { global $wpdb; $sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'gadwp_cache_qr%%'"); GADWP_Tools::unset_cookie('default_metric'); GADWP_Tools::unset_cookie('default_dimension'); GADWP_Tools::unset_cookie('default_view'); }
public function widget($args, $instance) { $widget_title = apply_filters('widget_title', $instance['title']); $title = __("Sessions", 'google-analytics-dashboard-for-wp'); echo "\n<!-- BEGIN GADWP v" . GADWP_CURRENT_VERSION . " Widget - https://deconf.com/google-analytics-dashboard-wordpress/ -->\n"; echo $args['before_widget']; if (!empty($widget_title)) { echo $args['before_title'] . $widget_title . $args['after_title']; } if (isset($this->gadwp->config->options['ga_dash_style'])) { $css = "colors:['" . $this->gadwp->config->options['ga_dash_style'] . "','" . GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -20) . "'],"; $color = $this->gadwp->config->options['ga_dash_style']; } else { $css = ""; $color = "#3366CC"; } ob_start(); if ($instance['anonim']) { $formater = "var formatter = new google.visualization.NumberFormat({\r\n\t\t\t\t\t suffix: '%',\r\n\t\t\t\t\t fractionDigits: 2\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\t\tformatter.format(data, 1);\t"; } else { $formater = ''; } $periodtext = ""; switch ($instance['period']) { case '7daysAgo': $periodtext = sprintf(__('Last %d Days', 'google-analytics-dashboard-for-wp'), 7); break; case '14daysAgo': $periodtext = sprintf(__('Last %d Days', 'google-analytics-dashboard-for-wp'), 14); break; case '30daysAgo': $periodtext = sprintf(__('Last %d Days', 'google-analytics-dashboard-for-wp'), 30); break; default: $periodtext = ""; break; } switch ($instance['display']) { case '1': echo '<div id="gadwp-widget"><div id="gadwp-widgetchart"></div><div id="gadwp-widgettotals"></div></div>'; break; case '2': echo '<div id="gadwp-widget"><div id="gadwp-widgetchart"></div></div>'; break; case '3': echo '<div id="gadwp-widget"><div id="gadwp-widgettotals"></div></div>'; break; } echo '<script type="text/javascript"> jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontendwidget_data",gadash_number: "' . $this->number . '",gadash_optionname: "' . $this->option_name . '"}, function(response){ if (!jQuery.isNumeric(response) && jQuery.isArray(response)){ if (jQuery("#gadwp-widgetchart")[0]){ gadash_widgetsessions=response[0]; google.setOnLoadCallback(ga_dash_drawfwidgetsessions(gadash_widgetsessions)); } if (jQuery("#gadwp-widgettotals")[0]){ ga_dash_drawtotalsstats(response[1]); } }else{ jQuery("#gadwp-widgetchart").css({"background-color":"#F7F7F7","height":"auto","padding-top":"50px","padding-bottom":"50px","color":"#000","text-align":"center"}); jQuery("#gadwp-widgetchart").html("' . __("This report is unavailable", 'google-analytics-dashboard-for-wp') . ' ("+response+")"); } });'; echo 'google.load("visualization", "1", {packages:["corechart"], "language" : "' . get_bloginfo('language') . '"}); function ga_dash_drawfwidgetsessions(response) { var data = google.visualization.arrayToDataTable(response); var options = { legend: {position: "none"}, pointSize: 3,' . $css . ' title: "' . $title . '", titlePosition: "in", chartArea: {width: "95%",height:"75%"}, hAxis: { textPosition: "none"}, vAxis: { textPosition: "none", minValue: 0, gridlines: {color: "transparent"}, baselineColor: "transparent"} } var chart = new google.visualization.AreaChart(document.getElementById("gadwp-widgetchart")); ' . $formater . ' chart.draw(data, options); } function ga_dash_drawtotalsstats(response) { if (response == null){ response = 0; } jQuery("#gadwp-widgettotals").html("<div class=\\"gadwp-left\\">' . __("Period:", 'google-analytics-dashboard-for-wp') . '</div> <div class=\\"gadwp-right\\">' . $periodtext . '</div><div class=\\"gadwp-left\\">' . __("Sessions:", 'google-analytics-dashboard-for-wp') . '</div> <div class=\\"gadwp-right\\">"+response+"</div>"); }'; echo '</script>'; if ($instance['give_credits'] == 1) { echo '<div style="text-align:right;width:100%;font-size:0.8em;clear:both;margin-right:5px;">' . __('generated by', 'google-analytics-dashboard-for-wp') . ' <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_report&utm_medium=link&utm_content=front_widget&utm_campaign=gadwp" rel="nofollow" style="text-decoration:none;font-size:1em;">GADWP</a> </div>'; } $widget_content = ob_get_contents(); ob_end_clean(); echo apply_filters('widget_html_content', $widget_content); echo $args['after_widget']; echo "\n<!-- END GADWP Widget -->\n"; }
private function maintain_compatibility() { $flag = false; if (GADWP_CURRENT_VERSION != get_option('gadwp_version')) { $rebuild_token = json_decode($this->options['ga_dash_token']); // v4.8.2 if (is_object($rebuild_token) && !isset($rebuild_token->token_type)) { if (isset($this->options['ga_dash_refresh_token'])) { $rebuild_token->refresh_token = $this->options['ga_dash_refresh_token']; } $rebuild_token->token_type = "Bearer"; $this->options['ga_dash_token'] = json_encode($rebuild_token); unset($this->options['ga_dash_refresh_token']); $this->set_plugin_options(true); } else { unset($this->options['ga_dash_refresh_token']); } GADWP_Tools::clear_cache(); GADWP_Tools::clear_transients(); // 4.8.3 to be removed after a few months $flag = true; GADWP_Tools::delete_cache('last_error'); update_option('gadwp_version', GADWP_CURRENT_VERSION); update_option('gadwp_got_updated', true); if (is_multisite()) { // Cleanup errors and cookies on the entire network foreach (wp_get_sites(array('limit' => apply_filters('gadwp_sites_limit', 100))) as $blog) { switch_to_blog($blog['blog_id']); GADWP_Tools::delete_cache('gapi_errors'); restore_current_blog(); } } else { GADWP_Tools::delete_cache('gapi_errors'); } GADWP_Tools::unset_cookie('default_metric'); GADWP_Tools::unset_cookie('default_dimension'); } if (!isset($this->options['ga_enhanced_links'])) { $this->options['ga_enhanced_links'] = 0; $flag = true; } if (!isset($this->options['ga_dash_network'])) { $this->options['ga_dash_network'] = 0; $flag = true; } if (!isset($this->options['ga_enhanced_excludesa'])) { $this->options['ga_dash_excludesa'] = 0; $flag = true; } if (!isset($this->options['ga_dash_remarketing'])) { $this->options['ga_dash_remarketing'] = 0; $flag = true; } if (!isset($this->options['ga_dash_adsense'])) { $this->options['ga_dash_adsense'] = 0; $flag = true; } if (!isset($this->options['ga_speed_samplerate'])) { $this->options['ga_speed_samplerate'] = 1; $flag = true; } if (!isset($this->options['automatic_updates_minorversion'])) { $this->options['automatic_updates_minorversion'] = 1; $flag = true; } if (!isset($this->options['ga_event_bouncerate'])) { $this->options['ga_event_bouncerate'] = 0; $flag = true; } if (!is_array($this->options['ga_dash_access_front']) || empty($this->options['ga_dash_access_front'])) { $this->options['ga_dash_access_front'] = array(); $this->options['ga_dash_access_front'][] = 'administrator'; $flag = true; } if (!is_array($this->options['ga_dash_profile_list'])) { $this->options['ga_dash_profile_list'] = array(); $flag = true; } if (!is_array($this->options['ga_dash_access_back']) || empty($this->options['ga_dash_access_back'])) { $this->options['ga_dash_access_back'] = array(); $this->options['ga_dash_access_back'][] = 'administrator'; $flag = true; } if (!is_array($this->options['ga_track_exclude'])) { $this->options['ga_track_exclude'] = array(); $flag = true; } if (!isset($this->options['ga_crossdomain_tracking'])) { $this->options['ga_crossdomain_tracking'] = 0; $flag = true; } if (!isset($this->options['ga_crossdomain_list'])) { $this->options['ga_crossdomain_list'] = ''; $flag = true; } if (!isset($this->options['ga_author_dimindex'])) { $this->options['ga_author_dimindex'] = 0; $flag = true; } if (!isset($this->options['ga_category_dimindex'])) { $this->options['ga_category_dimindex'] = 0; $flag = true; } if (!isset($this->options['ga_user_dimindex'])) { $this->options['ga_user_dimindex'] = 0; $flag = true; } if (!isset($this->options['ga_pubyear_dimindex'])) { $this->options['ga_pubyear_dimindex'] = 0; $flag = true; } if (!isset($this->options['ga_event_affiliates'])) { $this->options['ga_event_affiliates'] = '/out/'; $flag = true; } if (!isset($this->options['ga_aff_tracking'])) { $this->options['ga_aff_tracking'] = 0; $flag = true; } if (!isset($this->options['ga_hash_tracking'])) { $this->options['ga_hash_tracking'] = 0; $flag = true; } if (!isset($this->options['backend_item_reports'])) { // v4.8 $this->options['backend_item_reports'] = 1; $flag = true; } if (isset($this->options['ga_dash_default_metric'])) { // v4.8.1 unset($this->options['ga_dash_default_metric']); $flag = true; } if (isset($this->options['ga_dash_default_dimension'])) { // v4.8.1 unset($this->options['ga_dash_default_dimension']); $flag = true; } if (isset($this->options['item_reports'])) { // v4.8 $this->options['backend_item_reports'] = $this->options['item_reports']; unset($this->options['item_reports']); $flag = true; } if (isset($this->options['ga_dash_frontend_stats'])) { // v4.8 $this->options['frontend_item_reports'] = $this->options['ga_dash_frontend_stats']; unset($this->options['ga_dash_frontend_stats']); $flag = true; } if (!isset($this->options['dashboard_widget'])) { // v4.7 $this->options['dashboard_widget'] = 1; $flag = true; } if (!isset($this->options['api_backoff'])) { // v4.8.1.3 $this->options['api_backoff'] = 0; $flag = true; } if (isset($this->options['ga_tracking_code'])) { unset($this->options['ga_tracking_code']); $flag = true; } if (isset($this->options['ga_dash_frontend_keywords'])) { // v4.8 unset($this->options['ga_dash_frontend_keywords']); $flag = true; } if (isset($this->options['ga_dash_jailadmins'])) { // v4.7 if (isset($this->options['ga_dash_jailadmins'])) { $this->options['switch_profile'] = 0; unset($this->options['ga_dash_jailadmins']); $flag = true; } else { $this->options['switch_profile'] = 1; unset($this->options['ga_dash_jailadmins']); $flag = true; } } if ($flag) { $this->set_plugin_options(false); } }
/** * Styles & Scripts conditional loading (based on current URI) * * @param * $hook */ public function load_styles_scripts($hook) { $new_hook = explode('_page_', $hook); if (isset($new_hook[1])) { $new_hook = '_page_' . $new_hook[1]; } else { $new_hook = $hook; } /* * GADWP main stylesheet */ wp_enqueue_style('gadwp', GADWP_URL . 'admin/css/gadwp.css', null, GADWP_CURRENT_VERSION); /* * GADWP UI */ if (GADWP_Tools::get_cache('gapi_errors')) { $ed_bubble = '!'; } else { $ed_bubble = ''; } wp_enqueue_script('gadwp-backend-ui', plugins_url('js/ui.js', __FILE__), array('jquery'), GADWP_CURRENT_VERSION, true); /* @formatter:off */ wp_localize_script('gadwp-backend-ui', 'gadwp_ui_data', array('ajaxurl' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('gadwp_dismiss_notices'), 'ed_bubble' => $ed_bubble)); /* @formatter:on */ if ($this->gadwp->config->options['switch_profile'] && count($this->gadwp->config->options['ga_dash_profile_list']) > 1) { $views = array(); foreach ($this->gadwp->config->options['ga_dash_profile_list'] as $items) { if ($items[3]) { $views[$items[1]] = esc_js(GADWP_Tools::strip_protocol($items[3])); // . ' ⇒ ' . $items[0] ); } } } else { $views = false; } /* * Main Dashboard Widgets Styles & Scripts */ $widgets_hooks = array('index.php'); if (in_array($new_hook, $widgets_hooks)) { if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && $this->gadwp->config->options['dashboard_widget']) { if ($this->gadwp->config->options['ga_target_geomap']) { $country_codes = GADWP_Tools::get_countrycodes(); if (isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) { $region = $this->gadwp->config->options['ga_target_geomap']; } else { $region = false; } } else { $region = false; } wp_enqueue_style('gadwp-nprogress', GADWP_URL . 'common/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION); wp_enqueue_style('gadwp-backend-item-reports', GADWP_URL . 'admin/css/admin-widgets.css', null, GADWP_CURRENT_VERSION); wp_register_style('jquery-ui-tooltip-html', GADWP_URL . 'common/realtime/jquery.ui.tooltip.html.css'); wp_enqueue_style('jquery-ui-tooltip-html'); wp_register_script('jquery-ui-tooltip-html', GADWP_URL . 'common/realtime/jquery.ui.tooltip.html.js'); if (!wp_script_is('googlejsapi')) { wp_register_script('googlejsapi', 'https://www.google.com/jsapi'); } wp_enqueue_script('gadwp-nprogress', GADWP_URL . 'common/nprogress/nprogress.js', array('jquery'), GADWP_CURRENT_VERSION); wp_enqueue_script('gadwp-backend-dashboard-reports', GADWP_URL . 'common/js/reports.js', array('jquery', 'googlejsapi', 'gadwp-nprogress', 'jquery-ui-tooltip', 'jquery-ui-core', 'jquery-ui-position', 'jquery-ui-tooltip-html'), GADWP_CURRENT_VERSION); /* @formatter:off */ wp_localize_script('gadwp-backend-dashboard-reports', 'gadwp_item_data', array('ajaxurl' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('gadwp_backend_item_reports'), 'dateList' => array('realtime' => __("Real-Time", 'google-analytics-dashboard-for-wp'), 'today' => __("Today", 'google-analytics-dashboard-for-wp'), 'yesterday' => __("Yesterday", 'google-analytics-dashboard-for-wp'), '7daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 7), '14daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 14), '30daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 30), '90daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 90), '365daysAgo' => sprintf(_n("%s Year", "%s Years", 1, 'google-analytics-dashboard-for-wp'), __('One', 'google-analytics-dashboard-for-wp')), '1095daysAgo' => sprintf(_n("%s Year", "%s Years", 3, 'google-analytics-dashboard-for-wp'), __('Three', 'google-analytics-dashboard-for-wp'))), 'reportList' => array('sessions' => __("Sessions", 'google-analytics-dashboard-for-wp'), 'users' => __("Users", 'google-analytics-dashboard-for-wp'), 'organicSearches' => __("Organic", 'google-analytics-dashboard-for-wp'), 'pageviews' => __("Page Views", 'google-analytics-dashboard-for-wp'), 'visitBounceRate' => __("Bounce Rate", 'google-analytics-dashboard-for-wp'), 'locations' => __("Location", 'google-analytics-dashboard-for-wp'), 'contentpages' => __("Pages", 'google-analytics-dashboard-for-wp'), 'referrers' => __("Referrers", 'google-analytics-dashboard-for-wp'), 'searches' => __("Searches", 'google-analytics-dashboard-for-wp'), 'trafficdetails' => __("Traffic Details", 'google-analytics-dashboard-for-wp')), 'i18n' => array(__("A JavaScript Error is blocking plugin resources!", 'google-analytics-dashboard-for-wp'), __("Traffic Mediums", 'google-analytics-dashboard-for-wp'), __("Visitor Type", 'google-analytics-dashboard-for-wp'), __("Social Networks", 'google-analytics-dashboard-for-wp'), __("Search Engines", 'google-analytics-dashboard-for-wp'), __("Sessions", 'google-analytics-dashboard-for-wp'), __("Users", 'google-analytics-dashboard-for-wp'), __("Page Views", 'google-analytics-dashboard-for-wp'), __("Bounce Rate", 'google-analytics-dashboard-for-wp'), __("Organic Search", 'google-analytics-dashboard-for-wp'), __("Pages/Session", 'google-analytics-dashboard-for-wp'), __("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'), __("Not enough data collected", 'google-analytics-dashboard-for-wp'), __("This report is unavailable", 'google-analytics-dashboard-for-wp'), __("report generated by", 'google-analytics-dashboard-for-wp'), __("This plugin needs an authorization:", 'google-analytics-dashboard-for-wp') . ' <a href="' . menu_page_url('gadash_settings', false) . '">' . __("authorize the plugin", 'google-analytics-dashboard-for-wp') . '</a>.'), 'i18n_realtime' => array(__("REFERRALS", 'google-analytics-dashboard-for-wp'), __("KEYWORDS", 'google-analytics-dashboard-for-wp'), __("SOCIAL", 'google-analytics-dashboard-for-wp'), __("CAMPAIGN", 'google-analytics-dashboard-for-wp'), __("DIRECT", 'google-analytics-dashboard-for-wp'), __("NEW", 'google-analytics-dashboard-for-wp')), 'realtime_maxpages' => $this->gadwp->config->options['ga_realtime_pages'], 'colorVariations' => GADWP_Tools::variations($this->gadwp->config->options['ga_dash_style']), 'region' => $region, 'language' => get_bloginfo('language'), 'viewList' => $views, 'scope' => 'admin-widgets')); /* @formatter:on */ } } /* * Posts/Pages List Styles & Scripts */ $contentstats_hooks = array('edit.php'); if (in_array($hook, $contentstats_hooks)) { if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && $this->gadwp->config->options['backend_item_reports']) { if ($this->gadwp->config->options['ga_target_geomap']) { $country_codes = GADWP_Tools::get_countrycodes(); if (isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) { $region = $this->gadwp->config->options['ga_target_geomap']; } else { $region = false; } } else { $region = false; } wp_enqueue_style('gadwp-nprogress', GADWP_URL . 'common/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION); wp_enqueue_style('gadwp-backend-item-reports', GADWP_URL . 'admin/css/item-reports.css', null, GADWP_CURRENT_VERSION); wp_enqueue_style("wp-jquery-ui-dialog"); if (!wp_script_is('googlejsapi')) { wp_register_script('googlejsapi', 'https://www.google.com/jsapi'); } wp_enqueue_script('gadwp-nprogress', GADWP_URL . 'common/nprogress/nprogress.js', array('jquery'), GADWP_CURRENT_VERSION); wp_enqueue_script('gadwp-backend-item-reports', GADWP_URL . 'common/js/reports.js', array('gadwp-nprogress', 'googlejsapi', 'jquery', 'jquery-ui-dialog'), GADWP_CURRENT_VERSION); /* @formatter:off */ wp_localize_script('gadwp-backend-item-reports', 'gadwp_item_data', array('ajaxurl' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('gadwp_backend_item_reports'), 'dateList' => array('today' => __("Today", 'google-analytics-dashboard-for-wp'), 'yesterday' => __("Yesterday", 'google-analytics-dashboard-for-wp'), '7daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 7), '14daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 14), '30daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 30), '90daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 90), '365daysAgo' => sprintf(_n("%s Year", "%s Years", 1, 'google-analytics-dashboard-for-wp'), __('One', 'google-analytics-dashboard-for-wp')), '1095daysAgo' => sprintf(_n("%s Year", "%s Years", 3, 'google-analytics-dashboard-for-wp'), __('Three', 'google-analytics-dashboard-for-wp'))), 'reportList' => array('uniquePageviews' => __("Unique Views", 'google-analytics-dashboard-for-wp'), 'users' => __("Users", 'google-analytics-dashboard-for-wp'), 'organicSearches' => __("Organic", 'google-analytics-dashboard-for-wp'), 'pageviews' => __("Page Views", 'google-analytics-dashboard-for-wp'), 'visitBounceRate' => __("Bounce Rate", 'google-analytics-dashboard-for-wp'), 'locations' => __("Location", 'google-analytics-dashboard-for-wp'), 'referrers' => __("Referrers", 'google-analytics-dashboard-for-wp'), 'searches' => __("Searches", 'google-analytics-dashboard-for-wp'), 'trafficdetails' => __("Traffic Details", 'google-analytics-dashboard-for-wp')), 'i18n' => array(__("A JavaScript Error is blocking plugin resources!", 'google-analytics-dashboard-for-wp'), __("Traffic Mediums", 'google-analytics-dashboard-for-wp'), __("Visitor Type", 'google-analytics-dashboard-for-wp'), __("Social Networks", 'google-analytics-dashboard-for-wp'), __("Search Engines", 'google-analytics-dashboard-for-wp'), __("Unique Views", 'google-analytics-dashboard-for-wp'), __("Users", 'google-analytics-dashboard-for-wp'), __("Page Views", 'google-analytics-dashboard-for-wp'), __("Bounce Rate", 'google-analytics-dashboard-for-wp'), __("Organic Search", 'google-analytics-dashboard-for-wp'), __("Pages/Session", 'google-analytics-dashboard-for-wp'), __("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'), __("Not enough data collected", 'google-analytics-dashboard-for-wp'), __("This report is unavailable", 'google-analytics-dashboard-for-wp'), __("report generated by", 'google-analytics-dashboard-for-wp'), __("This plugin needs an authorization:", 'google-analytics-dashboard-for-wp') . ' <a href="' . menu_page_url('gadash_settings', false) . '">' . __("authorize the plugin", 'google-analytics-dashboard-for-wp') . '</a>.'), 'colorVariations' => GADWP_Tools::variations($this->gadwp->config->options['ga_dash_style']), 'region' => $region, 'language' => get_bloginfo('language'), 'viewList' => false, 'scope' => 'admin-item')); /* @formatter:on */ } } /* * Settings Styles & Scripts */ $settings_hooks = array('_page_gadash_settings', '_page_gadash_backend_settings', '_page_gadash_frontend_settings', '_page_gadash_tracking_settings', '_page_gadash_errors_debugging'); if (in_array($new_hook, $settings_hooks)) { wp_enqueue_style('wp-color-picker'); wp_enqueue_script('wp-color-picker'); wp_enqueue_script('wp-color-picker-script-handle', plugins_url('js/wp-color-picker-script.js', __FILE__), array('wp-color-picker'), false, true); wp_enqueue_script('gadwp-settings', plugins_url('js/settings.js', __FILE__), array('jquery'), GADWP_CURRENT_VERSION); } }
/** * Conditional load */ public function load() { if (is_admin()) { if (defined('DOING_AJAX') && DOING_AJAX) { if (GADWP_Tools::check_roles(self::$instance->config->options['ga_dash_access_back'])) { /* * Load Backend ajax actions */ include_once GADWP_DIR . 'admin/ajax-actions.php'; self::$instance->backend_actions = new GADWP_Backend_Ajax(); } /* * Load Frontend ajax actions */ include_once GADWP_DIR . 'front/ajax-actions.php'; self::$instance->frontend_actions = new GADWP_Frontend_Ajax(); /* * Load Common ajax actions */ include_once GADWP_DIR . 'common/ajax-actions.php'; self::$instance->common_actions = new GADWP_Common_Ajax(); } else { if (GADWP_Tools::check_roles(self::$instance->config->options['ga_dash_access_back'])) { /* * Load Backend Setup */ include_once GADWP_DIR . 'admin/setup.php'; self::$instance->backend_setup = new GADWP_Backend_Setup(); if (self::$instance->config->options['dashboard_widget']) { /* * Load Backend Widget */ include_once GADWP_DIR . 'admin/widgets.php'; self::$instance->backend_widgets = new GADWP_Backend_Widgets(); } if (self::$instance->config->options['backend_item_reports']) { /* * Load Backend Item Reports */ include_once GADWP_DIR . 'admin/item-reports.php'; self::$instance->backend_item_reports = new GADWP_Backend_Item_Reports(); } } } } else { if (GADWP_Tools::check_roles(self::$instance->config->options['ga_dash_access_front'])) { /* * Load Frontend Setup */ include_once GADWP_DIR . 'front/setup.php'; self::$instance->frontend_setup = new GADWP_Frontend_Setup(); if (self::$instance->config->options['frontend_item_reports']) { /* * Load Frontend Item Reports */ include_once GADWP_DIR . 'front/item-reports.php'; self::$instance->frontend_item_reports = new GADWP_Frontend_Item_Reports(); } } if (!GADWP_Tools::check_roles(self::$instance->config->options['ga_track_exclude'], true) && self::$instance->config->options['ga_dash_tracking']) { /* * Load tracking class */ include_once GADWP_DIR . 'front/tracking.php'; self::$instance->tracking = new GADWP_Tracking(); } } }
private function maintain_compatibility() { $flag = false; if (GADWP_CURRENT_VERSION != get_option('gadwp_version')) { GADWP_Tools::clear_cache(); $flag = true; $this->options['automatic_updates_minorversion'] = 1; delete_transient('ga_dash_lasterror'); update_option('gadwp_version', GADWP_CURRENT_VERSION); if (is_multisite()) { // Cleanup errors on the entire network foreach (wp_get_sites(array('limit' => apply_filters('gadwp_sites_limit', 100))) as $blog) { switch_to_blog($blog['blog_id']); delete_transient('ga_dash_gapi_errors'); restore_current_blog(); } } else { delete_transient('ga_dash_gapi_errors'); } } if (!isset($this->options['ga_enhanced_links'])) { $this->options['ga_enhanced_links'] = 0; $flag = true; } if (!isset($this->options['ga_enhanced_network'])) { $this->options['ga_dash_network'] = 0; $flag = true; } if (!isset($this->options['ga_enhanced_excludesa'])) { $this->options['ga_dash_excludesa'] = 0; $flag = true; } if (!isset($this->options['ga_dash_remarketing'])) { $this->options['ga_dash_remarketing'] = 0; $flag = true; } if (!isset($this->options['ga_dash_adsense'])) { $this->options['ga_dash_adsense'] = 0; $flag = true; } if (!isset($this->options['ga_speed_samplerate'])) { $this->options['ga_speed_samplerate'] = 1; $flag = true; } if (!isset($this->options['automatic_updates_minorversion'])) { $this->options['automatic_updates_minorversion'] = 1; $flag = true; } if (!isset($this->options['ga_event_bouncerate'])) { $this->options['ga_event_bouncerate'] = 0; $flag = true; } if (!is_array($this->options['ga_dash_access_front']) || empty($this->options['ga_dash_access_front'])) { $this->options['ga_dash_access_front'] = array(); $this->options['ga_dash_access_front'][] = 'administrator'; $flag = true; } if (!is_array($this->options['ga_dash_profile_list'])) { $this->options['ga_dash_profile_list'] = array(); $flag = true; } if (!is_array($this->options['ga_dash_access_back']) || empty($this->options['ga_dash_access_back'])) { $this->options['ga_dash_access_back'] = array(); $this->options['ga_dash_access_back'][] = 'administrator'; $flag = true; } if (!is_array($this->options['ga_track_exclude'])) { $this->options['ga_track_exclude'] = array(); $flag = true; } if (!isset($this->options['ga_crossdomain_tracking'])) { $this->options['ga_crossdomain_tracking'] = 0; $flag = true; } if (!isset($this->options['ga_crossdomain_list'])) { $this->options['ga_crossdomain_list'] = ''; $flag = true; } if (!isset($this->options['ga_author_dimindex'])) { $this->options['ga_author_dimindex'] = 0; $flag = true; } if (!isset($this->options['ga_category_dimindex'])) { $this->options['ga_category_dimindex'] = 0; $flag = true; } if (!isset($this->options['ga_user_dimindex'])) { $this->options['ga_user_dimindex'] = 0; $flag = true; } if (!isset($this->options['ga_pubyear_dimindex'])) { $this->options['ga_pubyear_dimindex'] = 0; $flag = true; } if (!isset($this->options['ga_event_affiliates'])) { $this->options['ga_event_affiliates'] = '/out/'; $flag = true; } if (!isset($this->options['ga_aff_tracking'])) { $this->options['ga_aff_tracking'] = 0; $flag = true; } if (!isset($this->options['ga_hash_tracking'])) { $this->options['ga_hash_tracking'] = 0; $flag = true; } if (!isset($this->options['item_reports'])) { $this->options['item_reports'] = 1; $flag = true; } if (!isset($this->options['dashboard_widget'])) { $this->options['dashboard_widget'] = 1; $flag = true; } if (isset($this->options['ga_tracking_code'])) { unset($this->options['ga_tracking_code']); $flag = true; } if (isset($this->options['ga_dash_jailadmins'])) { if (isset($this->options['ga_dash_jailadmins'])) { // invert disable with enable and change option name $this->options['switch_profile'] = 0; unset($this->options['ga_dash_jailadmins']); $flag = true; } else { $this->options['switch_profile'] = 1; unset($this->options['ga_dash_jailadmins']); $flag = true; } } if ($flag) { $this->set_plugin_options(false); } }