├── .gitignore ├── .wordpress-org ├── icon-128x128.jpg ├── icon-256x256.jpg ├── screenshot-1.png ├── screenshot-2.png ├── screenshot-3.png └── banner-772x250.png ├── languages ├── yandex-metrica-ru_RU.mo ├── yandex-metrica-tr_TR.mo ├── yandex-metrica.pot ├── yandex-metrica-ru_RU.po └── yandex-metrica-tr_TR.po ├── uninstall.php ├── composer.json ├── .github └── workflows │ ├── plugin-deploy.yml │ └── plugin-update.yml ├── includes ├── constants.php ├── wp-stack-plugin.php ├── utils.php ├── Yandex_Oauth.php ├── Encryption.php ├── widget.php └── Yandex_Metrica.php ├── .distignore ├── README.md ├── templates ├── tracker-js-new.php ├── tracker-js.php ├── dashboard-charts-js.php ├── dashboard-widget.php └── settings.php ├── readme.txt └── yandex-metrica.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Thumbs.db 3 | wp-cli.local.yml 4 | node_modules/ 5 | .idea/ -------------------------------------------------------------------------------- /.wordpress-org/icon-128x128.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mustafauysal/yandex-metrica/HEAD/.wordpress-org/icon-128x128.jpg -------------------------------------------------------------------------------- /.wordpress-org/icon-256x256.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mustafauysal/yandex-metrica/HEAD/.wordpress-org/icon-256x256.jpg -------------------------------------------------------------------------------- /.wordpress-org/screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mustafauysal/yandex-metrica/HEAD/.wordpress-org/screenshot-1.png -------------------------------------------------------------------------------- /.wordpress-org/screenshot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mustafauysal/yandex-metrica/HEAD/.wordpress-org/screenshot-2.png -------------------------------------------------------------------------------- /.wordpress-org/screenshot-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mustafauysal/yandex-metrica/HEAD/.wordpress-org/screenshot-3.png -------------------------------------------------------------------------------- /.wordpress-org/banner-772x250.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mustafauysal/yandex-metrica/HEAD/.wordpress-org/banner-772x250.png -------------------------------------------------------------------------------- /languages/yandex-metrica-ru_RU.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mustafauysal/yandex-metrica/HEAD/languages/yandex-metrica-ru_RU.mo -------------------------------------------------------------------------------- /languages/yandex-metrica-tr_TR.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mustafauysal/yandex-metrica/HEAD/languages/yandex-metrica-tr_TR.mo -------------------------------------------------------------------------------- /uninstall.php: -------------------------------------------------------------------------------- 1 | sanitize_method( $hook ); 8 | $args = func_get_args(); 9 | unset( $args[0] ); 10 | foreach( (array) $args as $arg ) { 11 | if ( is_int( $arg ) ) 12 | $priority = $arg; 13 | else 14 | $method = $arg; 15 | } 16 | return add_action( $hook, array( $this, $method ), $priority, 999 ); 17 | } 18 | 19 | private function sanitize_method( $method ) { 20 | return str_replace( array( '.', '-' ), array( '_DOT_', '_DASH_' ), $method ); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /.distignore: -------------------------------------------------------------------------------- 1 | # A set of files you probably don't want in your WordPress.org distribution 2 | .distignore 3 | .editorconfig 4 | .git 5 | .gitignore 6 | .gitlab-ci.yml 7 | .travis.yml 8 | .DS_Store 9 | .browserslistrc 10 | .eslintrc.json 11 | .eslintignore 12 | .eslintrc.js 13 | .npmrc 14 | .nvmrc 15 | .stylelintrc 16 | .stylelintignore 17 | .husky 18 | babel.config.js 19 | Thumbs.db 20 | behat.yml 21 | bin 22 | circle.yml 23 | composer.json 24 | composer.lock 25 | Gruntfile.js 26 | package.json 27 | package-lock.json 28 | phpunit.xml 29 | phpunit.xml.dist 30 | multisite.xml 31 | multisite.xml.dist 32 | phpcs.ruleset.xml 33 | phpcs.xml 34 | README.md 35 | wp-cli.local.yml 36 | tests 37 | node_modules 38 | *.zip 39 | *.tar.gz 40 | tests 41 | config 42 | postcss.config.js 43 | yarn.lock 44 | .wordpress-org 45 | .github 46 | LICENSE.md 47 | vendor 48 | .husky 49 | .lintstagedrc.json 50 | lerna.json 51 | hookdoc-conf.json 52 | *.js.LICENSE.txt 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Yandex Metrica](https://wordpress.org/plugins/yandex-metrica/) # 2 | 3 | ![Support Level](https://img.shields.io/badge/support-active-green.svg) [![Release Version](https://img.shields.io/wordpress/plugin/v/yandex-metrica?label=Release%20Version)](https://github.com/mustafauysal/yandex-metrica/releases) ![WordPress tested up to version](https://img.shields.io/wordpress/plugin/tested/yandex-metrica?label=WordPress) ![Required PHP Version](https://img.shields.io/wordpress/plugin/required-php/yandex-metrica?label=PHP) 4 | 5 | ### Welcome to our GitHub Repository 6 | 7 | The best Yandex Metrica plugin for WordPress. 8 | 9 | ### Features ### 10 | 11 | - Easy to manage counter's tracking options. 12 | - Role based user tracking 13 | - Dashboard widget that displays Metrica graphics,, summary of site usage, top pages etc.. 14 | - Role based user access for the displaying dashboard widget 15 | - Basic mode is ready! If you don't want to give API access, you can try basic mode. 16 | - i18n support: Completely translation ready! 17 | 18 | 19 | ## Support ## 20 | This is a developer's portal for Yandex Metrica and should _not_ be used for support. Please visit the [support forums](https://wordpress.org/support/plugin/yandex-metrica/) if you need to submit a support request. -------------------------------------------------------------------------------- /templates/tracker-js-new.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /includes/utils.php: -------------------------------------------------------------------------------- 1 | "", 21 | 'webvisor' => true, 22 | 'clickmap' => true, 23 | 'tracklinks' => true, 24 | 'accurate_track' => false, 25 | 'track_hash' => false, 26 | 'track-logged-in' => true, 27 | 'untrack-roles' => array( "administrator" ), 28 | 'widget-access-roles' => array( "administrator" ), 29 | 'backward' => false, 30 | 'new_yandex_code' => true, // @since 1.7, 31 | 'dispatch_ecommerce' => false, // @since 1.8.1 32 | 'ecommerce_container_name' => 'dataLayer', // @since 1.8.1 33 | 'tracker-address' => "", 34 | ); 35 | 36 | return wp_parse_args( get_option( \YandexMetrica\Constants\OPTION ), $defaults ); 37 | } 38 | 39 | 40 | /** 41 | * Get sensitive data in decrypted form 42 | * 43 | * @param string $field field name 44 | * 45 | * @return bool|mixed|string 46 | */ 47 | function get_decrypted_setting( $field ) { 48 | $settings = \YandexMetrica\Utils\get_settings(); 49 | $value = isset( $settings[ $field ] ) ? $settings[ $field ] : ''; 50 | 51 | // decrypt the value 52 | $encryption = new Encryption(); 53 | $decrypted_value = $encryption->decrypt( $value ); 54 | if ( false !== $decrypted_value ) { 55 | return $decrypted_value; 56 | } 57 | 58 | return $value; 59 | } 60 | -------------------------------------------------------------------------------- /templates/tracker-js.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 32 | 35 | -------------------------------------------------------------------------------- /includes/Yandex_Oauth.php: -------------------------------------------------------------------------------- 1 | app_id = $app_id; 26 | $this->app_secret = $app_secret; 27 | } 28 | 29 | /** 30 | * @param int $confirmation_code 31 | * 32 | * @return bool 33 | */ 34 | public function connect_oauth_server( $confirmation_code ) { 35 | 36 | $response = wp_remote_post( self::OAUTH_SERVER, array( 37 | 'method' => 'POST', 38 | 'timeout' => 45, 39 | 'httpversion' => '1.1', 40 | 'body' => array( 41 | 'grant_type' => 'authorization_code', 42 | 'code' => $confirmation_code, 43 | 'client_id' => $this->app_id, 44 | 'client_secret' => $this->app_secret, 45 | ), 46 | 'sslverify' => true, 47 | ) ); 48 | 49 | if ( is_wp_error( $response ) ) { 50 | return false; 51 | } 52 | 53 | $http_code = $response["response"]["code"]; 54 | 55 | if ( ( $http_code != '200' ) && ( $http_code != '400' ) ) { 56 | $this->error = $http_code; 57 | 58 | return false; 59 | } 60 | 61 | $result = json_decode( $response["body"], true ); 62 | 63 | if ( empty( $result['error'] ) ) { 64 | $this->access_token = $result['access_token']; 65 | 66 | return true; 67 | } 68 | 69 | 70 | $this->error = $result['error']; 71 | 72 | return false; 73 | } 74 | 75 | /** 76 | * @return bool 77 | */ 78 | public function check_access() { 79 | if ( ! empty( $this->access_token ) && ( empty( $this->error ) ) ) { 80 | return true; 81 | } 82 | 83 | $this->error = 'expired_token'; 84 | 85 | return false; 86 | } 87 | 88 | /** 89 | * What is the problem? 90 | * 91 | * @return string 92 | */ 93 | public function get_error() { 94 | if ( ! empty( $this->error ) ) { 95 | 96 | switch ( $this->error ) { 97 | case 'invalid_request': 98 | return 'Incorrect request format.'; 99 | 100 | case 'invalid_grant': 101 | return 'Invalid or expired authorization code.'; 102 | 103 | case 'unsupported_grant_type': 104 | return 'Incorrect value for the grant_type parameter.'; 105 | 106 | case 'invalid_client': 107 | return 'Invalid app_id or app_secret'; 108 | 109 | case '404': 110 | return 'Requested url not found'; 111 | 112 | case '403': 113 | return 'Forbidden zone'; 114 | 115 | case '500': 116 | return 'The server encountered an unexpected condition that prevents it from fulfilling the request'; 117 | 118 | default: 119 | return 'ERROR: ' . $this->error; 120 | } 121 | 122 | } 123 | 124 | } 125 | 126 | /** 127 | * @return mixed Access token 128 | */ 129 | public function get_access_token() { 130 | if ( $this->check_access() ) { 131 | return $this->access_token; 132 | } 133 | } 134 | 135 | 136 | } -------------------------------------------------------------------------------- /includes/Encryption.php: -------------------------------------------------------------------------------- 1 | key = $this->get_default_key(); 40 | $this->salt = $this->get_default_salt(); 41 | } 42 | 43 | /** 44 | * Encrypts a value. 45 | * If a user-based key is set, that key is used. Otherwise the default key is used. 46 | * 47 | * @param string $value Value to encrypt. 48 | * 49 | * @return string|bool Encrypted value, or false on failure. 50 | * @since 1.0 51 | */ 52 | public function encrypt( $value ) { 53 | if ( ! extension_loaded( 'openssl' ) ) { 54 | return $value; 55 | } 56 | 57 | $method = 'aes-256-ctr'; 58 | $ivlen = openssl_cipher_iv_length( $method ); 59 | $iv = openssl_random_pseudo_bytes( $ivlen ); 60 | 61 | $raw_value = openssl_encrypt( $value . $this->salt, $method, $this->key, 0, $iv ); 62 | if ( ! $raw_value ) { 63 | return false; 64 | } 65 | 66 | return base64_encode( $iv . $raw_value ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode 67 | } 68 | 69 | /** 70 | * Decrypts a value. 71 | * If a user-based key is set, that key is used. Otherwise the default key is used. 72 | * 73 | * @param string $raw_value Value to decrypt. 74 | * 75 | * @return string|bool Decrypted value, or false on failure. 76 | * @since 1.0 77 | */ 78 | public function decrypt( $raw_value ) { 79 | if ( ! extension_loaded( 'openssl' ) ) { 80 | return $raw_value; 81 | } 82 | 83 | $raw_value = base64_decode( $raw_value, true ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode 84 | 85 | $method = 'aes-256-ctr'; 86 | $ivlen = openssl_cipher_iv_length( $method ); 87 | $iv = substr( $raw_value, 0, $ivlen ); 88 | 89 | $raw_value = substr( $raw_value, $ivlen ); 90 | 91 | $value = openssl_decrypt( $raw_value, $method, $this->key, 0, $iv ); 92 | if ( ! $value || substr( $value, - strlen( $this->salt ) ) !== $this->salt ) { 93 | return false; 94 | } 95 | 96 | return substr( $value, 0, - strlen( $this->salt ) ); 97 | } 98 | 99 | /** 100 | * Gets the default encryption key 101 | * 102 | * @return string Default (not user-based) encryption key. 103 | * @since 1.0 104 | */ 105 | private function get_default_key() { 106 | if ( defined( 'YANDEX_METRICA_ENCRYPTION_KEY' ) && '' !== YANDEX_METRICA_ENCRYPTION_KEY ) { 107 | return YANDEX_METRICA_ENCRYPTION_KEY; 108 | } 109 | 110 | if ( defined( 'LOGGED_IN_KEY' ) && '' !== LOGGED_IN_KEY ) { 111 | return LOGGED_IN_KEY; 112 | } 113 | 114 | // If this is reached, you're either not on a live site or have a serious security issue. 115 | return 'this-is-not-a-secret-key'; 116 | } 117 | 118 | /** 119 | * Gets the encryption salt 120 | * 121 | * @return string Encryption salt. 122 | * @since 1.0 123 | */ 124 | private function get_default_salt() { 125 | if ( defined( 'YANDEX_METRICA_ENCRYPTION_SALT' ) && '' !== YANDEX_METRICA_ENCRYPTION_SALT ) { 126 | return YANDEX_METRICA_ENCRYPTION_SALT; 127 | } 128 | 129 | if ( defined( 'LOGGED_IN_SALT' ) && '' !== LOGGED_IN_SALT ) { 130 | return LOGGED_IN_SALT; 131 | } 132 | 133 | // If this is reached, you're either not on a live site or have a serious security issue. 134 | return 'this-is-not-a-secret-salt'; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /templates/dashboard-charts-js.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /includes/widget.php: -------------------------------------------------------------------------------- 1 | defaults = array( 14 | 'title' => '', 15 | 'time' => 'today', 16 | 'show_page_views' => true, 17 | 'show_visits' => true, 18 | 'show_visitors' => true 19 | ); 20 | 21 | 22 | parent::__construct( 23 | 'metrica_widget', 24 | 'Metrica Widget', 25 | array( 'description' => __( 'Display statistics within selected period.', 'yandex-metrica' ), ) // Args 26 | ); 27 | } 28 | 29 | 30 | public function widget( $args, $instance ) { 31 | $instance = wp_parse_args( (array) $instance, $this->defaults ); // merge options with default 32 | 33 | $title = apply_filters( 'widget_title', $instance['title'] ); 34 | 35 | echo wp_kses_post( $args['before_widget'] ); 36 | if ( ! empty( $title ) ) { 37 | echo wp_kses_post( $args['before_title'] . $title . $args['after_title'] ); 38 | } 39 | 40 | 41 | if ( $instance['time'] == "week" ) { 42 | $start_date = date( 'Ymd', strtotime( "-6 days" ) ); 43 | $end_date = date( 'Ymd' ); 44 | } 45 | elseif ( $instance['time'] == 'month' ) { 46 | $start_date = date( 'Ymd', strtotime( "-1 month" ) );; 47 | $end_date = date( 'Ymd' ); 48 | } 49 | else { 50 | $start_date = date( 'Ymd' ); 51 | $end_date = date( 'Ymd' ); 52 | } 53 | 54 | printf( __( '

Metrica statistics for %s

', 'yandex-metrica' ), __( ucfirst( $instance["time"] ), 'yandex-metrica' ) ); 55 | $main_options = \YandexMetrica\Utils\get_settings(); 56 | $metrica_api = new Yandex_Metrica( \YandexMetrica\Utils\get_decrypted_setting( 'access_token' ) ); 57 | $results = $metrica_api->get_counter_statistics( $main_options['counter_id'], $start_date, $end_date, "total" ); 58 | 59 | $instance["pageviews"] = $results["pageviews"]; 60 | $instance["visits"] = $results["visits"]; 61 | $instance["visitors"] = $results["visitors"]; 62 | 63 | 64 | if ( $instance['show_page_views'] === true && ( ! empty( $instance["pageviews"] ) ) ) { 65 | printf( __( 'Page Views: %d
', 'yandex-metrica' ), $instance['pageviews'] ); 66 | } 67 | if ( $instance['show_visits'] === true && ! empty( $instance["visits"] ) ) { 68 | printf( __( 'Visits: %d
', 'yandex-metrica' ), $instance['visits'] ); 69 | } 70 | if ( $instance['show_visitors'] === true && ! empty( $instance["visitors"] ) ) { 71 | printf( __( 'Visitors: %d
', 'yandex-metrica' ), $instance['visitors'] ); 72 | } 73 | 74 | echo wp_kses_post( $args['after_widget'] ); 75 | } 76 | 77 | 78 | public function form( $instance ) { 79 | $instance = wp_parse_args( (array) $instance, $this->defaults ); 80 | 81 | if ( isset( $instance['title'] ) ) { 82 | $title = $instance['title']; 83 | } 84 | ?> 85 | 86 |

87 | 88 | 89 |

90 |

91 | 92 | 97 |

98 |

99 |
101 |
103 |
105 |

106 | Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score 45 | * Magic Login Pro – Easy, secure, and passwordless authentication for WordPress. 46 | * Easy Text-to-Speech for WordPress – Transform your textual content into high-quality synthesized speech with Amazon Polly. 47 | * Handywriter – AI-powered writing assistant that can help you create content for your WordPress. 48 | * PaddlePress PRO – Paddle Plugin for WordPress 49 | 50 | 51 | == Installation == 52 | 53 | Extract the zip file, and place the contents in the `wp-content/plugins/` directory of your WordPress installation and then activate the Plugin from admin's Plugins page. 54 | 55 | == Frequently Asked Questions == 56 | 57 | = What is metrica? = 58 | Metrica is a powerful analytics tool that provided by Yandex. 59 | 60 | = Is it free? = 61 | Definitely, metrica service and this plugin are totally free. 62 | 63 | = Can I see statistics on the WordPress dashboard? = 64 | Yes! (You have to use advanced mode, this feature needs API access) 65 | 66 | = I can see dashboard widget but no graph? = 67 | It's likely that your counter is not working correctly, please check counter status on the official metrica website. Sometimes we can't retrieve the statistical data via API, especially on the fresh counters. 68 | 69 | = Everything done, but metrica service doesn't work for me? = 70 | Yandex Metrica plugin uses wp_head hook for the adds necessary tracking code. Please ensure that your theme has a wp_footer hook. 71 | 72 | == Screenshots == 73 | 74 | 1. Select mode, basic mode for who don't want to use metrica api. But advanced mode recommended! 75 | 2. Displaying graph with metrica results. 76 | 3. Settings page. 77 | 78 | == Changelog == 79 | 80 | = 2.0.2 (Feb 23, 2025) = 81 | - Fix authorization issue 82 | - Bump tested WP version to 6.7 83 | 84 | = 2.0.1 (May 15, 2024) = 85 | - Bump tested WP version to 6.5 86 | 87 | = 2.0 (October 18, 2023) = 88 | - Dashboad widget improvements 89 | - Improved accuracy of the stats 90 | - Added encryption for the access token 91 | - Fix jQuery deprecations 92 | - Bump required WP version to 5.0 93 | - Tested with WordPress 6.4 94 | 95 | = 1.9.3 (November 6, 2022) = 96 | - minor tweaks & improvements 97 | - Added uninstaller 98 | - tested with WordPress 6.1 99 | 100 | = 1.9.2 = 101 | - fix valid counter control 102 | - tested with WordPress 5.9 103 | 104 | = 1.9.1 = 105 | - hotfix: uppercase Chart.min.js 106 | 107 | = 1.9 = 108 | - chart.js update 109 | - Improved security 110 | - New filters: `yandex_metrica_app_id` and `yandex_metrica_app_secret` 111 | 112 | = 1.8.3 = 113 | - fixed an XSS 114 | - tested with WordPress 5.8 115 | 116 | = 1.8.2 = 117 | - Add composer support 118 | - tested with WordPress 5.5 119 | 120 | = 1.8.1 = 121 | - an option added for the dispatching e-commerce data 122 | 123 | = 1.8 = 124 | - Authorization method changed, URL parameters no longer acccepted 125 | - use wp_head instead wp_footer for the tracking code 126 | - tested with WordPress 5.1.x 127 | 128 | = 1.7 = 129 | - switched to new metrica tracking code by default 130 | - added an option for [new Yandex's tracking code](https://yandex.com/support/metrika/code/counter-initialize.html) (props @ildarkhasanshin) 131 | - Better tracker-address handling. (Don't save default addresses.) 132 | - tested with WordPress 5.x 133 | 134 | = 1.6.3 = 135 | - now users are able to change Tracker JS address 136 | - new filter `yandex_metrica_noscript_img_base` added 137 | 138 | = 1.6.2 = 139 | - prevent (possible) chart.js conflict with page builder plugins. Props @zzsnowballzz 140 | 141 | = 1.6.1 = 142 | - prevent inline js loading globally. Props Makaka Games 143 | - script handler renamed 144 | - chart options updated; bar charts start from zero and line charts are using index mode for tooltips 145 | 146 | = 1.6 = 147 | - charting library changed. (Switched to Chart.js) 148 | - daily stats using bar type 149 | - minor tweaks 150 | 151 | = 1.5 = 152 | - Metrica API upgraded, fixes api related problems 153 | - `sslverify` parameter set to true 154 | - UI improvements 155 | - Informer widget address update 156 | - Widget: showing visitors fix. Props Эльвира Капитонова 157 | - requires at least WordPress 3.7 158 | 159 | = 1.4.3 = 160 | - minor bug fix about HTTP request 161 | 162 | = 1.4.2 = 163 | - minor bug fixes 164 | 165 | = 1.4.1 = 166 | - array-multisort bug fix. Props Николай Астраханцев 167 | 168 | = 1.4 = 169 | - Text Domain changed 170 | - Nonces added to settings page 171 | - Wrong option name fixed. Props [romapad](https://github.com/romapad) 172 | 173 | = 1.3 = 174 | - Updated metrica tracking code 175 | - New hash tracking option added 176 | 177 | = 1.2 = 178 | - Improved error checking for API request 179 | - Possible connectivity case added 180 | - Minor tweaks 181 | 182 | = 1.1.2 = 183 | - Russian language pack added. Props Ксения Рыбка and oleg0789 184 | - API connectivity check improved 185 | - Minor fixes 186 | 187 | = 1.1.1 = 188 | - Dashboard widget daily order fixed 189 | 190 | = 1.1 = 191 | - Dashboard widget UI improvements 192 | - Bug fixes 193 | 194 | = 1.0.2 = 195 | - Capability checking before display temporary dashboard widget 196 | 197 | = 1.0.1 = 198 | - Closure function removed 199 | - Typo fix 200 | 201 | = 1.0 = 202 | - Metrica API integration 203 | - Backward compatibility mode 204 | - Tracking by user role 205 | - Dashboard widget 206 | - New widget, informer widget still exist 207 | - Better localization 208 | - Performance improvements 209 | - Special thanks to Yandex Team for all support. 210 | 211 | = 0.1.3 = 212 | - Minor bug fixes 213 | 214 | = 0.1.2 = 215 | - Bug fix - about options 216 | 217 | = 0.1.1 = 218 | - bug fix - header output 219 | 220 | = 0.1 = 221 | - Initial release. 222 | 223 | == Upgrade Notice == 224 | 225 | = 1.0 = 226 | 227 | Including major changes, recommended update! 228 | 229 | = 1.5 = 230 | 231 | Metrica api upgraded, if you get authentication related problems reset plugin settings and connect to API again (that will generate new token) 232 | 233 | = 1.7 = 234 | 235 | Switched to the new tracking code by default. You can turn off from the options. 236 | 237 | = 1.8.3 = 238 | 239 | Security release. Update the plugin ASAP! -------------------------------------------------------------------------------- /templates/dashboard-widget.php: -------------------------------------------------------------------------------- 1 | 4 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 |
22 |

23 | 24 | 25 | 28 | 37 | 40 | 49 | 50 | 51 | 52 | 53 | 56 | 64 | 67 | 75 | 76 | 77 | 78 | 79 | 82 | 90 | 93 | 102 | 103 | 104 | 105 |
26 | : 27 | 29 | 36 | 38 | : 39 | 41 | 48 |
54 | : 55 | 57 | 63 | 65 | : 66 | 68 | 74 |
80 | : 81 | 83 | 89 | 91 | : 92 | 94 | 101 |
106 | 107 | 108 | 136 | 137 | 138 |
139 |
140 |

141 |
142 | 145 |
146 |
147 | 148 |
149 |
    150 | 151 | 152 | 153 |
  1. 154 | "> - 155 | 156 |
  2. 157 | 158 | 159 | 160 | 161 | 162 |
163 |
164 |
165 | 166 | 167 |
168 |
169 |

170 |
171 | 174 |
175 |
176 | 177 |
178 |
    179 | 180 | 181 | 182 |
  1. 183 | - 184 | 185 |
  2. 186 | 187 | 188 | 189 | 190 | 191 |
192 | 193 |
194 |
195 | 196 |
197 | 198 | 211 | 212 | -------------------------------------------------------------------------------- /languages/yandex-metrica.pot: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2023 Mustafa Uysal 2 | # This file is distributed under the GPLv2 (or later). 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: Yandex Metrica 2.0\n" 6 | "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/yandex-metrica\n" 7 | "Last-Translator: FULL NAME \n" 8 | "Language-Team: LANGUAGE \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "POT-Creation-Date: 2023-10-18T18:24:14+00:00\n" 13 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 | "X-Generator: WP-CLI 2.7.1\n" 15 | "X-Domain: yandex-metrica\n" 16 | 17 | #. Plugin Name of the plugin 18 | #: templates/settings.php:79 19 | #: yandex-metrica.php:71 20 | msgid "Yandex Metrica" 21 | msgstr "" 22 | 23 | #. Plugin URI of the plugin 24 | msgid "https://github.com/mustafauysal/yandex-metrica" 25 | msgstr "" 26 | 27 | #. Description of the plugin 28 | msgid "The best Yandex Metrica plugin for WordPress." 29 | msgstr "" 30 | 31 | #. Author of the plugin 32 | msgid "Mustafa Uysal" 33 | msgstr "" 34 | 35 | #. Author URI of the plugin 36 | msgid "https://uysalmustafa.com" 37 | msgstr "" 38 | 39 | #: includes/widget.php:25 40 | msgid "Display statistics within selected period." 41 | msgstr "" 42 | 43 | #: includes/widget.php:54 44 | msgid "

Metrica statistics for %s

" 45 | msgstr "" 46 | 47 | #: includes/widget.php:65 48 | msgid "Page Views: %d
" 49 | msgstr "" 50 | 51 | #: includes/widget.php:68 52 | msgid "Visits: %d
" 53 | msgstr "" 54 | 55 | #: includes/widget.php:71 56 | msgid "Visitors: %d
" 57 | msgstr "" 58 | 59 | #: includes/widget.php:91 60 | msgid "Statistics for:" 61 | msgstr "" 62 | 63 | #: includes/widget.php:93 64 | msgid "Today" 65 | msgstr "" 66 | 67 | #: includes/widget.php:94 68 | msgid "Week" 69 | msgstr "" 70 | 71 | #: includes/widget.php:95 72 | msgid "Month" 73 | msgstr "" 74 | 75 | #: includes/widget.php:99 76 | msgid "Show Pageview" 77 | msgstr "" 78 | 79 | #: includes/widget.php:101 80 | msgid "Show Visits" 81 | msgstr "" 82 | 83 | #: includes/widget.php:103 84 | msgid "Show Visitors" 85 | msgstr "" 86 | 87 | #: templates/dashboard-charts-js.php:7 88 | msgid "Sorry, couldn't draw graph for selected period, please try different time period." 89 | msgstr "" 90 | 91 | #: templates/dashboard-charts-js.php:33 92 | msgid "Pageviews" 93 | msgstr "" 94 | 95 | #: templates/dashboard-charts-js.php:44 96 | #: templates/dashboard-widget.php:26 97 | msgid "Visits" 98 | msgstr "" 99 | 100 | #: templates/dashboard-charts-js.php:55 101 | msgid "Unique" 102 | msgstr "" 103 | 104 | #: templates/dashboard-charts-js.php:77 105 | msgid "Metrica Traffic" 106 | msgstr "" 107 | 108 | #: templates/dashboard-charts-js.php:109 109 | msgid "View Full Report" 110 | msgstr "" 111 | 112 | #: templates/dashboard-widget.php:6 113 | msgid "Daily" 114 | msgstr "" 115 | 116 | #: templates/dashboard-widget.php:9 117 | msgid "Weekly" 118 | msgstr "" 119 | 120 | #: templates/dashboard-widget.php:10 121 | msgid "Monthly" 122 | msgstr "" 123 | 124 | #: templates/dashboard-widget.php:22 125 | msgid "Site Usage" 126 | msgstr "" 127 | 128 | #: templates/dashboard-widget.php:33 129 | #: templates/dashboard-widget.php:45 130 | #: templates/dashboard-widget.php:60 131 | #: templates/dashboard-widget.php:71 132 | #: templates/dashboard-widget.php:86 133 | #: templates/dashboard-widget.php:98 134 | #: templates/dashboard-widget.php:130 135 | #: templates/dashboard-widget.php:159 136 | #: templates/dashboard-widget.php:188 137 | msgid "None" 138 | msgstr "" 139 | 140 | #: templates/dashboard-widget.php:38 141 | msgid "New Visitors" 142 | msgstr "" 143 | 144 | #: templates/dashboard-widget.php:54 145 | msgid "Page Views" 146 | msgstr "" 147 | 148 | #: templates/dashboard-widget.php:65 149 | msgid "Session depth" 150 | msgstr "" 151 | 152 | #: templates/dashboard-widget.php:80 153 | msgid "Visitors" 154 | msgstr "" 155 | 156 | #: templates/dashboard-widget.php:91 157 | msgid "Avg. Time on Site" 158 | msgstr "" 159 | 160 | #: templates/dashboard-widget.php:110 161 | msgid "Popular Pages" 162 | msgstr "" 163 | 164 | #: templates/dashboard-widget.php:126 165 | msgid "%d View" 166 | msgid_plural "%d Views" 167 | msgstr[0] "" 168 | msgstr[1] "" 169 | 170 | #: templates/dashboard-widget.php:140 171 | msgid "Top Referrers" 172 | msgstr "" 173 | 174 | #: templates/dashboard-widget.php:155 175 | #: templates/dashboard-widget.php:184 176 | msgid "%d Visit" 177 | msgid_plural "%d Visits" 178 | msgstr[0] "" 179 | msgstr[1] "" 180 | 181 | #: templates/dashboard-widget.php:169 182 | msgid "Search Terms" 183 | msgstr "" 184 | 185 | #: templates/settings.php:8 186 | msgid "Cheatin, uh?" 187 | msgstr "" 188 | 189 | #: templates/settings.php:15 190 | msgid "Successfully connected to Yandex Server" 191 | msgstr "" 192 | 193 | #: templates/settings.php:17 194 | msgid "Something went wrong. Please check your confirmation code!" 195 | msgstr "" 196 | 197 | #: templates/settings.php:52 198 | msgid "Options Saved!" 199 | msgstr "" 200 | 201 | #: templates/settings.php:55 202 | msgid "Please enter a valid counter code!" 203 | msgstr "" 204 | 205 | #: templates/settings.php:68 206 | msgid "All options cleared!" 207 | msgstr "" 208 | 209 | #: templates/settings.php:82 210 | msgid "You need sign in to Yandex and grant this plugin access to your Yandex Metrica account." 211 | msgstr "" 212 | 213 | #: templates/settings.php:83 214 | msgid "https://oauth.yandex.com/" 215 | msgstr "" 216 | 217 | #: templates/settings.php:84 218 | msgid "Click here to getting confirmation code" 219 | msgstr "" 220 | 221 | #: templates/settings.php:88 222 | msgid "Enter Confirmation code here" 223 | msgstr "" 224 | 225 | #: templates/settings.php:89 226 | #: templates/settings.php:220 227 | msgid "Save" 228 | msgstr "" 229 | 230 | #: templates/settings.php:93 231 | msgid "If you don't want to use API, you can use basic mode." 232 | msgstr "" 233 | 234 | #: templates/settings.php:94 235 | msgid "Basic Mode (Compatible with Backward)" 236 | msgstr "" 237 | 238 | #: templates/settings.php:100 239 | msgid "Counter:" 240 | msgstr "" 241 | 242 | #: templates/settings.php:107 243 | msgid "Temporary, getting connectivity problem.!" 244 | msgstr "" 245 | 246 | #: templates/settings.php:112 247 | msgid "Enter counter number" 248 | msgstr "" 249 | 250 | #: templates/settings.php:115 251 | msgid "Tracking Settings" 252 | msgstr "" 253 | 254 | #: templates/settings.php:123 255 | msgid "Select tracking options" 256 | msgstr "" 257 | 258 | #: templates/settings.php:126 259 | msgid "Webvisor" 260 | msgstr "" 261 | 262 | #: templates/settings.php:128 263 | msgid "Track Clickmap" 264 | msgstr "" 265 | 266 | #: templates/settings.php:130 267 | msgid "Track Links, social sharing, file requests..." 268 | msgstr "" 269 | 270 | #: templates/settings.php:132 271 | msgid "Accurate Track Bounce" 272 | msgstr "" 273 | 274 | #: templates/settings.php:134 275 | msgid "Hash tracking in the browser's address bar" 276 | msgstr "" 277 | 278 | #: templates/settings.php:136 279 | msgid "Use new counter code" 280 | msgstr "" 281 | 282 | #: templates/settings.php:138 283 | msgid "Dispatch ecommerce data to Metrica" 284 | msgstr "" 285 | 286 | #: templates/settings.php:145 287 | msgid "Ecommerce Container" 288 | msgstr "" 289 | 290 | #: templates/settings.php:149 291 | msgid "Data container name for the collecting data from" 292 | msgstr "" 293 | 294 | #: templates/settings.php:155 295 | msgid "Track logged in users" 296 | msgstr "" 297 | 298 | #: templates/settings.php:159 299 | msgid "Yes" 300 | msgstr "" 301 | 302 | #: templates/settings.php:160 303 | msgid "No" 304 | msgstr "" 305 | 306 | #: templates/settings.php:167 307 | msgid "User roles to not track" 308 | msgstr "" 309 | 310 | #: templates/settings.php:180 311 | msgid "If a user is logged into with one of these roles, they won't track by metrica." 312 | msgstr "" 313 | 314 | #: templates/settings.php:186 315 | msgid "User roles to display dashboard widget" 316 | msgstr "" 317 | 318 | #: templates/settings.php:200 319 | msgid "Selected roles can display metrica statistic on the dashboard." 320 | msgstr "" 321 | 322 | #: templates/settings.php:208 323 | msgid "Tracker JS" 324 | msgstr "" 325 | 326 | #: templates/settings.php:212 327 | msgid "If you want to change watcher js address, use the field above." 328 | msgstr "" 329 | 330 | #: templates/settings.php:221 331 | msgid "Reset" 332 | msgstr "" 333 | 334 | #: yandex-metrica.php:115 335 | msgid "You do not have sufficient permissions to access this page." 336 | msgstr "" 337 | 338 | #: yandex-metrica.php:132 339 | #: yandex-metrica.php:135 340 | msgid "Metrica Statistics" 341 | msgstr "" 342 | 343 | #: yandex-metrica.php:142 344 | msgid "Oh no! There is nothing to display. Here Are the Possible Causes" 345 | msgstr "" 346 | 347 | #: yandex-metrica.php:143 348 | msgid "If selected a new counter (recently created), please give a few hours for verification. Please be patient." 349 | msgstr "" 350 | 351 | #: yandex-metrica.php:144 352 | msgid "Did you save options? You need to save options at least once after account confirmation." 353 | msgstr "" 354 | 355 | #: yandex-metrica.php:145 356 | msgid "Are you sure you selected the correct counter? Please confirm." 357 | msgstr "" 358 | 359 | #: yandex-metrica.php:146 360 | msgid "Did you change your Yandex password? If changed, you need to re-authorize this plugin." 361 | msgstr "" 362 | 363 | #: yandex-metrica.php:147 364 | msgid "Temporary, connectivity problem!" 365 | msgstr "" 366 | 367 | #: yandex-metrica.php:274 368 | msgid "Add metrica Informer to your sidebar, share daily statistics" 369 | msgstr "" 370 | -------------------------------------------------------------------------------- /includes/Yandex_Metrica.php: -------------------------------------------------------------------------------- 1 | error = "Empty access token!"; 18 | } 19 | $this->access_token = $access_token; 20 | } 21 | 22 | /** 23 | * Fetch data via WordPress HTTP api 24 | * 25 | * @param $url 26 | * 27 | * @return mixed 28 | */ 29 | public function fetch_data( $url ) { 30 | 31 | $args = array( 32 | 'timeout' => 7, 33 | 'httpversion' => '1.1', 34 | 'sslverify' => true, 35 | 'headers' => array( 36 | 'Authorization' => 'OAuth '.$this->access_token 37 | ) 38 | ); 39 | 40 | $response = wp_remote_get( $url, $args ); 41 | 42 | if ( is_wp_error( $response ) ) { 43 | $this->error = "HTTP Request problem"; 44 | 45 | return false; 46 | } 47 | 48 | if ( isset( $response['response']['message'] ) && 'OK' != $response['response']['message'] ) { 49 | $this->error = "API connectivity problem."; 50 | 51 | return false; 52 | } 53 | 54 | return $response["body"]; 55 | } 56 | 57 | 58 | /** 59 | * Fetch counter lists 60 | * 61 | * @since 1.0 62 | * @return array|mixed counters 63 | */ 64 | public function get_all_counters() { 65 | 66 | $url = esc_url_raw( add_query_arg( array( 67 | ), 'https://api-metrika.yandex.com/management/v1/counters' ) ); 68 | 69 | $response = $this->fetch_data( $url ); 70 | $results = json_decode( $response, true ); 71 | 72 | return $results; 73 | } 74 | 75 | /** 76 | * How many counters are there? 77 | * 78 | * @return mixed 79 | * @since 1.0 80 | */ 81 | public function count_counters() { 82 | $counters = $this->get_all_counters(); 83 | 84 | return $counters["rows"]; 85 | } 86 | 87 | /** 88 | * Get all counters 89 | * 90 | * @return mixed | array 91 | * @since 1.0 92 | */ 93 | public function get_counters() { 94 | $results = $this->get_all_counters(); 95 | 96 | return $results["counters"]; 97 | } 98 | 99 | /** 100 | * Check metrica counter installed correctly 101 | * 102 | * @param $counter_id int 103 | * 104 | * @return bool 105 | */ 106 | public function is_valid_counter( $counter_id ) { 107 | $current_counter = $this->fetch_counter( $counter_id ); 108 | 109 | if ( isset( $current_counter["counter"]["code_status"] ) && 'CS_OK' === $current_counter["counter"]["code_status"] ) { 110 | return true; 111 | } 112 | 113 | /** 114 | * The management API can return `CS_ERR_UNKNOWN` while counter is active. 115 | * 116 | * @since 1.9.2 117 | */ 118 | if ( isset( $current_counter["counter"]["status"] ) && 'Active' === $current_counter["counter"]["status"] ) { 119 | return true; 120 | } 121 | 122 | return false; 123 | } 124 | 125 | /** 126 | * Fetch counter' all data 127 | * 128 | * @see http://api.yandex.com/metrika/doc/ref/reference/get-counter.xml 129 | * 130 | * @param $counter_id 131 | * 132 | * @return array|mixed 133 | * @since 1.0 134 | */ 135 | public function fetch_counter( $counter_id ) { 136 | $results = get_transient( 'metrica_counter_' . self::TRANSIENT_VERSION . '_' . $counter_id ); 137 | 138 | if ( ! $results ) { 139 | $counter_url = 'https://api-metrika.yandex.com/management/v1/counter/' . $counter_id; 140 | $data = $this->fetch_data( $counter_url ); 141 | $results = json_decode( $data, true ); 142 | set_transient( 'metrica_counter_' . self::TRANSIENT_VERSION . '_' . $counter_id, $results, 720 ); 143 | } 144 | 145 | return $results; 146 | } 147 | 148 | 149 | public function get_counter_name( $counter_id ) { 150 | $current_counter = $this->fetch_counter( $counter_id ); 151 | 152 | return $current_counter["counter"]["name"]; 153 | } 154 | 155 | 156 | public function get_counter_statistics( $counter_id, $start_date, $end_date, $stats_type = null ) { 157 | $stats = get_transient( 'counter_statistics_' . self::TRANSIENT_VERSION . '_' . $counter_id . '_' . $start_date . $end_date ); 158 | 159 | if ( ! $stats ) { 160 | $stats_url = esc_url_raw( add_query_arg( array( 161 | 'date1' => $start_date, 162 | 'date2' => $end_date, 163 | 'metrics' => 'ym:s:pageviews,ym:s:visits,ym:s:users,ym:s:percentNewVisitors,ym:s:pageDepth,ym:s:avgVisitDurationSeconds', 164 | 'group' => 'day', 165 | 'ids' => $counter_id, 166 | ), 'https://api-metrika.yandex.com/stat/v1/data/bytime' ) ); 167 | 168 | 169 | $response = json_decode( $this->fetch_data( $stats_url ), true ); 170 | $daily = array(); 171 | 172 | $pageviews = $response['data'][0]['metrics'][0]; 173 | $visits = $response['data'][0]['metrics'][1]; 174 | $users = $response['data'][0]['metrics'][2]; 175 | $new_visitors = $response['data'][0]['metrics'][3]; 176 | $page_depth = $response['data'][0]['metrics'][4]; 177 | $duration = $response['data'][0]['metrics'][5]; 178 | 179 | foreach ( $response['time_intervals'] as $key => $time ) { 180 | $daily[ $time[0] ] = array( 181 | 'pageviews' => $pageviews[ $key ], 182 | 'visits' => $visits[ $key ], 183 | 'visitors' => $users[ $key ], 184 | 'new_visitors' => $new_visitors[ $key ], 185 | 'page_depth' => $page_depth[ $key ], 186 | 'duration' => $duration[ $key ], 187 | ); 188 | } 189 | 190 | $total = array( 191 | 'pageviews' => ( isset( $response['totals'][0] ) ? absint( array_sum( $response['totals'][0] ) ) : 0 ), 192 | 'visits' => ( isset( $response['totals'][1] ) ? absint( array_sum( $response['totals'][1] ) ) : 0 ), 193 | 'visitors' => ( isset( $response['totals'][2] ) ? absint( array_sum( $response['totals'][2] ) ) : 0 ), 194 | 'new_visitors' => ( isset( $response['totals'][3] ) ? floatval( array_sum( $response['totals'][3] ) / count( $response['totals'][3] ) ) : 0 ), 195 | 'page_depth' => ( isset( $response['totals'][4] ) ? floatval( array_sum( $response['totals'][4] ) / count( $response['totals'][4] ) ) : 0 ), 196 | 'duration' => ( isset( $response['totals'][5] ) ? floatval( array_sum( $response['totals'][5] ) / count( $response['totals'][5] ) ) : 0 ), 197 | ); 198 | 199 | $stats = array( 200 | 'daily' => $daily, 201 | 'total' => $total, 202 | ); 203 | 204 | set_transient( 'counter_statistics_' . self::TRANSIENT_VERSION . '_' . $counter_id . '_' . $start_date . $end_date, $stats, 3600 ); 205 | } 206 | 207 | 208 | if ( ! is_null( $stats_type ) && array_key_exists( $stats_type, $stats ) ) { 209 | return $stats[ $stats_type ]; 210 | } 211 | 212 | return $stats; 213 | } 214 | 215 | 216 | public function get_popular_content( $counter_id, $start_date, $end_date, $per_page = 5 ) { 217 | $popular_content = get_transient( 'popular_content_' . self::TRANSIENT_VERSION . '_' . $counter_id . '_' . $start_date . $end_date ); 218 | 219 | if ( ! $popular_content ) { 220 | 221 | $stats_url = esc_url_raw( add_query_arg( array( 222 | 'date1' => $start_date, 223 | 'date2' => $end_date, 224 | 'dimensions' => 'ym:pv:URL', 225 | 'metrics' => 'ym:pv:pageviews', 226 | 'group' => 'day', 227 | 'ids' => $counter_id, 228 | 'limit' => $per_page, // @todo this parameter is not works, take a look later 229 | ), 'https://api-metrika.yandex.com/stat/v1/data/bytime' ) ); 230 | 231 | 232 | $popular_content_result = json_decode( $this->fetch_data( $stats_url ), true ); 233 | 234 | 235 | $popular_content = array(); 236 | 237 | foreach ( $popular_content_result['data'] as $data_key => $data ) { 238 | $popular_content[ $data_key ]['url'] = $data['dimensions'][0]['name']; 239 | $popular_content[ $data_key ]['pageviews'] = ( isset( $data['metrics'][0] ) ? array_sum( $data['metrics'][0]) : 0 ); 240 | if ( count( $popular_content ) >= $per_page ) { 241 | break; 242 | } 243 | } 244 | 245 | set_transient( 'popular_content_' . self::TRANSIENT_VERSION . '_' . $counter_id . '_' . $start_date . $end_date, $popular_content, 3600 ); 246 | } 247 | 248 | return $popular_content; 249 | } 250 | 251 | 252 | public function get_referal_sites( $counter_id, $start_date, $end_date, $per_page = 5 ) { 253 | $top_referrers = get_transient( 'top_referrers_' . self::TRANSIENT_VERSION . '_' . $counter_id . '_' . $start_date . $end_date ); 254 | 255 | if ( ! $top_referrers ) { 256 | 257 | $stats_url = esc_url_raw( add_query_arg( array( 258 | 'date1' => $start_date, 259 | 'date2' => $end_date, 260 | 'dimensions' => 'ym:s:referer', 261 | 'metrics' => 'ym:s:visits', 262 | 'group' => 'day', 263 | 'ids' => $counter_id, 264 | 'limit' => $per_page, 265 | ), 'https://api-metrika.yandex.com/stat/v1/data/bytime' ) ); 266 | 267 | 268 | $top_referrers_result = json_decode( $this->fetch_data( $stats_url ), true ); 269 | 270 | 271 | $top_referrers = array(); 272 | 273 | foreach ( $top_referrers_result['data'] as $data_key => $data ) { 274 | $top_referrers[ $data_key ]['url'] = $data['dimensions'][0]['name']; 275 | $top_referrers[ $data_key ]['visits'] = ( isset( $data['metrics'][0] ) ? array_sum( $data['metrics'][0]) : 0 ); 276 | if ( count( $top_referrers ) >= $per_page ) { 277 | break; 278 | } 279 | } 280 | 281 | set_transient( 'top_referrers_' . self::TRANSIENT_VERSION . '_' . $counter_id . '_' . $start_date . $end_date, $top_referrers, 3600 ); 282 | } 283 | 284 | 285 | return $top_referrers; 286 | } 287 | 288 | 289 | public function get_search_terms( $counter_id, $start_date, $end_date, $per_page = 5 ) { 290 | 291 | $top_searches = get_transient( 'top_searches_' . self::TRANSIENT_VERSION . '_' . $counter_id . '_' . $start_date . $end_date ); 292 | 293 | if ( ! $top_searches ) { 294 | 295 | $stats_url = add_query_arg( array( 296 | 'date1' => $start_date, 297 | 'date2' => $end_date, 298 | 'dimensions' => 'ym:s:SearchPhrase', 299 | 'metrics' => 'ym:s:visits', 300 | 'group' => 'day', 301 | 'ids' => $counter_id, 302 | 'limit' => $per_page, 303 | ), 'https://api-metrika.yandex.com/stat/v1/data/bytime' ); 304 | 305 | 306 | $top_searches_result = json_decode( $this->fetch_data( $stats_url ), true ); 307 | 308 | $top_searches = array(); 309 | 310 | foreach ( $top_searches_result['data'] as $data_key => $data ) { 311 | $top_searches[ $data_key ]['name'] = $data['dimensions'][0]['name']; 312 | $top_searches[ $data_key ]['url'] = $data['dimensions'][0]['url']; 313 | $top_searches[ $data_key ]['visits'] = $top_searches_result['totals'][0][ $data_key ]; 314 | if ( count( $top_searches ) >= $per_page ) { 315 | break; 316 | } 317 | } 318 | 319 | set_transient( 'top_searches_' . self::TRANSIENT_VERSION . '_' . $counter_id . '_' . $start_date . $end_date, $top_searches, 3600 ); 320 | } 321 | 322 | 323 | return $top_searches; 324 | } 325 | 326 | 327 | } -------------------------------------------------------------------------------- /languages/yandex-metrica-ru_RU.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: Yandex Metrica 1.x\n" 4 | "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/yandex-metrica\n" 5 | "POT-Creation-Date: 2016-09-20 21:59:12+00:00\n" 6 | "PO-Revision-Date: 2018-03-09 00:52+0300\n" 7 | "Last-Translator: Mustafa Uysal \n" 8 | "Language-Team: \n" 9 | "Language: ru\n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | "X-Generator: Poedit 1.6.7\n" 14 | "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e;_n:1,2;_n_noop:1,2\n" 15 | "X-Poedit-Basepath: .\n" 16 | "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" 17 | "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" 18 | "X-Poedit-SourceCharset: UTF-8\n" 19 | "X-Poedit-SearchPath-0: ..\n" 20 | 21 | #: libs/widget.php:27 22 | msgid "Display statistics within selected period." 23 | msgstr "Показать статистику для выбранного периода" 24 | 25 | #: libs/widget.php:55 26 | msgid "

Metrica statistics for %s

" 27 | msgstr "

Статистика Метрики для %s

" 28 | 29 | #: libs/widget.php:66 30 | msgid "Page Views: %d
" 31 | msgstr "Просмотры страниц: %d
" 32 | 33 | #: libs/widget.php:68 34 | msgid "Visits: %d
" 35 | msgstr "Визиты: %d
" 36 | 37 | #: libs/widget.php:70 38 | msgid "Visitors: %d
" 39 | msgstr "Посетители: %d
" 40 | 41 | #: libs/widget.php:85 42 | msgid "Title:" 43 | msgstr "Заголовок" 44 | 45 | #: libs/widget.php:89 46 | msgid "Statistics for:" 47 | msgstr "Статистика за:" 48 | 49 | #: libs/widget.php:91 50 | msgid "Today" 51 | msgstr "сегодня" 52 | 53 | #: libs/widget.php:92 54 | msgid "Week" 55 | msgstr "неделю" 56 | 57 | #: libs/widget.php:93 58 | msgid "Month" 59 | msgstr "месяц" 60 | 61 | #: libs/widget.php:97 62 | msgid "Show Pageview" 63 | msgstr "Показать просмотры страниц" 64 | 65 | #: libs/widget.php:99 66 | msgid "Show Visits" 67 | msgstr "Показать посещения" 68 | 69 | #: libs/widget.php:101 70 | msgid "Show Visitors" 71 | msgstr "Показать посетителей" 72 | 73 | #: templates/dashboard-charts-js.php:10 74 | msgid "Metrica Traffic" 75 | msgstr "Трафик Метрики" 76 | 77 | #: templates/dashboard-charts-js.php:16 78 | msgid "Source" 79 | msgstr "Источник" 80 | 81 | msgid "Pageviews" 82 | msgstr "Просмотры страниц" 83 | 84 | #: templates/dashboard-charts-js.php:38 templates/dashboard-charts-js.php:52 85 | #: templates/dashboard-widget.php:20 86 | msgid "Visits" 87 | msgstr "Посещения" 88 | 89 | #: templates/dashboard-charts-js.php:60 90 | msgid "Unique" 91 | msgstr "Уникальные" 92 | 93 | #: templates/dashboard-widget.php:5 94 | msgid "Daily" 95 | msgstr "по дням" 96 | 97 | #: templates/dashboard-widget.php:8 98 | msgid "Weekly" 99 | msgstr "по неделям" 100 | 101 | #: templates/dashboard-widget.php:9 102 | msgid "Monthly" 103 | msgstr "по месяцам" 104 | 105 | #: templates/dashboard-widget.php:16 106 | msgid "Site Usage" 107 | msgstr "Использование сайта" 108 | 109 | #: templates/dashboard-widget.php:27 templates/dashboard-widget.php:39 110 | #: templates/dashboard-widget.php:54 templates/dashboard-widget.php:65 111 | #: templates/dashboard-widget.php:80 templates/dashboard-widget.php:92 112 | #: templates/dashboard-widget.php:117 templates/dashboard-widget.php:139 113 | #: templates/dashboard-widget.php:161 114 | msgid "None" 115 | msgstr "Нет" 116 | 117 | #: templates/dashboard-widget.php:32 118 | msgid "New Visitors" 119 | msgstr "Новые посетители" 120 | 121 | #: templates/dashboard-widget.php:48 122 | msgid "Page Views" 123 | msgstr "Просмотры страниц" 124 | 125 | #: templates/dashboard-widget.php:59 126 | msgid "Session depth" 127 | msgstr "Глубина сессии" 128 | 129 | #: templates/dashboard-widget.php:74 130 | msgid "Visitors" 131 | msgstr "Посетители" 132 | 133 | #: templates/dashboard-widget.php:85 134 | msgid "Avg. Time on Site" 135 | msgstr "Среднее время на сайте" 136 | 137 | #: templates/dashboard-widget.php:105 138 | msgid "Popular Pages" 139 | msgstr "Популярные страницы" 140 | 141 | #: templates/dashboard-widget.php:113 142 | msgid "%d View" 143 | msgid_plural "%d Views" 144 | msgstr[0] "%d просмотр" 145 | msgstr[1] "%d просмотра" 146 | msgstr[2] "%d просмотров" 147 | 148 | #: templates/dashboard-widget.php:127 149 | msgid "Top Referrers" 150 | msgstr "Основные источники" 151 | 152 | #: templates/dashboard-widget.php:135 templates/dashboard-widget.php:157 153 | msgid "%d Visit" 154 | msgid_plural "%d Visits" 155 | msgstr[0] "%d посещение" 156 | msgstr[1] "%d посещения" 157 | msgstr[2] "%d посещений" 158 | 159 | #: templates/dashboard-widget.php:150 160 | msgid "Search Terms" 161 | msgstr "Поисковые запросы" 162 | 163 | #: templates/settings.php:6 164 | msgid "Cheatin, uh?" 165 | msgstr "" 166 | 167 | #: templates/settings.php:14 168 | msgid "Successfully connected to Yandex Server" 169 | msgstr "Успешное соединение с сервером Яндекса" 170 | 171 | #: templates/settings.php:17 172 | msgid "Something went wrong. Please check your confirmation code!" 173 | msgstr "Что-то пошло не так! Пожалуйста, проверьте ваш код подтверждения!" 174 | 175 | #: templates/settings.php:40 176 | msgid "Options Saved!" 177 | msgstr "Параметры сохранены!" 178 | 179 | #: templates/settings.php:43 180 | msgid "Please enter a valid counter code!" 181 | msgstr "Пожалуйста, введите правильный код счетчика!" 182 | 183 | #: templates/settings.php:56 184 | msgid "All options cleared!" 185 | msgstr "Все параметры очищены!" 186 | 187 | #. Plugin Name of the plugin/theme 188 | #: templates/settings.php:67 yandex-metrica.php:89 189 | msgid "Yandex Metrica" 190 | msgstr "Яндекс Метрика" 191 | 192 | #: templates/settings.php:70 193 | msgid "" 194 | "You need sign in to Yandex and grant this plugin access to your Yandex " 195 | "Metrica account." 196 | msgstr "" 197 | "Вам нужно войти в ваш аккаунт в Яндекс Метрике и дать плагину право доступа " 198 | "к вашему аккаунту." 199 | 200 | #: templates/settings.php:71 201 | msgid "https://oauth.yandex.com/" 202 | msgstr "https://oauth.yandex.ru/" 203 | 204 | #: templates/settings.php:72 205 | msgid "Click here to getting confirmation code" 206 | msgstr "Нажмите сюда для получения кода подтверждения" 207 | 208 | #: templates/settings.php:76 209 | msgid "Enter Confirmation code here" 210 | msgstr "Введите код подтверждения здесь" 211 | 212 | #: templates/settings.php:77 templates/settings.php:182 213 | msgid "Save" 214 | msgstr "Сохранить" 215 | 216 | #: templates/settings.php:81 217 | msgid "If you don't want to use API, you can use basic mode." 218 | msgstr "" 219 | "Если Вы не хотите использовать API, то Вы можете использовать обычный режим." 220 | 221 | #: templates/settings.php:82 222 | msgid "Basic Mode (Compatible with Backward)" 223 | msgstr "Обычный режим (обратно совместимый)" 224 | 225 | #: templates/settings.php:88 226 | msgid "Counter:" 227 | msgstr "Счётчик:" 228 | 229 | #: templates/settings.php:95 230 | msgid "Temporary, getting connectivity problem.!" 231 | msgstr "Временная проблема с подключением!" 232 | 233 | #: templates/settings.php:100 234 | msgid "Enter counter number" 235 | msgstr "Введите код счётчика" 236 | 237 | #: templates/settings.php:103 238 | msgid "Tracking Settings" 239 | msgstr "Настройки отслеживания" 240 | 241 | #: templates/settings.php:111 242 | msgid "Select tracking options" 243 | msgstr "Выберите настройки отслеживания" 244 | 245 | #: templates/settings.php:114 246 | msgid "Webvisor" 247 | msgstr "Вебвизор" 248 | 249 | #: templates/settings.php:116 250 | msgid "Track Clickmap" 251 | msgstr "Отслеживание карты кликов" 252 | 253 | #: templates/settings.php:118 254 | msgid "Track Links, social sharing, file requests..." 255 | msgstr "Отслеживание ссылок, социальных факторов, файловых запросов.." 256 | 257 | #: templates/settings.php:120 258 | msgid "Accurate Track Bounce" 259 | msgstr "Точный учет отказов" 260 | 261 | #: templates/settings.php:122 262 | msgid "Hash tracking in the browser's address bar" 263 | msgstr "Признак отслеживания хеша в адресной строке браузера" 264 | 265 | #: templates/settings.php:129 266 | msgid "Track logged in users" 267 | msgstr "Отслеживание авторизованных пользователей" 268 | 269 | #: templates/settings.php:133 270 | msgid "Yes" 271 | msgstr "Да" 272 | 273 | #: templates/settings.php:134 274 | msgid "No" 275 | msgstr "Нет" 276 | 277 | #: templates/settings.php:141 278 | msgid "User roles to not track" 279 | msgstr "Не отслеживаемые роли пользователей" 280 | 281 | #: templates/settings.php:154 282 | msgid "" 283 | "If a user is logged into with one of these roles, they won't track by " 284 | "metrica." 285 | msgstr "" 286 | "Если у пользователя имеется одна из этих ролей, то он не будет отслеживаться " 287 | "Метрикой" 288 | 289 | #: templates/settings.php:160 290 | msgid "User roles to display dashboard widget" 291 | msgstr "" 292 | "Роли пользователей, для которых отображается виджет в панели управления." 293 | 294 | #: templates/settings.php:174 295 | msgid "Selected roles can display metrica statistic on the dashboard." 296 | msgstr "Выбранные роли могут показывать статистику Метрики в панели управленя." 297 | 298 | #: templates/settings.php:183 299 | msgid "Reset" 300 | msgstr "Сбросить" 301 | 302 | #: yandex-metrica.php:126 303 | msgid "You do not have sufficient permissions to access this page." 304 | msgstr "У вас недостаточно прав для доступа к этой странице." 305 | 306 | #: yandex-metrica.php:139 yandex-metrica.php:142 307 | msgid "Metrica Statistics" 308 | msgstr "Статистика Метрики" 309 | 310 | #: yandex-metrica.php:149 311 | msgid "Oh no! There is nothing to display. Here Are the Possible Causes" 312 | msgstr "Нет элементов для отображения. Возможно причина в следующем" 313 | 314 | #: yandex-metrica.php:150 315 | msgid "" 316 | "If selected a new counter (recently created), please give a few hours for " 317 | "verification. Please be patient." 318 | msgstr "" 319 | "Если выбран новый счётчик (недавно созданный), будьте терпеливы и подождите " 320 | "несколько часов, пока пройдет процесс верификации." 321 | 322 | #: yandex-metrica.php:151 323 | msgid "" 324 | "Did you save options? You need to save options at least once after account " 325 | "confirmation." 326 | msgstr "" 327 | "Вы сохранили параметры? Вам нужно сохранить нужные параметры хотя бы раз " 328 | "после подтверждения аккаунта." 329 | 330 | #: yandex-metrica.php:152 331 | msgid "Are you sure you selected the correct counter? Please confirm." 332 | msgstr "Вы уверены, что выбрали правильный счетчик? Пожалуйста, подтвердите." 333 | 334 | #: yandex-metrica.php:153 335 | msgid "" 336 | "Did you change your Yandex password? If changed, you need to re-authorize " 337 | "this plugin." 338 | msgstr "" 339 | "Вы изменили пароль Яндекса? Если изменилось, то необходимо повторно " 340 | "разрешить этот плагин." 341 | 342 | #: yandex-metrica.php:154 343 | msgid "Temporary, connectivity problem!" 344 | msgstr "Временная проблема с подключением!" 345 | 346 | #: yandex-metrica.php:172 347 | msgid "View Full Report" 348 | msgstr "Посмотреть полный отчёт" 349 | 350 | #. Plugin URI of the plugin/theme 351 | msgid "http://uysalmustafa.com/plugins/yandex-metrica" 352 | msgstr "" 353 | 354 | #. Description of the plugin/theme 355 | msgid "Best metrica plugin for the use Yandex Metrica in your WordPress site." 356 | msgstr "Лучший плагин для использования Яндекс Метрики на сайте Wordpress." 357 | 358 | #. Author of the plugin/theme 359 | msgid "Mustafa Uysal" 360 | msgstr "" 361 | 362 | #. Author URI of the plugin/theme 363 | msgid "http://uysalmustafa.com" 364 | msgstr "" 365 | 366 | #: ../templates/settings.php:179 367 | msgid "Tracker JS" 368 | msgstr "" 369 | 370 | #: ../templates/settings.php:183 371 | msgid "If you want to change watcher js address, use the field above." 372 | msgstr "" 373 | 374 | #: ../templates/settings.php:126 375 | msgid "Use new counter code" 376 | msgstr "Использовать новый код счетчика" -------------------------------------------------------------------------------- /yandex-metrica.php: -------------------------------------------------------------------------------- 1 | options = \YandexMetrica\Utils\get_settings(); 38 | 39 | 40 | $this->hook( 'init' ); 41 | 42 | if ( $this->is_authorized() ) { 43 | $this->hook( 'widgets_init', 'call_metrica_widget' ); 44 | } 45 | 46 | } 47 | 48 | 49 | public function init() { 50 | $this->maybe_install(); 51 | // Load langauge pack 52 | load_plugin_textdomain( 'yandex-metrica', false, basename( dirname( __FILE__ ) ) . '/languages' ); 53 | 54 | $this->hook( 'admin_menu' ); 55 | $this->hook( 'wp_head' ); // using wp_head for adding tracking code. If your theme doesn't have it, this plugin can't track your site. 56 | 57 | if ( $this->is_authorized() ) { 58 | self::$metrica_api = new Yandex_Metrica( \YandexMetrica\Utils\get_decrypted_setting( 'access_token' ) ); 59 | $this->set_period( $this->period ); 60 | $this->hook( 'wp_ajax_metrica_actions', 'ajax_listener' ); 61 | if ( $this->current_user_has_access( $this->options["widget-access-roles"] ) ) 62 | $this->hook( 'wp_dashboard_setup' ); 63 | 64 | } 65 | 66 | $this->widgets_init(); 67 | 68 | } 69 | 70 | public function admin_menu() { 71 | add_options_page( __('Yandex Metrica', 'yandex-metrica'), __('Yandex Metrica', 'yandex-metrica'), 'manage_options', YandexMetrica\Constants\MENU_SLUG, array( $this, 'metrica_settings_page' ) ); 72 | } 73 | 74 | 75 | /** 76 | * @param int $code confirmation code 77 | * 78 | * @return bool 79 | */ 80 | public function authorize( $code ) { 81 | $Auth = new Yandex_Oauth( $this->get_app_id(), $this->get_app_secret() ); 82 | if ( $Auth->connect_oauth_server( $code ) ) { 83 | $encryption = new \YandexMetrica\Encryption(); 84 | $access_token = $Auth->get_access_token(); 85 | // save encrypted access token 86 | $this->options['access_token'] = $encryption->encrypt( $access_token ); 87 | $this->update_options( $this->options ); 88 | $this->init(); 89 | 90 | return true; 91 | } 92 | 93 | return false; 94 | } 95 | 96 | 97 | /** 98 | * Check authorization status 99 | * 100 | * @return bool 101 | */ 102 | public function is_authorized() { 103 | if ( ! empty( \YandexMetrica\Utils\get_decrypted_setting( 'access_token' ) ) ) { 104 | return true; 105 | } 106 | 107 | return false; 108 | } 109 | 110 | 111 | public function metrica_settings_page() { 112 | global $wp_roles; 113 | 114 | if ( ! current_user_can( 'manage_options' ) ) { 115 | wp_die( __( 'You do not have sufficient permissions to access this page.', 'yandex-metrica' ) ); 116 | } 117 | wp_enqueue_script( 'jquery' ); 118 | include( dirname( __FILE__ ) . '/templates/settings.php' ); 119 | } 120 | 121 | 122 | public function wp_dashboard_setup() { 123 | /** 124 | * Check user access 125 | */ 126 | if ( self::$metrica_api->is_valid_counter( $this->options["counter_id"] ) ) { 127 | 128 | /** 129 | * add inline chart js 130 | */ 131 | $this->hook( 'admin_head', 'dashboard_chart_js' ); 132 | wp_add_dashboard_widget( 'yandex_metrica_widget', __( 'Metrica Statistics', 'yandex-metrica' ), array( $this, 'metrica_dashboard_widget' ) ); 133 | } 134 | else { 135 | wp_add_dashboard_widget( 'yandex_metrica_widget', __( 'Metrica Statistics', 'yandex-metrica' ), array( $this, 'temporary_dashboard_widget' ) ); 136 | } 137 | 138 | } 139 | 140 | 141 | public function temporary_dashboard_widget() { 142 | echo '

' . __( 'Oh no! There is nothing to display. Here Are the Possible Causes', 'yandex-metrica' ) . '

'; 143 | echo '
  1. ' . __( 'If selected a new counter (recently created), please give a few hours for verification. Please be patient.', 'yandex-metrica' ) . '
  2. '; 144 | echo '
  3. ' . __( 'Did you save options? You need to save options at least once after account confirmation.', 'yandex-metrica' ) . '
  4. '; 145 | echo '
  5. ' . __( 'Are you sure you selected the correct counter? Please confirm.', 'yandex-metrica' ) . '
  6. '; 146 | echo '
  7. ' . __( 'Did you change your Yandex password? If changed, you need to re-authorize this plugin.', 'yandex-metrica' ) . '
  8. '; 147 | echo '
  9. ' . __( 'Temporary, connectivity problem!', 'yandex-metrica' ) . '
    1. '; 148 | } 149 | 150 | 151 | public function metrica_dashboard_widget() { 152 | $total_values = self::$metrica_api->get_counter_statistics( $this->options["counter_id"], $this->start_date, $this->end_date, 'total' ); 153 | $popular_posts = self::$metrica_api->get_popular_content( $this->options["counter_id"], $this->start_date, $this->end_date ); 154 | $top_referrers = self::$metrica_api->get_referal_sites( $this->options["counter_id"], $this->start_date, $this->end_date ); 155 | $top_searches = self::$metrica_api->get_search_terms( $this->options["counter_id"], $this->start_date, $this->end_date ); 156 | 157 | 158 | 159 | include( dirname( __FILE__ ) . '/templates/dashboard-widget.php' ); 160 | } 161 | 162 | 163 | public function dashboard_chart_js() { 164 | wp_enqueue_script( 'jquery' ); 165 | wp_enqueue_script( 'yandex-metrica-chart', plugins_url( "js/Chart.min.js", __FILE__ ), array(), '3.4.0' ); 166 | 167 | $statical_data = self::$metrica_api->get_counter_statistics( $this->options["counter_id"], $this->start_date, $this->end_date, "daily" ); 168 | 169 | include( dirname( __FILE__ ) . '/templates/dashboard-charts-js.php' ); 170 | } 171 | 172 | /** 173 | * Ajax request handler 174 | */ 175 | public function ajax_listener() { 176 | 177 | if ( isset( $_POST["period"] ) && check_ajax_referer( "yandex-metrica-nonce" ) ) { 178 | $period = sanitize_text_field( stripslashes( $_POST["period"] ) ); 179 | $this->set_period( $period ); 180 | $this->dashboard_chart_js(); 181 | $this->metrica_dashboard_widget(); 182 | } 183 | 184 | die(); 185 | } 186 | 187 | private function update_options( $options ) { 188 | $this->options = $options; 189 | update_option( YandexMetrica\Constants\OPTION, $options ); 190 | } 191 | 192 | /** 193 | * Calculate time period of data blocks. 194 | * 195 | * @param string $period 196 | * 197 | * @return string 198 | */ 199 | public function set_period( $period = "weekly" ) { 200 | 201 | switch ( $period ) { 202 | case "monthly": 203 | $this->start_date = date( 'Y-m-d', strtotime( "-1 month" ) ); 204 | $this->end_date = date( 'Y-m-d' ); 205 | break; 206 | case "weekly": 207 | $this->start_date = date( 'Y-m-d', strtotime( "-6 days" ) ); 208 | $this->end_date = date( 'Y-m-d' ); 209 | break; 210 | case "daily": 211 | $this->start_date = date( 'Y-m-d' ); 212 | $this->end_date = date( 'Y-m-d' ); 213 | break; 214 | } 215 | 216 | return $this->period = $period; 217 | } 218 | 219 | 220 | /** 221 | * @return mixed | Current user' role 222 | */ 223 | public function current_user_role() { 224 | global $current_user; 225 | 226 | $user_roles = $current_user->roles; 227 | $user_role = array_shift( $user_roles ); 228 | 229 | return $user_role; 230 | } 231 | 232 | 233 | private function current_user_has_access( $array ) { 234 | if ( is_array( $array ) && in_array( $this->current_user_role(), $array ) ) { 235 | return true; 236 | } 237 | return false; 238 | } 239 | 240 | 241 | public function wp_head() { 242 | if ( ! empty( $this->options['counter_id'] ) ) { 243 | 244 | $tracker_file = $this->options["new_yandex_code"] === true ? "tracker-js-new.php" : "tracker-js.php"; 245 | 246 | if ( $this->options["track-logged-in"] === true && ( is_user_logged_in() && ! $this->current_user_has_access( $this->options["untrack-roles"] ) ) || ( ! is_user_logged_in() ) ) { 247 | include( dirname( __FILE__ ) . '/templates/' . $tracker_file ); 248 | } 249 | elseif ( $this->options["track-logged-in"] === false && ! is_user_logged_in() ) { 250 | include( dirname( __FILE__ ) . '/templates/' . $tracker_file ); 251 | } 252 | } 253 | } 254 | 255 | 256 | public function metrica_informer() { 257 | echo ''; 258 | } 259 | 260 | /** 261 | * Call back for metrica widget 262 | */ 263 | public function call_metrica_widget() { 264 | register_widget( 'Metrica_Widget' ); 265 | } 266 | 267 | 268 | public function widgets_init() { 269 | wp_register_sidebar_widget( 270 | 'metrica_informer', 271 | 'Metrica Informer', 272 | array( $this, 'metrica_informer' ), 273 | array( 274 | 'description' => esc_html__( 'Add metrica Informer to your sidebar, share daily statistics', 'yandex-metrica' ) 275 | ) 276 | ); 277 | } 278 | 279 | /** 280 | * Get APP ID 281 | * 282 | * @return mixed|void 283 | */ 284 | private function get_app_id() { 285 | return apply_filters( 'yandex_metrica_app_id', YandexMetrica\Constants\YANDEX_APP_ID ); 286 | } 287 | 288 | /** 289 | * Get APP Secret 290 | * 291 | * @return mixed|void 292 | */ 293 | private function get_app_secret() { 294 | return apply_filters( 'yandex_metrica_app_secret', YandexMetrica\Constants\YANDEX_APP_SECRET ); 295 | } 296 | 297 | 298 | /** 299 | * Run db installation routine 300 | */ 301 | public function maybe_install() { 302 | if ( ! is_blog_installed() ) { 303 | return; 304 | } 305 | 306 | // Check if we are not already running 307 | if ( 'yes' === get_transient( 'yandex_metrica_installing' ) ) { 308 | return; 309 | } 310 | 311 | // lets set the transient now. 312 | set_transient( 'yandex_metrica_installing', 'yes', MINUTE_IN_SECONDS ); 313 | 314 | if ( version_compare( get_option( YandexMetrica\Constants\DB_VERSION_OPTION ), YandexMetrica\Constants\DB_VERSION, '<' ) ) { 315 | $this->maybe_upgrade_20(); 316 | update_option( YandexMetrica\Constants\DB_VERSION_OPTION, YandexMetrica\Constants\DB_VERSION, false ); 317 | do_action( 'yandex_metrica_db_upgraded' ); 318 | } 319 | 320 | delete_transient( 'yandex_metrica_installing' ); 321 | } 322 | 323 | /** 324 | * Upgrade routine for 2.0 325 | * 326 | * @return void 327 | */ 328 | public function maybe_upgrade_20() { 329 | $current_version = get_option( YandexMetrica\Constants\DB_VERSION ); 330 | 331 | if ( ! version_compare( $current_version, '2.0', '<' ) ) { 332 | return; 333 | } 334 | 335 | $encryption = new \YandexMetrica\Encryption(); 336 | 337 | if ( ! empty( $this->options['access_token'] ) && false === $encryption->decrypt( $this->options['access_token'] ) ) { 338 | $this->options['access_token'] = $encryption->encrypt( $this->options['access_token'] ); 339 | } 340 | 341 | $this->update_options( $this->options ); 342 | } 343 | 344 | 345 | } 346 | 347 | new WP_Yandex_Metrica; -------------------------------------------------------------------------------- /languages/yandex-metrica-tr_TR.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: Yandex Metrica 1.x\n" 4 | "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/yandex-metrica\n" 5 | "POT-Creation-Date: 2016-09-20 21:59:12+00:00\n" 6 | "PO-Revision-Date: 2018-03-09 00:51+0300\n" 7 | "Last-Translator: Mustafa Uysal \n" 8 | "Language-Team: \n" 9 | "Language: en\n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | "X-Generator: Poedit 1.6.7\n" 14 | "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e;_n:1,2;_n_noop:1,2\n" 15 | "X-Poedit-Basepath: .\n" 16 | "Plural-Forms: nplurals=2; plural=n != 1;\n" 17 | "X-Poedit-SourceCharset: UTF-8\n" 18 | "X-Poedit-SearchPath-0: ..\n" 19 | 20 | #: libs/widget.php:27 21 | msgid "Display statistics within selected period." 22 | msgstr "Seçtiğim periyot için istatistikleri görüntüle." 23 | 24 | #: libs/widget.php:55 25 | msgid "

      Metrica statistics for %s

      " 26 | msgstr "

      %s için Metrika İstatistikleri

      " 27 | 28 | #: libs/widget.php:66 29 | msgid "Page Views: %d
      " 30 | msgstr "Sayfa Gösterimleri: %d
      " 31 | 32 | #: libs/widget.php:68 33 | msgid "Visits: %d
      " 34 | msgstr "Ziyaretler: %d
      " 35 | 36 | #: libs/widget.php:70 37 | msgid "Visitors: %d
      " 38 | msgstr "Ziyaretçiler: %d
      " 39 | 40 | #: libs/widget.php:85 41 | msgid "Title:" 42 | msgstr "Başlık:" 43 | 44 | #: libs/widget.php:89 45 | msgid "Statistics for:" 46 | msgstr "Zaman:" 47 | 48 | #: libs/widget.php:91 49 | msgid "Today" 50 | msgstr "Bugün" 51 | 52 | #: libs/widget.php:92 53 | msgid "Week" 54 | msgstr "Hafta" 55 | 56 | #: libs/widget.php:93 57 | msgid "Month" 58 | msgstr "Ay" 59 | 60 | #: libs/widget.php:97 61 | msgid "Show Pageview" 62 | msgstr "Sayfa Gösterimlerini Göster" 63 | 64 | #: libs/widget.php:99 65 | msgid "Show Visits" 66 | msgstr "Ziyaretleri Göster" 67 | 68 | #: libs/widget.php:101 69 | msgid "Show Visitors" 70 | msgstr "Ziyaretçileri Göster" 71 | 72 | #: templates/dashboard-charts-js.php:10 73 | msgid "Metrica Traffic" 74 | msgstr "Metrika Trafiği" 75 | 76 | #: templates/dashboard-charts-js.php:16 77 | msgid "Source" 78 | msgstr "Kaynak" 79 | 80 | msgid "Pageviews" 81 | msgstr "Sayfa Gösterimleri" 82 | 83 | #: templates/dashboard-charts-js.php:38 templates/dashboard-charts-js.php:52 84 | #: templates/dashboard-widget.php:20 85 | msgid "Visits" 86 | msgstr "Ziyaretler" 87 | 88 | #: templates/dashboard-charts-js.php:60 89 | msgid "Unique" 90 | msgstr "Ziyaretçiler" 91 | 92 | #: templates/dashboard-widget.php:5 93 | msgid "Daily" 94 | msgstr "Günlük" 95 | 96 | #: templates/dashboard-widget.php:8 97 | msgid "Weekly" 98 | msgstr "Haftalık" 99 | 100 | #: templates/dashboard-widget.php:9 101 | msgid "Monthly" 102 | msgstr "Aylık" 103 | 104 | #: templates/dashboard-widget.php:16 105 | msgid "Site Usage" 106 | msgstr "Site Kullanımı" 107 | 108 | #: templates/dashboard-widget.php:27 templates/dashboard-widget.php:39 109 | #: templates/dashboard-widget.php:54 templates/dashboard-widget.php:65 110 | #: templates/dashboard-widget.php:80 templates/dashboard-widget.php:92 111 | #: templates/dashboard-widget.php:117 templates/dashboard-widget.php:139 112 | #: templates/dashboard-widget.php:161 113 | msgid "None" 114 | msgstr "Gösterilecek veri yok" 115 | 116 | #: templates/dashboard-widget.php:32 117 | msgid "New Visitors" 118 | msgstr "Yeni Ziyaretçiler" 119 | 120 | #: templates/dashboard-widget.php:48 121 | msgid "Page Views" 122 | msgstr "Sayfa Gösterimleri" 123 | 124 | #: templates/dashboard-widget.php:59 125 | msgid "Session depth" 126 | msgstr "Ziyaret derinliği" 127 | 128 | #: templates/dashboard-widget.php:74 129 | msgid "Visitors" 130 | msgstr "Ziyaretçiler" 131 | 132 | #: templates/dashboard-widget.php:85 133 | msgid "Avg. Time on Site" 134 | msgstr "Sitede Geçirilen Ort. Süre" 135 | 136 | #: templates/dashboard-widget.php:105 137 | msgid "Popular Pages" 138 | msgstr "Popüler Sayfalar" 139 | 140 | #: templates/dashboard-widget.php:113 141 | msgid "%d View" 142 | msgid_plural "%d Views" 143 | msgstr[0] "%d Görüntülenme" 144 | msgstr[1] "%d Görüntülenme" 145 | 146 | #: templates/dashboard-widget.php:127 147 | msgid "Top Referrers" 148 | msgstr "En Çok Yönlendirenler" 149 | 150 | #: templates/dashboard-widget.php:135 templates/dashboard-widget.php:157 151 | msgid "%d Visit" 152 | msgid_plural "%d Visits" 153 | msgstr[0] "%d Ziyaret" 154 | msgstr[1] "%d Ziyaret" 155 | 156 | #: templates/dashboard-widget.php:150 157 | msgid "Search Terms" 158 | msgstr "En İyi Aramalar" 159 | 160 | #: templates/settings.php:6 161 | msgid "Cheatin, uh?" 162 | msgstr "Hile mi yapıyorsunuz?" 163 | 164 | #: templates/settings.php:14 165 | msgid "Successfully connected to Yandex Server" 166 | msgstr "Başarılı bir şekilde Yandex Servisine bağlanıldı." 167 | 168 | #: templates/settings.php:17 169 | msgid "Something went wrong. Please check your confirmation code!" 170 | msgstr "" 171 | "Olamaz! Bi' şeyler ters gitti! Doğrulama kodunu kontrol edebilir misiniz?" 172 | 173 | #: templates/settings.php:40 174 | msgid "Options Saved!" 175 | msgstr "Ayarlar Kaydedildi!" 176 | 177 | #: templates/settings.php:43 178 | msgid "Please enter a valid counter code!" 179 | msgstr "Lütfen geçerli bir sayaç kodu giriniz!" 180 | 181 | #: templates/settings.php:56 182 | msgid "All options cleared!" 183 | msgstr "Tüm ayarlar sıfırlandı!" 184 | 185 | #. Plugin Name of the plugin/theme 186 | #: templates/settings.php:67 yandex-metrica.php:89 187 | msgid "Yandex Metrica" 188 | msgstr "Yandex Metrika" 189 | 190 | #: templates/settings.php:70 191 | msgid "" 192 | "You need sign in to Yandex and grant this plugin access to your Yandex " 193 | "Metrica account." 194 | msgstr "" 195 | "Yandex hesabınıza giriş yapmanız ve bu eklentinin Yandex Metrica hesabınıza " 196 | "bağlanmasına izin vermelisiniz." 197 | 198 | #: templates/settings.php:71 199 | msgid "https://oauth.yandex.com/" 200 | msgstr "https://oauth.yandex.com/" 201 | 202 | #: templates/settings.php:72 203 | msgid "Click here to getting confirmation code" 204 | msgstr "Aktivasyon kodu almak için tıklayınız." 205 | 206 | #: templates/settings.php:76 207 | msgid "Enter Confirmation code here" 208 | msgstr "Doğrulama kodunu buraya giriniz" 209 | 210 | #: templates/settings.php:77 templates/settings.php:182 211 | msgid "Save" 212 | msgstr "Kaydet" 213 | 214 | #: templates/settings.php:81 215 | msgid "If you don't want to use API, you can use basic mode." 216 | msgstr "" 217 | "Eğer metrica API kullanmak istemiyorsanız, temel modu deneyebilirsiniz." 218 | 219 | #: templates/settings.php:82 220 | msgid "Basic Mode (Compatible with Backward)" 221 | msgstr "Temel Mod (Geri uyumlu)" 222 | 223 | #: templates/settings.php:88 224 | msgid "Counter:" 225 | msgstr "Sayaç:" 226 | 227 | #: templates/settings.php:95 228 | msgid "Temporary, getting connectivity problem.!" 229 | msgstr "API erişiminde geçici bir bağlantı sorunu var!" 230 | 231 | #: templates/settings.php:100 232 | msgid "Enter counter number" 233 | msgstr "Sayaç numarasını giriniz" 234 | 235 | #: templates/settings.php:103 236 | msgid "Tracking Settings" 237 | msgstr "Takip Ayarları" 238 | 239 | #: templates/settings.php:111 240 | msgid "Select tracking options" 241 | msgstr "Sayaç özellikleri" 242 | 243 | #: templates/settings.php:114 244 | msgid "Webvisor" 245 | msgstr "Webvisor" 246 | 247 | #: templates/settings.php:116 248 | msgid "Track Clickmap" 249 | msgstr "Tıklama Haritası" 250 | 251 | #: templates/settings.php:118 252 | msgid "Track Links, social sharing, file requests..." 253 | msgstr "Dış bağlantılar, dosya yüklemeleri ve Paylaş butonu raporu" 254 | 255 | #: templates/settings.php:120 256 | msgid "Accurate Track Bounce" 257 | msgstr "Hemen çıkma oranı" 258 | 259 | #: templates/settings.php:122 260 | msgid "Hash tracking in the browser's address bar" 261 | msgstr "Tarayıcının adres satırında hash'in takip edilmesi" 262 | 263 | #: templates/settings.php:129 264 | msgid "Track logged in users" 265 | msgstr "Giriş yapmış kullanıcıları dahil et" 266 | 267 | #: templates/settings.php:133 268 | msgid "Yes" 269 | msgstr "Evet" 270 | 271 | #: templates/settings.php:134 272 | msgid "No" 273 | msgstr "Hayır" 274 | 275 | #: templates/settings.php:141 276 | msgid "User roles to not track" 277 | msgstr "Takip edilmeyecek kullanıcı seviyesi" 278 | 279 | #: templates/settings.php:154 280 | msgid "" 281 | "If a user is logged into with one of these roles, they won't track by " 282 | "metrica." 283 | msgstr "" 284 | "Bu yetkiye sahip kullanıcılar, metrica servisi tarafından takip " 285 | "edilmeyecektir." 286 | 287 | #: templates/settings.php:160 288 | msgid "User roles to display dashboard widget" 289 | msgstr "Yönetim panelinde istatistikleri görüntüleyebilecek kullanıcı seviyesi" 290 | 291 | #: templates/settings.php:174 292 | msgid "Selected roles can display metrica statistic on the dashboard." 293 | msgstr "" 294 | "Bu yetkiye sahip kullanıcılar, istatistikleri yönetim panelinden " 295 | "görüntüleyebilecektir." 296 | 297 | #: templates/settings.php:183 298 | msgid "Reset" 299 | msgstr "Sıfırla" 300 | 301 | #: yandex-metrica.php:126 302 | msgid "You do not have sufficient permissions to access this page." 303 | msgstr "Bu sayfayı görüntüleme yetkiniz bulunmamaktadır." 304 | 305 | #: yandex-metrica.php:139 yandex-metrica.php:142 306 | msgid "Metrica Statistics" 307 | msgstr "Metrika İstatistikleri" 308 | 309 | #: yandex-metrica.php:149 310 | msgid "Oh no! There is nothing to display. Here Are the Possible Causes" 311 | msgstr "Olamaz :( Yayınlayacak bi'şey bulamadık. Muhtemel sebepler şöyle;" 312 | 313 | #: yandex-metrica.php:150 314 | msgid "" 315 | "If selected a new counter (recently created), please give a few hours for " 316 | "verification. Please be patient." 317 | msgstr "" 318 | "Seçtiğiniz sayacı yeni mi oluşturdunuz? Eğer yeni oluşturmuşsanız " 319 | "doğrulamamız için bir kaç saat bekleyiniz." 320 | 321 | #: yandex-metrica.php:151 322 | msgid "" 323 | "Did you save options? You need to save options at least once after account " 324 | "confirmation." 325 | msgstr "" 326 | "Ayarları kaydettiniz mi? Api izni verdikten sonra en az bir kere ayarları " 327 | "kaydetmeniz gerekmektedir." 328 | 329 | #: yandex-metrica.php:152 330 | msgid "Are you sure you selected the correct counter? Please confirm." 331 | msgstr "" 332 | "Seçtiğiniz sayaç doğru mu? Lütfen sayacı yada sayacı kurarken belirttiğiniz " 333 | "internet adresinin doğru olduğundan emin olunuz." 334 | 335 | #: yandex-metrica.php:153 336 | msgid "" 337 | "Did you change your Yandex password? If changed, you need to re-authorize " 338 | "this plugin." 339 | msgstr "" 340 | "Yandex şifrenizi mi değiştirdiniz? Şifre değişimlerinde eklenti yeniden " 341 | "yetkilendirilmelidir." 342 | 343 | #: yandex-metrica.php:154 344 | msgid "Temporary, connectivity problem!" 345 | msgstr "" 346 | "Düşük bir olasılıkta olsa, geçici bir bağlantı sorunu yaşamış olabilirsiniz." 347 | 348 | #: yandex-metrica.php:172 349 | msgid "View Full Report" 350 | msgstr "Tüm Raporu Görüntüle" 351 | 352 | #. Plugin URI of the plugin/theme 353 | msgid "http://uysalmustafa.com/plugins/yandex-metrica" 354 | msgstr "http://uysalmustafa.com/plugins/yandex-metrica" 355 | 356 | #. Description of the plugin/theme 357 | msgid "Best metrica plugin for the use Yandex Metrica in your WordPress site." 358 | msgstr "" 359 | "Yandex Metrika servisi için kullanabileceğiniz en iyi WordPress eklentisi." 360 | 361 | #. Author of the plugin/theme 362 | msgid "Mustafa Uysal" 363 | msgstr "Mustafa Uysal" 364 | 365 | #. Author URI of the plugin/theme 366 | msgid "http://uysalmustafa.com" 367 | msgstr "http://uysalmustafa.com" 368 | 369 | #: ../templates/settings.php:179 370 | msgid "Tracker JS" 371 | msgstr "Takipçi JS" 372 | 373 | #: ../templates/settings.php:183 374 | msgid "If you want to change watcher js address, use the field above." 375 | msgstr "JS adresini değiştirmek isterseniz yukarıdaki alanı kullanın." 376 | 377 | #~ msgid "" 378 | #~ "Sorry, couldn't draw graph for selected period, please try different time " 379 | #~ "period." 380 | #~ msgstr "" 381 | #~ "Üzgünüz, seçitiğiniz aralık için grafik oluşturamadık, lütfen farklı bir " 382 | #~ "periyot seçin." 383 | -------------------------------------------------------------------------------- /templates/settings.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | authorize( esc_attr( $auth_code ) ) ) { 15 | echo '

      ' . __( 'Successfully connected to Yandex Server', 'yandex-metrica' ) . '

      '; 16 | } else { 17 | echo '

      ' . __( 'Something went wrong. Please check your confirmation code!', 'yandex-metrica' ) . '

      '; 18 | } 19 | } 20 | 21 | if ( isset( $_POST["backward"] ) ) { 22 | $this->options['backward'] = true; // enable backward compatibility 23 | $this->update_options( $this->options ); 24 | } 25 | 26 | if ( isset( $_POST["yandex-metrica-save"] ) ) { 27 | $this->options["counter_id"] = intval( $_POST["metrica-counter"] ); 28 | $this->options['webvisor'] = empty( $_POST['metrica_webvisor'] ) ? false : true; 29 | $this->options['clickmap'] = empty ( $_POST['metrica_clickmap'] ) ? false : true; 30 | $this->options['tracklinks'] = empty( $_POST['metrica_tracklinks'] ) ? false : true; 31 | $this->options['accurate_track'] = empty( $_POST['metrica_accurate_track'] ) ? false : true; 32 | $this->options['track_hash'] = empty( $_POST['track_hash'] ) ? false : true; 33 | 34 | $this->options['track-logged-in'] = ( $_POST['track-logged-in'] == "no" ) ? false : true; 35 | $this->options["untrack-roles"] = ! empty( $_POST["tracker_role"] ) ? array_map( 'sanitize_text_field', $_POST["tracker_role"] ) : ""; 36 | $this->options["widget-access-roles"] = ! empty( $_POST["widget_access"] ) ? array_map( 'sanitize_text_field', $_POST["widget_access"] ) : ""; 37 | $this->options['new_yandex_code'] = empty( $_POST['new_yandex_code'] ) ? false : true; 38 | $this->options['dispatch_ecommerce'] = empty( $_POST['dispatch_ecommerce'] ) ? false : true; 39 | $this->options["ecommerce_container_name"] = ! empty( $_POST["ecommerce_container_name"] ) ? sanitize_text_field( $_POST['ecommerce_container_name'] ) : "dataLayer"; 40 | $this->options["tracker-address"] = ! empty( $_POST["tracker-address"] ) ? esc_url_raw( $_POST['tracker-address'] ) : ""; 41 | 42 | $default_trackers[] = 'https://mc.yandex.ru/metrika/watch.js'; 43 | $default_trackers[] = 'https://mc.yandex.ru/metrika/tag.js'; 44 | 45 | // don't save when it's default address 46 | if ( in_array( $this->options["tracker-address"], $default_trackers ) ) { 47 | $this->options["tracker-address"] = ""; 48 | } 49 | 50 | 51 | if ( is_numeric( $_POST["metrica-counter"] ) ) { 52 | echo '

      ' . __( 'Options Saved!', 'yandex-metrica' ) . '

      '; 53 | } 54 | else { 55 | echo '

      ' . __( "Please enter a valid counter code!", "yandex-metrica" ) . '

      '; 56 | $this->options["counter_id"] = null; 57 | } 58 | 59 | $this->update_options( $this->options ); 60 | 61 | } 62 | 63 | 64 | if ( isset( $_POST["reset"] ) ) { 65 | $this->update_options( null ); 66 | $this->options = \YandexMetrica\Utils\get_settings(); // call default options 67 | 68 | echo '

      ' . __( 'All options cleared!', 'yandex-metrica' ) . '

      '; 69 | } 70 | 71 | ?> 72 | 73 | 74 | 75 |
      76 |
      77 | 78 | 79 |

      80 | 81 | is_authorized() && $this->options["backward"] === false ) : ?> 82 |

      83 |

      84 | 85 |

      86 | 87 |
      88 | 89 | 90 |
      91 | 92 |
      93 |

      94 | 95 | 96 | 97 | 98 | options["backward"] === false ): ?> 99 | get_counters() ) ): ?> 100 | 101 | 106 |

      ' . __( 'Temporary, getting connectivity problem.!', 'yandex-metrica' ) . '

      '; 108 | ?> 109 |
      110 | 111 | 112 | options["counter_id"] ) ) echo 'value="' . esc_attr( $this->options["counter_id"] ) . '"'; ?> placeholder="" style="width:300px;" metrica-counter" /> 113 | 114 | 115 |

      116 | 117 | 118 | 119 | 120 | 121 | 122 | 125 | 141 | 142 | 143 | 144 | 147 | 151 | 152 | 153 | 154 | 157 | 163 | 164 | 165 | 166 | 169 | 182 | 183 | options["backward"] === false ): ?> 184 | 185 | 188 | 202 | 203 | 204 | 205 | 206 | 207 | 210 | 214 | 215 | 216 | 217 |
      123 | 124 | 126 |
      128 |
      130 |
      132 |
      134 |
      136 | (?)
      138 |
      140 |
      145 | 146 | 148 | "> 149 |

      150 |
      155 | 156 | 158 | 162 |
      167 | 168 | 170 | get_names(); 172 | $untrack_roles = $this->options["untrack-roles"]; // get roles that not tracking if logged users track tuned on 173 | if ( ! is_array( $untrack_roles ) ) $untrack_roles = array(); 174 | 175 | foreach ( $roles as $role => $name ): ?> 176 | name="tracker_role[]" value="" /> 177 |
      178 | 179 | 180 |

      181 |
      186 | 187 | 189 | options["widget-access-roles"]; // get roles that not tracking if logged users track tuned on 191 | if ( ! is_array( $widget_roles ) ) $widget_roles = array(); 192 | 193 | foreach ( $roles as $role => $name ): ?> 194 | 195 | name="widget_access[]" value="" /> 196 |
      197 | 198 | 199 | 200 |

      201 |
      208 | 209 | 211 | "> 212 |

      213 |
      218 | 219 |
      220 | 221 | 222 |
      223 | 224 | 225 | 226 | 227 | 228 | 237 | --------------------------------------------------------------------------------