/**
  * 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 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])) . ' &#8658; ' . 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();
    }
Beispiel #3
0
 /**
  * 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]));
                 //  . ' &#8658; ' . $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);
     }
 }