Yandex Metrica - Version 1.8

Version Description

  • Authorization method changed, URL parameters no longer acccepted
    • use wp_head instead wp_footer for the tracking code
    • tested with WordPress 5.1.x
Download this release

Release Info

Developer m_uysl
Plugin Icon 128x128 Yandex Metrica
Version 1.8
Comparing to
See all releases

Code changes from version 1.7 to 1.8

Files changed (4) hide show
  1. README.md +9 -4
  2. libs/Yandex_Metrica.php +12 -7
  3. readme.txt +8 -3
  4. yandex-metrica.php +3 -3
README.md CHANGED
@@ -1,10 +1,10 @@
1
  # Yandex Metrica #
2
 
3
- Contributors: m_uysl, ildarkhasanshin
4
  Tags: yandex,metrica,stats,statistics,tools,analytics,analytics tool,metrika
5
  Requires at least: 3.8
6
- Tested up to: 5.0.1
7
- Stable tag: 1.7
8
  License: GPLv2 (or later)
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -55,7 +55,7 @@ Extract the zip file and just drop the contents in the `wp-content/plugins/` dir
55
  - Probably 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.
56
 
57
  * Everything done, but metrica service doesn't work for me?
58
- - Yandex Metrica plugin uses wp_footer hook for the adds necessary tracking code. Please, ensure your theme has wp_footer hook?
59
 
60
 
61
  ## Screenshots ##
@@ -72,6 +72,11 @@ Extract the zip file and just drop the contents in the `wp-content/plugins/` dir
72
 
73
  ## Changelog ##
74
 
 
 
 
 
 
75
  ### 1.7 ###
76
  - switched to new metrica tracking code by default
77
  - added an option for [new Yandex's tracking code](https://yandex.com/support/metrika/code/counter-initialize.html) (props @ildarkhasanshin)
1
  # Yandex Metrica #
2
 
3
+ Contributors: m_uysl, ildarkhasanshin
4
  Tags: yandex,metrica,stats,statistics,tools,analytics,analytics tool,metrika
5
  Requires at least: 3.8
6
+ Tested up to: 5.1
7
+ Stable tag: 1.8
8
  License: GPLv2 (or later)
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
55
  - Probably 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.
56
 
57
  * Everything done, but metrica service doesn't work for me?
58
+ - Yandex Metrica plugin uses wp_head hook for the adds necessary tracking code. Please, ensure your theme has wp_footer hook?
59
 
60
 
61
  ## Screenshots ##
72
 
73
  ## Changelog ##
74
 
75
+ ### 1.8 ###
76
+ - Authorization method changed, URL parameters no longer acccepted
77
+ - use wp_head instead wp_footer for the tracking code
78
+ - tested with WordPress 5.1.x
79
+
80
  ### 1.7 ###
81
  - switched to new metrica tracking code by default
82
  - added an option for [new Yandex's tracking code](https://yandex.com/support/metrika/code/counter-initialize.html) (props @ildarkhasanshin)
libs/Yandex_Metrica.php CHANGED
@@ -27,7 +27,17 @@ class Yandex_Metrica {
27
  * @return mixed
28
  */
29
  public function fetch_data( $url ) {
30
- $response = wp_remote_get( $url, array( 'timeout' => 7, 'httpversion' => '1.1', 'sslverify' => true ) );
 
 
 
 
 
 
 
 
 
 
31
 
32
  if ( is_wp_error( $response ) ) {
33
  $this->error = "HTTP Request problem";
@@ -54,7 +64,6 @@ class Yandex_Metrica {
54
  public function get_all_counters() {
55
 
56
  $url = esc_url_raw( add_query_arg( array(
57
- 'oauth_token' => $this->access_token,
58
  ), 'https://api-metrika.yandex.com/management/v1/counters' ) );
59
 
60
  $response = $this->fetch_data( $url );
@@ -118,7 +127,7 @@ class Yandex_Metrica {
118
  $results = get_transient( 'metrica_counter_' . self::TRANSIENT_VERSION . '_' . $counter_id );
119
 
120
  if ( ! $results ) {
121
- $counter_url = 'https://api-metrika.yandex.com/management/v1/counter/' . $counter_id . '?oauth_token=' . $this->access_token;
122
  $data = $this->fetch_data( $counter_url );
123
  $results = json_decode( $data, true );
124
  set_transient( 'metrica_counter_' . self::TRANSIENT_VERSION . '_' . $counter_id, $results, 720 );
@@ -145,7 +154,6 @@ class Yandex_Metrica {
145
  'metrics' => 'ym:s:pageviews,ym:s:visits,ym:s:users,ym:s:percentNewVisitors,ym:s:pageDepth,ym:s:avgVisitDurationSeconds',
146
  'group' => 'day',
147
  'ids' => $counter_id,
148
- 'oauth_token' => $this->access_token,
149
  ), 'https://api-metrika.yandex.com/stat/v1/data/bytime' ) );
150
 
151
 
@@ -209,7 +217,6 @@ class Yandex_Metrica {
209
  'group' => 'day',
210
  'ids' => $counter_id,
211
  'limit' => $per_page, // @todo this parameter is not works, take a look later
212
- 'oauth_token' => $this->access_token,
213
  ), 'https://api-metrika.yandex.com/stat/v1/data/bytime' ) );
214
 
215
 
@@ -246,7 +253,6 @@ class Yandex_Metrica {
246
  'group' => 'day',
247
  'ids' => $counter_id,
248
  'limit' => $per_page,
249
- 'oauth_token' => $this->access_token,
250
  ), 'https://api-metrika.yandex.com/stat/v1/data/bytime' ) );
251
 
252
 
@@ -285,7 +291,6 @@ class Yandex_Metrica {
285
  'group' => 'day',
286
  'ids' => $counter_id,
287
  'limit' => $per_page,
288
- 'oauth_token' => $this->access_token,
289
  ), 'https://api-metrika.yandex.com/stat/v1/data/bytime' );
290
 
291
 
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";
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 );
127
  $results = get_transient( 'metrica_counter_' . self::TRANSIENT_VERSION . '_' . $counter_id );
128
 
129
  if ( ! $results ) {
130
+ $counter_url = 'https://api-metrika.yandex.com/management/v1/counter/' . $counter_id;
131
  $data = $this->fetch_data( $counter_url );
132
  $results = json_decode( $data, true );
133
  set_transient( 'metrica_counter_' . self::TRANSIENT_VERSION . '_' . $counter_id, $results, 720 );
154
  'metrics' => 'ym:s:pageviews,ym:s:visits,ym:s:users,ym:s:percentNewVisitors,ym:s:pageDepth,ym:s:avgVisitDurationSeconds',
155
  'group' => 'day',
156
  'ids' => $counter_id,
 
157
  ), 'https://api-metrika.yandex.com/stat/v1/data/bytime' ) );
158
 
159
 
217
  'group' => 'day',
218
  'ids' => $counter_id,
219
  'limit' => $per_page, // @todo this parameter is not works, take a look later
 
220
  ), 'https://api-metrika.yandex.com/stat/v1/data/bytime' ) );
221
 
222
 
253
  'group' => 'day',
254
  'ids' => $counter_id,
255
  'limit' => $per_page,
 
256
  ), 'https://api-metrika.yandex.com/stat/v1/data/bytime' ) );
257
 
258
 
291
  'group' => 'day',
292
  'ids' => $counter_id,
293
  'limit' => $per_page,
 
294
  ), 'https://api-metrika.yandex.com/stat/v1/data/bytime' );
295
 
296
 
readme.txt CHANGED
@@ -3,8 +3,8 @@
3
  Contributors: m_uysl, ildarkhasanshin
4
  Tags: yandex,metrica,stats,statistics,tools,analytics,analytics tool,metrika
5
  Requires at least: 3.8
6
- Tested up to: 5.0.1
7
- Stable tag: 1.7
8
  License: GPLv2 (or later)
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -55,7 +55,7 @@ Yes! (You have to use advanced mode, this feature needs API access)
55
  Probably 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.
56
 
57
  = Everything done, but metrica service doesn't work for me? =
58
- Yandex Metrica plugin uses wp_footer hook for the adds necessary tracking code. Please, ensure your theme has wp_footer hook?
59
 
60
  == Screenshots ==
61
 
@@ -65,6 +65,11 @@ Yandex Metrica plugin uses wp_footer hook for the adds necessary tracking code.
65
 
66
  == Changelog ==
67
 
 
 
 
 
 
68
  = 1.7 =
69
  - switched to new metrica tracking code by default
70
  - added an option for [new Yandex's tracking code](https://yandex.com/support/metrika/code/counter-initialize.html) (props @ildarkhasanshin)
3
  Contributors: m_uysl, ildarkhasanshin
4
  Tags: yandex,metrica,stats,statistics,tools,analytics,analytics tool,metrika
5
  Requires at least: 3.8
6
+ Tested up to: 5.1
7
+ Stable tag: 1.8
8
  License: GPLv2 (or later)
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
55
  Probably 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.
56
 
57
  = Everything done, but metrica service doesn't work for me? =
58
+ Yandex Metrica plugin uses wp_head hook for the adds necessary tracking code. Please, ensure your theme has wp_footer hook?
59
 
60
  == Screenshots ==
61
 
65
 
66
  == Changelog ==
67
 
68
+ = 1.8 =
69
+ - Authorization method changed, URL parameters no longer acccepted
70
+ - use wp_head instead wp_footer for the tracking code
71
+ - tested with WordPress 5.1.x
72
+
73
  = 1.7 =
74
  - switched to new metrica tracking code by default
75
  - added an option for [new Yandex's tracking code](https://yandex.com/support/metrika/code/counter-initialize.html) (props @ildarkhasanshin)
yandex-metrica.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Yandex Metrica
4
  Plugin URI: http://uysalmustafa.com/plugins/yandex-metrica
5
  Description: Best metrica plugin for the use Yandex Metrica in your WordPress site.
6
  Author: Mustafa Uysal
7
- Version: 1.7
8
  Text Domain: yandex-metrica
9
  Domain Path: /languages/
10
  Author URI: http://uysalmustafa.com
@@ -50,7 +50,7 @@ class WP_Yandex_Metrica extends WP_Stack_Plugin {
50
  load_plugin_textdomain( 'yandex-metrica', false, basename( dirname( __FILE__ ) ) . '/languages' );
51
 
52
  $this->hook( 'admin_menu' );
53
- $this->hook( 'wp_footer' ); // using wp_footer for adding tracking code. If you theme don't have it, this plugin can't track your site.
54
 
55
  if ( $this->is_authorized() ) {
56
  self::$metrica_api = new Yandex_Metrica( $this->options["access_token"] );
@@ -246,7 +246,7 @@ class WP_Yandex_Metrica extends WP_Stack_Plugin {
246
  }
247
 
248
 
249
- public function wp_footer() {
250
  if ( ! empty( $this->options['counter_id'] ) ) {
251
 
252
  $tracker_file = $this->options["new_yandex_code"] === true ? "tracker-js-new.php" : "tracker-js.php";
4
  Plugin URI: http://uysalmustafa.com/plugins/yandex-metrica
5
  Description: Best metrica plugin for the use Yandex Metrica in your WordPress site.
6
  Author: Mustafa Uysal
7
+ Version: 1.8
8
  Text Domain: yandex-metrica
9
  Domain Path: /languages/
10
  Author URI: http://uysalmustafa.com
50
  load_plugin_textdomain( 'yandex-metrica', false, basename( dirname( __FILE__ ) ) . '/languages' );
51
 
52
  $this->hook( 'admin_menu' );
53
+ $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.
54
 
55
  if ( $this->is_authorized() ) {
56
  self::$metrica_api = new Yandex_Metrica( $this->options["access_token"] );
246
  }
247
 
248
 
249
+ public function wp_head() {
250
  if ( ! empty( $this->options['counter_id'] ) ) {
251
 
252
  $tracker_file = $this->options["new_yandex_code"] === true ? "tracker-js-new.php" : "tracker-js.php";