Version Description
Release Date: January 8th, 2015
- Bugfixes:
- Makes sure reauthentication notice is only shown on the GA dashboard page.
- Fixes a couple of situations in which the GA reauthentication notice was shown erroneously.
Download this release
Release Info
| Developer | omarreiss |
| Plugin | |
| Version | 5.2.8 |
| Comparing to | |
| See all releases | |
Code changes from version 5.2.7 to 5.2.8
- CONTRIBUTING.md +5 -0
- admin/api-libs/googleanalytics/class-api-googleanalytics.php +2 -2
- admin/api-libs/tests/google/text-class-api-google.php +19 -0
- admin/api-libs/tests/googleanalytics/test-class-api-googleanalytics.php +12 -0
- admin/api-libs/tests/test-class-api-libs.php +28 -0
- admin/class-admin-form.php +4 -4
- admin/class-admin-ga-js.php +0 -16
- admin/class-admin-universal.php +0 -18
- admin/class-admin.php +12 -5
- admin/dashboards/class-admin-dashboards-collector.php +4 -7
- admin/pages/settings.php +5 -6
- frontend/abstract-class-tracking.php +365 -0
- frontend/class-frontend.php +6 -175
- frontend/class-ga-js.php +4 -139
- frontend/class-universal.php +3 -137
- frontend/views/tracking-universal.php +1 -1
- googleanalytics.php +2 -2
- includes/class-autoload.php +1 -2
- readme.txt +9 -1
CONTRIBUTING.md
CHANGED
|
@@ -34,6 +34,11 @@ _Note:_ do **not** report security issues here. Email them to security at yoast
|
|
| 34 |
|
| 35 |
At this point you're waiting on us to merge your pull request. We'll review all pull requests, and make suggestions and changes if necessary.
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Additional Resources
|
| 38 |
* [General GitHub Documentation](http://help.github.com/)
|
| 39 |
* [GitHub Pull Request documentation](http://help.github.com/send-pull-requests/)
|
| 34 |
|
| 35 |
At this point you're waiting on us to merge your pull request. We'll review all pull requests, and make suggestions and changes if necessary.
|
| 36 |
|
| 37 |
+
<a name="patch-welcome"></a>
|
| 38 |
+
## "Patch welcome" issues
|
| 39 |
+
|
| 40 |
+
Some issues are [labeled "Patch-welcome"](https://github.com/Yoast/google-analytics-for-wordpress/issues?q=is%3Aopen+is%3Aissue+label%3APatch-Welcome). This means we see the value in the particular enhancement being suggested but have decided for now not to prioritize it. If you however decide to write a patch for it we'll gladly include it after some code review.
|
| 41 |
+
|
| 42 |
# Additional Resources
|
| 43 |
* [General GitHub Documentation](http://help.github.com/)
|
| 44 |
* [GitHub Pull Request documentation](http://help.github.com/send-pull-requests/)
|
admin/api-libs/googleanalytics/class-api-googleanalytics.php
CHANGED
|
@@ -22,7 +22,7 @@ if ( ! class_exists( 'Yoast_Api_Googleanalytics' ) ) {
|
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Autoload the API Oauth classes
|
| 25 |
-
*
|
| 26 |
* @param string $class_name - The class that should be loaded
|
| 27 |
*/
|
| 28 |
private function autoload_api_oauth_files( $class_name ) {
|
|
@@ -30,7 +30,7 @@ if ( ! class_exists( 'Yoast_Api_Googleanalytics' ) ) {
|
|
| 30 |
$class_name = strtolower( $class_name );
|
| 31 |
$oauth_files = array(
|
| 32 |
'yoast_googleanalytics_reporting' => 'class-googleanalytics-reporting',
|
| 33 |
-
'yoast_google_analytics_client'
|
| 34 |
);
|
| 35 |
|
| 36 |
if ( ! empty( $oauth_files[$class_name] ) ) {
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Autoload the API Oauth classes
|
| 25 |
+
*
|
| 26 |
* @param string $class_name - The class that should be loaded
|
| 27 |
*/
|
| 28 |
private function autoload_api_oauth_files( $class_name ) {
|
| 30 |
$class_name = strtolower( $class_name );
|
| 31 |
$oauth_files = array(
|
| 32 |
'yoast_googleanalytics_reporting' => 'class-googleanalytics-reporting',
|
| 33 |
+
'yoast_google_analytics_client' => 'class-google-analytics-client',
|
| 34 |
);
|
| 35 |
|
| 36 |
if ( ! empty( $oauth_files[$class_name] ) ) {
|
admin/api-libs/tests/google/text-class-api-google.php
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Yoast_Api_Google_Test extends GA_UnitTestCase {
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* Test the autoload functionality
|
| 7 |
+
*/
|
| 8 |
+
public function test_autoload(){
|
| 9 |
+
$classes = array(
|
| 10 |
+
'Yoast_Google_Client',
|
| 11 |
+
'Yoast_Google_Model',
|
| 12 |
+
);
|
| 13 |
+
|
| 14 |
+
foreach( $classes as $class_name ) {
|
| 15 |
+
$this->assertTrue( class_exists( $class_name ) );
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
}
|
admin/api-libs/tests/googleanalytics/test-class-api-googleanalytics.php
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Yoast_Api_Googleanalytics_Test extends GA_UnitTestCase {
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* Test the autoload functionality
|
| 7 |
+
*/
|
| 8 |
+
public function test_autoload(){
|
| 9 |
+
$this->assertTrue( class_exists( 'Yoast_Googleanalytics_Reporting' ) );
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
}
|
admin/api-libs/tests/test-class-api-libs.php
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Yoast_Api_Libs_Test extends GA_UnitTestCase {
|
| 4 |
+
|
| 5 |
+
private $loaded_api_libs = 0;
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* Register API libs in the construct, so we don't need to do that every time
|
| 9 |
+
*/
|
| 10 |
+
public function __construct() {
|
| 11 |
+
$load_libraries = array( 'googleanalytics' );
|
| 12 |
+
$this->loaded_api_libs = count( $load_libraries );
|
| 13 |
+
|
| 14 |
+
Yoast_Api_Libs::load_api_libraries( $load_libraries );
|
| 15 |
+
|
| 16 |
+
parent::__construct();
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Count the result of activated API libs
|
| 21 |
+
*/
|
| 22 |
+
public function test_get_api_libs() {
|
| 23 |
+
$total_active = count( Yoast_Api_Libs::get_api_libs() );
|
| 24 |
+
|
| 25 |
+
$this->assertEquals( $this->loaded_api_libs, 1 );
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
}
|
admin/class-admin-form.php
CHANGED
|
@@ -89,7 +89,7 @@ if ( ! class_exists( 'Yoast_GA_Admin_Form' ) ) {
|
|
| 89 |
$input .= '<input ' . self::parse_attributes( $attributes ) . ' />';
|
| 90 |
|
| 91 |
if ( ! is_null( $text_label ) ) {
|
| 92 |
-
$input .= '<label class="ga-form ga-form-' . $type . '-label" id="yoast-ga-form-label-' . $type . '-textlabel-' . self::$form_namespace . '-' . $id . '" for="yoast-ga-form-' . $type . '-' . self::$form_namespace . '-' . $id . '"
|
| 93 |
}
|
| 94 |
|
| 95 |
// If we get a description, append it to this select field in a new row
|
|
@@ -121,7 +121,7 @@ if ( ! class_exists( 'Yoast_GA_Admin_Form' ) ) {
|
|
| 121 |
|
| 122 |
$select .= '<div class="ga-form ga-form-input">';
|
| 123 |
if ( ! is_null( $title ) ) {
|
| 124 |
-
$select .= self::label( $id, $title, 'select' ); //'<label class="ga-form ga-form-select-label ga-form-label-left" id="yoast-ga-form-label-select-' . self::$form_namespace . '-' . $id . '"
|
| 125 |
}
|
| 126 |
|
| 127 |
if ( $multiple ) {
|
|
@@ -174,7 +174,7 @@ if ( ! class_exists( 'Yoast_GA_Admin_Form' ) ) {
|
|
| 174 |
$text .= '<div class="ga-form ga-form-input">';
|
| 175 |
|
| 176 |
if ( ! is_null( $title ) ) {
|
| 177 |
-
$text .= '<label class="ga-form ga-form-select-label ga-form-label-left" id="yoast-ga-form-label-select-' . self::$form_namespace . '-' . $id . '"
|
| 178 |
}
|
| 179 |
|
| 180 |
$text .= '<textarea rows="5" cols="60" name="' . $name . '" id="yoast-ga-form-textarea-' . self::$form_namespace . '-' . $id . '">' . stripslashes( $textarea_value ) . '</textarea>';
|
|
@@ -254,7 +254,7 @@ if ( ! class_exists( 'Yoast_GA_Admin_Form' ) ) {
|
|
| 254 |
* @return string
|
| 255 |
*/
|
| 256 |
private static function label( $id, $title, $type ) {
|
| 257 |
-
return '<label class="ga-form ga-form-' . $type . '-label ga-form-label-left" id="yoast-ga-form-label-' . $type . '-' . self::$form_namespace . '-' . $id . '"
|
| 258 |
}
|
| 259 |
|
| 260 |
/**
|
| 89 |
$input .= '<input ' . self::parse_attributes( $attributes ) . ' />';
|
| 90 |
|
| 91 |
if ( ! is_null( $text_label ) ) {
|
| 92 |
+
$input .= '<label class="ga-form ga-form-' . $type . '-label" id="yoast-ga-form-label-' . $type . '-textlabel-' . self::$form_namespace . '-' . $id . '" for="yoast-ga-form-' . $type . '-' . self::$form_namespace . '-' . $id . '">' . $text_label . '</label>';
|
| 93 |
}
|
| 94 |
|
| 95 |
// If we get a description, append it to this select field in a new row
|
| 121 |
|
| 122 |
$select .= '<div class="ga-form ga-form-input">';
|
| 123 |
if ( ! is_null( $title ) ) {
|
| 124 |
+
$select .= self::label( $id, $title, 'select' ); //'<label class="ga-form ga-form-select-label ga-form-label-left" id="yoast-ga-form-label-select-' . self::$form_namespace . '-' . $id . '">' . $title . ':</label>';
|
| 125 |
}
|
| 126 |
|
| 127 |
if ( $multiple ) {
|
| 174 |
$text .= '<div class="ga-form ga-form-input">';
|
| 175 |
|
| 176 |
if ( ! is_null( $title ) ) {
|
| 177 |
+
$text .= '<label class="ga-form ga-form-select-label ga-form-label-left" id="yoast-ga-form-label-select-' . self::$form_namespace . '-' . $id . '">' . __( $title, 'google-analytics-for-wordpress' ) . ':</label>';
|
| 178 |
}
|
| 179 |
|
| 180 |
$text .= '<textarea rows="5" cols="60" name="' . $name . '" id="yoast-ga-form-textarea-' . self::$form_namespace . '-' . $id . '">' . stripslashes( $textarea_value ) . '</textarea>';
|
| 254 |
* @return string
|
| 255 |
*/
|
| 256 |
private static function label( $id, $title, $type ) {
|
| 257 |
+
return '<label class="ga-form ga-form-' . $type . '-label ga-form-label-left" id="yoast-ga-form-label-' . $type . '-' . self::$form_namespace . '-' . $id . '">' . $title . ':</label>';
|
| 258 |
}
|
| 259 |
|
| 260 |
/**
|
admin/class-admin-ga-js.php
DELETED
|
@@ -1,16 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* This class is the backend ga.js class, extends the basic admin class
|
| 4 |
-
*/
|
| 5 |
-
|
| 6 |
-
if ( ! class_exists( 'Yoast_GA_Admin_GA_JS' ) ) {
|
| 7 |
-
|
| 8 |
-
class Yoast_GA_Admin_GA_JS extends Yoast_GA_Admin {
|
| 9 |
-
|
| 10 |
-
public function __construct() {
|
| 11 |
-
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
admin/class-admin-universal.php
DELETED
|
@@ -1,18 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* This class is the backend universal class, extends the basic admin class
|
| 4 |
-
*/
|
| 5 |
-
|
| 6 |
-
if ( ! class_exists( 'Yoast_GA_Admin_Universal' ) ) {
|
| 7 |
-
|
| 8 |
-
class Yoast_GA_Admin_Universal extends Yoast_GA_Admin {
|
| 9 |
-
|
| 10 |
-
public function __construct() {
|
| 11 |
-
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
global $yoast_ga_admin_universal;
|
| 17 |
-
$yoast_ga_admin_universal = new Yoast_GA_Admin_Universal;
|
| 18 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
admin/class-admin.php
CHANGED
|
@@ -50,7 +50,7 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
| 50 |
$last_run = get_option( 'yst_ga_last_wp_run' );
|
| 51 |
if ( $last_run === false || Yoast_GA_Utils::hours_between( strtotime( $last_run ), time() ) >= 48 ) {
|
| 52 |
// Show error, something went wrong
|
| 53 |
-
if ( ! is_null( $this->get_tracking_code() ) && empty( $this->options['manual_ua_code_field'] ) && $this->
|
| 54 |
add_action( 'admin_notices', array( $this, 'warning_fetching_data' ) );
|
| 55 |
}
|
| 56 |
}
|
|
@@ -91,7 +91,7 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
| 91 |
* Throw a warning when the fetching failed
|
| 92 |
*/
|
| 93 |
public function warning_fetching_data() {
|
| 94 |
-
echo '<div class="error"><p>' . sprintf( __( 'Failed to fetch the new data from Google Analytics.
|
| 95 |
}
|
| 96 |
|
| 97 |
/**
|
|
@@ -160,7 +160,7 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
| 160 |
}
|
| 161 |
|
| 162 |
/**
|
| 163 |
-
* Are we allowed to show
|
| 164 |
*
|
| 165 |
* @return bool
|
| 166 |
*/
|
|
@@ -174,6 +174,15 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
| 174 |
return false;
|
| 175 |
}
|
| 176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
/**
|
| 178 |
* Transform the Profile ID into an helpful UA code
|
| 179 |
*
|
|
@@ -256,8 +265,6 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
| 256 |
* Load the page of a menu item in the GA plugin
|
| 257 |
*/
|
| 258 |
public function load_page() {
|
| 259 |
-
global $yoast_ga_admin_ga_js;
|
| 260 |
-
$yoast_ga_admin_ga_js = new Yoast_GA_Admin_GA_JS;
|
| 261 |
|
| 262 |
$this->translate_promo();
|
| 263 |
|
| 50 |
$last_run = get_option( 'yst_ga_last_wp_run' );
|
| 51 |
if ( $last_run === false || Yoast_GA_Utils::hours_between( strtotime( $last_run ), time() ) >= 48 ) {
|
| 52 |
// Show error, something went wrong
|
| 53 |
+
if ( ! is_null( $this->get_tracking_code() ) && empty( $this->options['manual_ua_code_field'] ) && $this->show_admin_dashboard_warning() ) {
|
| 54 |
add_action( 'admin_notices', array( $this, 'warning_fetching_data' ) );
|
| 55 |
}
|
| 56 |
}
|
| 91 |
* Throw a warning when the fetching failed
|
| 92 |
*/
|
| 93 |
public function warning_fetching_data() {
|
| 94 |
+
echo '<div class="error"><p>' . sprintf( __( 'Failed to fetch the new data from Google Analytics. You might need to %sreauthenticate%s.', 'google-analytics-for-wordpress' ), '<a href="' . admin_url( 'admin.php?page=yst_ga_settings' ) . '">', '</a>' ) . '</p></div>';
|
| 95 |
}
|
| 96 |
|
| 97 |
/**
|
| 160 |
}
|
| 161 |
|
| 162 |
/**
|
| 163 |
+
* Are we allowed to show a warning message? returns true if it's allowed
|
| 164 |
*
|
| 165 |
* @return bool
|
| 166 |
*/
|
| 174 |
return false;
|
| 175 |
}
|
| 176 |
|
| 177 |
+
/**
|
| 178 |
+
* Are we allowed to show a warning message? returns true if it's allowed ( this is meant to be only for dashboard )
|
| 179 |
+
*
|
| 180 |
+
* @return bool
|
| 181 |
+
*/
|
| 182 |
+
private function show_admin_dashboard_warning() {
|
| 183 |
+
return ( current_user_can( 'manage_options' ) && isset( $_GET['page'] ) && $_GET['page'] === 'yst_ga_dashboard' );
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
/**
|
| 187 |
* Transform the Profile ID into an helpful UA code
|
| 188 |
*
|
| 265 |
* Load the page of a menu item in the GA plugin
|
| 266 |
*/
|
| 267 |
public function load_page() {
|
|
|
|
|
|
|
| 268 |
|
| 269 |
$this->translate_promo();
|
| 270 |
|
admin/dashboards/class-admin-dashboards-collector.php
CHANGED
|
@@ -262,6 +262,10 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Collector' ) ) {
|
|
| 262 |
$response = Yoast_Google_Analytics::get_instance()->do_request( 'https://www.googleapis.com/analytics/v3/data/ga?' . $params );
|
| 263 |
|
| 264 |
if ( isset( $response['response']['code'] ) && $response['response']['code'] == 200 ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
$response = Yoast_Googleanalytics_Reporting::get_instance()->parse_response( $response, $storage_type, $start_date, $end_date );
|
| 266 |
} else {
|
| 267 |
return false;
|
|
@@ -395,13 +399,6 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Collector' ) ) {
|
|
| 395 |
$name = $storage_name;
|
| 396 |
}
|
| 397 |
|
| 398 |
-
/**
|
| 399 |
-
* Success, set a transient which stores the latest runtime
|
| 400 |
-
*/
|
| 401 |
-
if ( ! empty( $response ) ) {
|
| 402 |
-
update_option( 'yst_ga_last_wp_run', date( 'Y-m-d' ) );
|
| 403 |
-
}
|
| 404 |
-
|
| 405 |
return Yoast_GA_Dashboards_Data::set( $name, $response, strtotime( $start_date ), strtotime( $end_date ), $store_as );
|
| 406 |
} else {
|
| 407 |
// Failure on API call try to log it
|
| 262 |
$response = Yoast_Google_Analytics::get_instance()->do_request( 'https://www.googleapis.com/analytics/v3/data/ga?' . $params );
|
| 263 |
|
| 264 |
if ( isset( $response['response']['code'] ) && $response['response']['code'] == 200 ) {
|
| 265 |
+
|
| 266 |
+
// Success, set a transient which stores the latest runtime
|
| 267 |
+
update_option( 'yst_ga_last_wp_run', date( 'Y-m-d' ) );
|
| 268 |
+
|
| 269 |
$response = Yoast_Googleanalytics_Reporting::get_instance()->parse_response( $response, $storage_type, $start_date, $end_date );
|
| 270 |
} else {
|
| 271 |
return false;
|
| 399 |
$name = $storage_name;
|
| 400 |
}
|
| 401 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
return Yoast_GA_Dashboards_Data::set( $name, $response, strtotime( $start_date ), strtotime( $end_date ), $store_as );
|
| 403 |
} else {
|
| 404 |
// Failure on API call try to log it
|
admin/pages/settings.php
CHANGED
|
@@ -32,7 +32,7 @@ echo Yoast_GA_Admin_Form::create_form( 'settings' );
|
|
| 32 |
$ga_class = Yoast_Google_Analytics::get_instance();
|
| 33 |
$wp_block_google = $ga_class->check_google_access_from_wp();
|
| 34 |
$check_google_access = $ga_class->check_google_access();
|
| 35 |
-
|
| 36 |
if ( $wp_block_google && $check_google_access ) {
|
| 37 |
|
| 38 |
$profiles = Yoast_GA_Admin_Form::parse_optgroups( $yoast_ga_admin->get_profiles() );
|
|
@@ -44,27 +44,26 @@ echo Yoast_GA_Admin_Form::create_form( 'settings' );
|
|
| 44 |
echo "<div id='google_ua_code_field'>";
|
| 45 |
if ( count( $profiles ) == 0 ) {
|
| 46 |
echo '<div class="ga-form ga-form-input">';
|
| 47 |
-
echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle"
|
| 48 |
echo '<a id="yst_ga_authenticate" class="button" onclick="yst_popupwindow(\'' . $auth_url . '\',500,500);">' . __( 'Authenticate with your Google account', 'google-analytics-for-wordpress' ) . '</a>';
|
| 49 |
echo '</div>';
|
| 50 |
echo '<div class="ga-form ga-form-input">';
|
| 51 |
-
echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle"
|
| 52 |
echo $yoast_ga_admin->get_tracking_code();
|
| 53 |
echo '</div>';
|
| 54 |
} else {
|
| 55 |
echo Yoast_GA_Admin_Form::select( __('Analytics profile', 'google-analytics-for-wordpress' ), 'analytics_profile', $profiles, null, false, __( 'Select a profile', 'google-analytics-for-wordpress' ) );
|
| 56 |
|
| 57 |
echo '<div class="ga-form ga-form-input">';
|
| 58 |
-
echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle"
|
| 59 |
echo '<a id="yst_ga_authenticate" class="button" onclick="yst_popupwindow(\'' . $auth_url . '\',500,500);">' . __( 'Re-authenticate with your Google account', 'google-analytics-for-wordpress' ) . '</a>';
|
| 60 |
echo '</div>';
|
| 61 |
}
|
| 62 |
echo '</div>';
|
| 63 |
|
| 64 |
echo '<div id="oauth_code" class="ga-form ga-form-input">';
|
| 65 |
-
echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle"
|
| 66 |
echo Yoast_GA_Admin_Form::input( 'text', null, 'google_auth_code', null, null );
|
| 67 |
-
echo '</label>';
|
| 68 |
|
| 69 |
echo '</div>';
|
| 70 |
} else {
|
| 32 |
$ga_class = Yoast_Google_Analytics::get_instance();
|
| 33 |
$wp_block_google = $ga_class->check_google_access_from_wp();
|
| 34 |
$check_google_access = $ga_class->check_google_access();
|
| 35 |
+
|
| 36 |
if ( $wp_block_google && $check_google_access ) {
|
| 37 |
|
| 38 |
$profiles = Yoast_GA_Admin_Form::parse_optgroups( $yoast_ga_admin->get_profiles() );
|
| 44 |
echo "<div id='google_ua_code_field'>";
|
| 45 |
if ( count( $profiles ) == 0 ) {
|
| 46 |
echo '<div class="ga-form ga-form-input">';
|
| 47 |
+
echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle">' . __( 'Google profile', 'google-analytics-for-wordpress' ) . ':</label>';
|
| 48 |
echo '<a id="yst_ga_authenticate" class="button" onclick="yst_popupwindow(\'' . $auth_url . '\',500,500);">' . __( 'Authenticate with your Google account', 'google-analytics-for-wordpress' ) . '</a>';
|
| 49 |
echo '</div>';
|
| 50 |
echo '<div class="ga-form ga-form-input">';
|
| 51 |
+
echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle">' . __( 'Current UA-profile', 'google-analytics-for-wordpress' ) . '</label>';
|
| 52 |
echo $yoast_ga_admin->get_tracking_code();
|
| 53 |
echo '</div>';
|
| 54 |
} else {
|
| 55 |
echo Yoast_GA_Admin_Form::select( __('Analytics profile', 'google-analytics-for-wordpress' ), 'analytics_profile', $profiles, null, false, __( 'Select a profile', 'google-analytics-for-wordpress' ) );
|
| 56 |
|
| 57 |
echo '<div class="ga-form ga-form-input">';
|
| 58 |
+
echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle"> </label>';
|
| 59 |
echo '<a id="yst_ga_authenticate" class="button" onclick="yst_popupwindow(\'' . $auth_url . '\',500,500);">' . __( 'Re-authenticate with your Google account', 'google-analytics-for-wordpress' ) . '</a>';
|
| 60 |
echo '</div>';
|
| 61 |
}
|
| 62 |
echo '</div>';
|
| 63 |
|
| 64 |
echo '<div id="oauth_code" class="ga-form ga-form-input">';
|
| 65 |
+
echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle">' . __( 'Paste your Google code and press return', 'google-analytics-for-wordpress' ) . ':</label>';
|
| 66 |
echo Yoast_GA_Admin_Form::input( 'text', null, 'google_auth_code', null, null );
|
|
|
|
| 67 |
|
| 68 |
echo '</div>';
|
| 69 |
} else {
|
frontend/abstract-class-tracking.php
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* The basic frontend tracking class for the GA plugin, extendable for the children
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
abstract class Yoast_GA_Tracking {
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* Regular expression for Ga.js and universal tracking to detect links
|
| 10 |
+
* @var string
|
| 11 |
+
*/
|
| 12 |
+
protected $link_regex = '/<a\s+([^>]*?)href=[\'\"](.*?):(\/\/)?([^\'\"]+?)[\'\"]\s?(.*?)>(.*?)<\/a>/i';
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* Storage for the currently set options
|
| 16 |
+
* @var mixed|void
|
| 17 |
+
*/
|
| 18 |
+
protected $options;
|
| 19 |
+
|
| 20 |
+
/**
|
| 21 |
+
* Should the tracking code be added
|
| 22 |
+
* @var bool
|
| 23 |
+
*/
|
| 24 |
+
protected $do_tracking;
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Function to output the GA Tracking code in the wp_head()
|
| 28 |
+
*
|
| 29 |
+
* @param bool $return_array
|
| 30 |
+
*
|
| 31 |
+
* @return mixed
|
| 32 |
+
*/
|
| 33 |
+
abstract public function tracking( $return_array = false );
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Output tracking link
|
| 37 |
+
*
|
| 38 |
+
* @param $label
|
| 39 |
+
* @param $matches
|
| 40 |
+
*
|
| 41 |
+
* @return mixed
|
| 42 |
+
*/
|
| 43 |
+
abstract protected function output_parse_link( $label, $matches );
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* Class constructor
|
| 47 |
+
*/
|
| 48 |
+
public function __construct() {
|
| 49 |
+
|
| 50 |
+
$this->options = Yoast_GA_Options::instance()->options;
|
| 51 |
+
$this->do_tracking = $this->do_tracking();
|
| 52 |
+
|
| 53 |
+
add_action( 'wp_head', array( $this, 'tracking' ), 8 );
|
| 54 |
+
|
| 55 |
+
if ( $this->options['track_outbound'] == 1 ) {
|
| 56 |
+
$this->track_outbound_filters();
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* Delegates `get_tracking_code` to the options class
|
| 62 |
+
*
|
| 63 |
+
* @return null
|
| 64 |
+
*/
|
| 65 |
+
public function get_tracking_code() {
|
| 66 |
+
return Yoast_GA_Options::instance()->get_tracking_code();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* Parse article link
|
| 71 |
+
*
|
| 72 |
+
* @param $matches
|
| 73 |
+
*
|
| 74 |
+
* @return mixed
|
| 75 |
+
*/
|
| 76 |
+
public function parse_article_link( $matches ) {
|
| 77 |
+
return $this->output_parse_link( 'outbound-article', $matches );
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* Parse comment link
|
| 82 |
+
*
|
| 83 |
+
* @param $matches
|
| 84 |
+
*
|
| 85 |
+
* @return mixed
|
| 86 |
+
*/
|
| 87 |
+
public function parse_comment_link( $matches ) {
|
| 88 |
+
return $this->output_parse_link( 'outbound-comment', $matches );
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/**
|
| 92 |
+
* Parse widget link
|
| 93 |
+
*
|
| 94 |
+
* @param $matches
|
| 95 |
+
*
|
| 96 |
+
* @return mixed
|
| 97 |
+
*/
|
| 98 |
+
public function parse_widget_link( $matches ) {
|
| 99 |
+
return $this->output_parse_link( 'outbound-widget', $matches );
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Parse menu link
|
| 104 |
+
*
|
| 105 |
+
* @param $matches
|
| 106 |
+
*
|
| 107 |
+
* @return mixed
|
| 108 |
+
*/
|
| 109 |
+
public function parse_nav_menu( $matches ) {
|
| 110 |
+
return $this->output_parse_link( 'outbound-menu', $matches );
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Parse the_content or the_excerpt for links
|
| 115 |
+
*
|
| 116 |
+
* @param $text
|
| 117 |
+
*
|
| 118 |
+
* @return mixed
|
| 119 |
+
*/
|
| 120 |
+
public function the_content( $text ) {
|
| 121 |
+
if ( false === $this->do_tracking ) {
|
| 122 |
+
return $text;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
if ( ! is_feed() ) {
|
| 126 |
+
$text = preg_replace_callback( $this->link_regex, array( $this, 'parse_article_link' ), $text );
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
return $text;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/**
|
| 133 |
+
* Parse the widget content for links
|
| 134 |
+
*
|
| 135 |
+
* @param $text
|
| 136 |
+
*
|
| 137 |
+
* @return mixed
|
| 138 |
+
*/
|
| 139 |
+
public function widget_content( $text ) {
|
| 140 |
+
if ( ! $this->do_tracking ) {
|
| 141 |
+
return $text;
|
| 142 |
+
}
|
| 143 |
+
$text = preg_replace_callback( $this->link_regex, array( $this, 'parse_widget_link' ), $text );
|
| 144 |
+
|
| 145 |
+
return $text;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* Parse the nav menu for links
|
| 150 |
+
*
|
| 151 |
+
* @param $text
|
| 152 |
+
*
|
| 153 |
+
* @return mixed
|
| 154 |
+
*/
|
| 155 |
+
public function nav_menu( $text ) {
|
| 156 |
+
if ( ! $this->do_tracking ) {
|
| 157 |
+
return $text;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
if ( ! is_feed() ) {
|
| 161 |
+
$text = preg_replace_callback( $this->link_regex, array( $this, 'parse_nav_menu' ), $text );
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
return $text;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
/**
|
| 168 |
+
* Parse comment text for links
|
| 169 |
+
*
|
| 170 |
+
* @param $text
|
| 171 |
+
*
|
| 172 |
+
* @return mixed
|
| 173 |
+
*/
|
| 174 |
+
public function comment_text( $text ) {
|
| 175 |
+
if ( ! $this->do_tracking ) {
|
| 176 |
+
return $text;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
if ( ! is_feed() ) {
|
| 180 |
+
$text = preg_replace_callback( $this->link_regex, array( $this, 'parse_comment_link' ), $text );
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
return $text;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
/**
|
| 187 |
+
* Parse the domain
|
| 188 |
+
*
|
| 189 |
+
* @param $uri
|
| 190 |
+
*
|
| 191 |
+
* @return array|bool
|
| 192 |
+
*/
|
| 193 |
+
public function yoast_ga_get_domain( $uri ) {
|
| 194 |
+
$hostPattern = '/^(https?:\/\/)?([^\/]+)/i';
|
| 195 |
+
$domainPatternUS = '/[^\.\/]+\.[^\.\/]+$/';
|
| 196 |
+
$domainPatternUK = '/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/';
|
| 197 |
+
|
| 198 |
+
$matching = preg_match( $hostPattern, $uri, $matches );
|
| 199 |
+
if ( $matching ) {
|
| 200 |
+
$host = $matches[2];
|
| 201 |
+
if ( preg_match( '/.*\..*\..*\..*$/', $host ) ) {
|
| 202 |
+
preg_match( $domainPatternUK, $host, $matches );
|
| 203 |
+
} else {
|
| 204 |
+
preg_match( $domainPatternUS, $host, $matches );
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
if ( isset( $matches[0] ) ) {
|
| 208 |
+
return array( 'domain' => $matches[0], 'host' => $host );
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
return false;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
/**
|
| 215 |
+
* Merge the existing onclick with a new one and append it
|
| 216 |
+
*
|
| 217 |
+
* @param string $link_attribute
|
| 218 |
+
* @param string $onclick
|
| 219 |
+
*
|
| 220 |
+
* @return string
|
| 221 |
+
*/
|
| 222 |
+
public function output_add_onclick( $link_attribute, $onclick ) {
|
| 223 |
+
if ( preg_match( '/onclick=[\'\"](.*?;)[\'\"]/i', $link_attribute, $matches ) > 0 ) {
|
| 224 |
+
$js_snippet_single = 'onclick=\'' . $matches[1] . ' ' . $onclick . '\'';
|
| 225 |
+
$js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"';
|
| 226 |
+
|
| 227 |
+
$link_attribute = str_replace( 'onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute );
|
| 228 |
+
$link_attribute = str_replace( "onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute );
|
| 229 |
+
|
| 230 |
+
return $link_attribute;
|
| 231 |
+
} else {
|
| 232 |
+
if ( ! is_null( $onclick ) ) {
|
| 233 |
+
return 'onclick="' . $onclick . '" ' . $link_attribute;
|
| 234 |
+
} else {
|
| 235 |
+
return $link_attribute;
|
| 236 |
+
}
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/**
|
| 241 |
+
* Generate the full URL
|
| 242 |
+
*
|
| 243 |
+
* @param string $link
|
| 244 |
+
*
|
| 245 |
+
* @return string
|
| 246 |
+
*/
|
| 247 |
+
public function make_full_url( $link ) {
|
| 248 |
+
switch ( $link['type'] ) {
|
| 249 |
+
case 'download':
|
| 250 |
+
case 'internal':
|
| 251 |
+
case 'internal-as-outbound':
|
| 252 |
+
case 'outbound':
|
| 253 |
+
return $link['protocol'] . '://' . $link['original_url'];
|
| 254 |
+
break;
|
| 255 |
+
case 'email':
|
| 256 |
+
return 'mailto:' . $link['original_url'];
|
| 257 |
+
break;
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
/**
|
| 262 |
+
* Setting the filters for tracking outbound links
|
| 263 |
+
*
|
| 264 |
+
*/
|
| 265 |
+
protected function track_outbound_filters() {
|
| 266 |
+
add_filter( 'the_content', array( $this, 'the_content' ), 99 );
|
| 267 |
+
add_filter( 'widget_text', array( $this, 'widget_content' ), 99 );
|
| 268 |
+
add_filter( 'wp_list_bookmarks', array( $this, 'widget_content' ), 99 );
|
| 269 |
+
add_filter( 'wp_nav_menu', array( $this, 'widget_content' ), 99 );
|
| 270 |
+
add_filter( 'the_excerpt', array( $this, 'the_content' ), 99 );
|
| 271 |
+
add_filter( 'comment_text', array( $this, 'comment_text' ), 99 );
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
/**
|
| 275 |
+
* Check if we need to show an actual tracking code
|
| 276 |
+
*
|
| 277 |
+
* @return bool
|
| 278 |
+
*/
|
| 279 |
+
public function do_tracking() {
|
| 280 |
+
global $current_user;
|
| 281 |
+
|
| 282 |
+
if ( ! function_exists( 'get_currentuserinfo' ) ) {
|
| 283 |
+
require_once( ABSPATH . 'wp-includes/pluggable.php' );
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
get_currentuserinfo();
|
| 287 |
+
|
| 288 |
+
if ( 0 == $current_user->ID ) {
|
| 289 |
+
return true;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
if ( isset( $this->options['ignore_users'] ) ) {
|
| 293 |
+
if ( ! empty( $current_user->roles ) && in_array( $current_user->roles[0], $this->options['ignore_users'] ) ) {
|
| 294 |
+
return false;
|
| 295 |
+
}
|
| 296 |
+
}
|
| 297 |
+
return true;
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
/**
|
| 301 |
+
* Return the target with a lot of parameters
|
| 302 |
+
*
|
| 303 |
+
* @param string $category
|
| 304 |
+
* @param array $matches
|
| 305 |
+
*
|
| 306 |
+
* @return array
|
| 307 |
+
*/
|
| 308 |
+
protected function get_target( $category, $matches ) {
|
| 309 |
+
$protocol = $matches[2];
|
| 310 |
+
$original_url = $matches[4];
|
| 311 |
+
$domain = $this->yoast_ga_get_domain( $matches[4] );
|
| 312 |
+
$origin = $this->yoast_ga_get_domain( $_SERVER['HTTP_HOST'] );
|
| 313 |
+
$download_extensions = explode( ',', str_replace( '.', '', $this->options['extensions_of_files'] ) );
|
| 314 |
+
$extension = substr( strrchr( $original_url, '.' ), 1 );
|
| 315 |
+
|
| 316 |
+
// Break out immediately if the link is not an http or https link.
|
| 317 |
+
$type = null;
|
| 318 |
+
if ( $protocol !== 'http' && $protocol !== 'https' && $protocol !== 'mailto' ) {
|
| 319 |
+
$type = null;
|
| 320 |
+
} else {
|
| 321 |
+
if ( ( $protocol == 'mailto' ) ) {
|
| 322 |
+
$type = 'email';
|
| 323 |
+
} elseif ( in_array( $extension, $download_extensions ) ) {
|
| 324 |
+
$type = 'download';
|
| 325 |
+
} else {
|
| 326 |
+
if ( $domain['domain'] == $origin['domain'] ) {
|
| 327 |
+
$out_links = explode( ',', $this->options['track_internal_as_outbound'] );
|
| 328 |
+
|
| 329 |
+
if ( count( $out_links ) >= 1 ) {
|
| 330 |
+
foreach ( $out_links as $out ) {
|
| 331 |
+
if ( ! empty( $original_url ) && ! empty( $domain['domain'] ) ) {
|
| 332 |
+
if ( strpos( $original_url, $domain['domain'] . $out ) !== false ) {
|
| 333 |
+
$type = 'internal-as-outbound';
|
| 334 |
+
}
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
if ( ! isset( $type ) ) {
|
| 340 |
+
$type = 'internal';
|
| 341 |
+
}
|
| 342 |
+
} elseif ( $domain['domain'] != $origin['domain'] ) {
|
| 343 |
+
$type = 'outbound';
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
return array(
|
| 349 |
+
'category' => $category,
|
| 350 |
+
'type' => $type,
|
| 351 |
+
'protocol' => $protocol,
|
| 352 |
+
'domain' => $domain['domain'],
|
| 353 |
+
'host' => $domain['host'],
|
| 354 |
+
'origin_domain' => $origin['domain'],
|
| 355 |
+
'origin_host' => $origin['host'],
|
| 356 |
+
'extension' => $extension,
|
| 357 |
+
'link_attributes' => rtrim( $matches[1] . ' ' . $matches[5] ),
|
| 358 |
+
'link_text' => $matches[6],
|
| 359 |
+
'original_url' => $original_url,
|
| 360 |
+
);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
}
|
| 365 |
+
|
frontend/class-frontend.php
CHANGED
|
@@ -5,15 +5,16 @@
|
|
| 5 |
|
| 6 |
if ( ! class_exists( 'Yoast_GA_Frontend' ) ) {
|
| 7 |
|
| 8 |
-
class Yoast_GA_Frontend
|
| 9 |
|
| 10 |
-
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Class constructor
|
| 14 |
*/
|
| 15 |
public function __construct() {
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
if ( isset( $this->options['tag_links_in_rss'] ) && $this->options['tag_links_in_rss'] == 1 ) {
|
| 19 |
add_filter( 'the_permalink_rss', array( $this, 'rsslinktagger' ), 99 );
|
|
@@ -21,72 +22,11 @@ if ( ! class_exists( 'Yoast_GA_Frontend' ) ) {
|
|
| 21 |
|
| 22 |
// Check if the customer is running Universal or not (Enable in GA Settings -> Universal)
|
| 23 |
if ( isset( $this->options['enable_universal'] ) && $this->options['enable_universal'] == 1 ) {
|
| 24 |
-
|
| 25 |
-
$yoast_ga_universal = new Yoast_GA_Universal;
|
| 26 |
} else {
|
| 27 |
-
|
| 28 |
-
$yoast_ga_js = new Yoast_GA_JS;
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
/**
|
| 34 |
-
* Get the regex for Ga.js and universal tracking to detect links
|
| 35 |
-
*
|
| 36 |
-
* @return string Contains the regular expression for detecting links
|
| 37 |
-
*/
|
| 38 |
-
public function get_regex() {
|
| 39 |
-
return '/<a\s+([^>]*?)href=[\'\"](.*?):(\/\/)?([^\'\"]+?)[\'\"]\s?(.*?)>(.*?)<\/a>/i';
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
/**
|
| 43 |
-
* Check if we need to show an actual tracking code
|
| 44 |
-
*
|
| 45 |
-
* @return bool
|
| 46 |
-
*/
|
| 47 |
-
public function do_tracking() {
|
| 48 |
-
global $current_user;
|
| 49 |
-
|
| 50 |
-
get_currentuserinfo();
|
| 51 |
-
|
| 52 |
-
if ( 0 == $current_user->ID ) {
|
| 53 |
-
return true;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
if ( isset( $this->options['ignore_users'] ) ) {
|
| 57 |
-
if ( ! empty( $current_user->roles ) && in_array( $current_user->roles[0], $this->options['ignore_users'] ) ) {
|
| 58 |
-
return false;
|
| 59 |
-
}
|
| 60 |
}
|
| 61 |
-
return true;
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
/**
|
| 65 |
-
* Parse the domain
|
| 66 |
-
*
|
| 67 |
-
* @param $uri
|
| 68 |
-
*
|
| 69 |
-
* @return array|bool
|
| 70 |
-
*/
|
| 71 |
-
public function yoast_ga_get_domain( $uri ) {
|
| 72 |
-
$hostPattern = '/^(https?:\/\/)?([^\/]+)/i';
|
| 73 |
-
$domainPatternUS = '/[^\.\/]+\.[^\.\/]+$/';
|
| 74 |
-
$domainPatternUK = '/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/';
|
| 75 |
|
| 76 |
-
$matching = preg_match( $hostPattern, $uri, $matches );
|
| 77 |
-
if ( $matching ) {
|
| 78 |
-
$host = $matches[2];
|
| 79 |
-
if ( preg_match( '/.*\..*\..*\..*$/', $host ) ) {
|
| 80 |
-
preg_match( $domainPatternUK, $host, $matches );
|
| 81 |
-
} else {
|
| 82 |
-
preg_match( $domainPatternUS, $host, $matches );
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
if ( isset( $matches[0] ) ) {
|
| 86 |
-
return array( 'domain' => $matches[0], 'host' => $host );
|
| 87 |
-
}
|
| 88 |
-
}
|
| 89 |
-
return false;
|
| 90 |
}
|
| 91 |
|
| 92 |
/**
|
|
@@ -114,115 +54,6 @@ if ( ! class_exists( 'Yoast_GA_Frontend' ) ) {
|
|
| 114 |
return $guid;
|
| 115 |
}
|
| 116 |
|
| 117 |
-
/**
|
| 118 |
-
* Return the target with a lot of parameters
|
| 119 |
-
*
|
| 120 |
-
* @param string $category
|
| 121 |
-
* @param array $matches
|
| 122 |
-
*
|
| 123 |
-
* @return array
|
| 124 |
-
*/
|
| 125 |
-
public function get_target( $category, $matches ) {
|
| 126 |
-
$protocol = $matches[2];
|
| 127 |
-
$original_url = $matches[4];
|
| 128 |
-
$domain = $this->yoast_ga_get_domain( $matches[4] );
|
| 129 |
-
$origin = $this->yoast_ga_get_domain( $_SERVER['HTTP_HOST'] );
|
| 130 |
-
$download_extensions = explode( ',', str_replace( '.', '', $this->options['extensions_of_files'] ) );
|
| 131 |
-
$extension = substr( strrchr( $original_url, '.' ), 1 );
|
| 132 |
-
|
| 133 |
-
// Break out immediately if the link is not an http or https link.
|
| 134 |
-
$type = null;
|
| 135 |
-
if ( $protocol !== 'http' && $protocol !== 'https' && $protocol !== 'mailto' ) {
|
| 136 |
-
$type = null;
|
| 137 |
-
} else {
|
| 138 |
-
if ( ( $protocol == 'mailto' ) ) {
|
| 139 |
-
$type = 'email';
|
| 140 |
-
} elseif ( in_array( $extension, $download_extensions ) ) {
|
| 141 |
-
$type = 'download';
|
| 142 |
-
} else {
|
| 143 |
-
if ( $domain['domain'] == $origin['domain'] ) {
|
| 144 |
-
$out_links = explode( ',', $this->options['track_internal_as_outbound'] );
|
| 145 |
-
|
| 146 |
-
if ( count( $out_links ) >= 1 ) {
|
| 147 |
-
foreach ( $out_links as $out ) {
|
| 148 |
-
if ( ! empty( $original_url ) && ! empty( $domain['domain'] ) ) {
|
| 149 |
-
if ( strpos( $original_url, $domain['domain'] . $out ) !== false ) {
|
| 150 |
-
$type = 'internal-as-outbound';
|
| 151 |
-
}
|
| 152 |
-
}
|
| 153 |
-
}
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
if ( ! isset( $type ) ) {
|
| 157 |
-
$type = 'internal';
|
| 158 |
-
}
|
| 159 |
-
} elseif ( $domain['domain'] != $origin['domain'] ) {
|
| 160 |
-
$type = 'outbound';
|
| 161 |
-
}
|
| 162 |
-
}
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
return array(
|
| 166 |
-
'category' => $category,
|
| 167 |
-
'type' => $type,
|
| 168 |
-
'protocol' => $protocol,
|
| 169 |
-
'domain' => $domain['domain'],
|
| 170 |
-
'host' => $domain['host'],
|
| 171 |
-
'origin_domain' => $origin['domain'],
|
| 172 |
-
'origin_host' => $origin['host'],
|
| 173 |
-
'extension' => $extension,
|
| 174 |
-
'link_attributes' => rtrim( $matches[1] . ' ' . $matches[5] ),
|
| 175 |
-
'link_text' => $matches[6],
|
| 176 |
-
'original_url' => $original_url,
|
| 177 |
-
);
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
/**
|
| 181 |
-
* Merge the existing onclick with a new one and append it
|
| 182 |
-
*
|
| 183 |
-
* @param string $link_attribute
|
| 184 |
-
* @param string $onclick
|
| 185 |
-
*
|
| 186 |
-
* @return string
|
| 187 |
-
*/
|
| 188 |
-
public function output_add_onclick( $link_attribute, $onclick ) {
|
| 189 |
-
if ( preg_match( '/onclick=[\'\"](.*?;)[\'\"]/i', $link_attribute, $matches ) > 0 ) {
|
| 190 |
-
$js_snippet_single = 'onclick=\'' . $matches[1] . ' ' . $onclick . '\'';
|
| 191 |
-
$js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"';
|
| 192 |
-
|
| 193 |
-
$link_attribute = str_replace( 'onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute );
|
| 194 |
-
$link_attribute = str_replace( "onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute );
|
| 195 |
-
|
| 196 |
-
return $link_attribute;
|
| 197 |
-
} else {
|
| 198 |
-
if ( ! is_null( $onclick ) ) {
|
| 199 |
-
return 'onclick="' . $onclick . '" ' . $link_attribute;
|
| 200 |
-
} else {
|
| 201 |
-
return $link_attribute;
|
| 202 |
-
}
|
| 203 |
-
}
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
/**
|
| 207 |
-
* Generate the full URL
|
| 208 |
-
*
|
| 209 |
-
* @param string $link
|
| 210 |
-
*
|
| 211 |
-
* @return string
|
| 212 |
-
*/
|
| 213 |
-
public function make_full_url( $link ) {
|
| 214 |
-
switch ( $link['type'] ) {
|
| 215 |
-
case 'download':
|
| 216 |
-
case 'internal':
|
| 217 |
-
case 'internal-as-outbound':
|
| 218 |
-
case 'outbound':
|
| 219 |
-
return $link['protocol'] . '://' . $link['original_url'];
|
| 220 |
-
break;
|
| 221 |
-
case 'email':
|
| 222 |
-
return 'mailto:' . $link['original_url'];
|
| 223 |
-
break;
|
| 224 |
-
}
|
| 225 |
-
}
|
| 226 |
}
|
| 227 |
|
| 228 |
}
|
| 5 |
|
| 6 |
if ( ! class_exists( 'Yoast_GA_Frontend' ) ) {
|
| 7 |
|
| 8 |
+
class Yoast_GA_Frontend {
|
| 9 |
|
| 10 |
+
protected $options;
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Class constructor
|
| 14 |
*/
|
| 15 |
public function __construct() {
|
| 16 |
+
|
| 17 |
+
$this->options = Yoast_GA_Options::instance()->options;
|
| 18 |
|
| 19 |
if ( isset( $this->options['tag_links_in_rss'] ) && $this->options['tag_links_in_rss'] == 1 ) {
|
| 20 |
add_filter( 'the_permalink_rss', array( $this, 'rsslinktagger' ), 99 );
|
| 22 |
|
| 23 |
// Check if the customer is running Universal or not (Enable in GA Settings -> Universal)
|
| 24 |
if ( isset( $this->options['enable_universal'] ) && $this->options['enable_universal'] == 1 ) {
|
| 25 |
+
new Yoast_GA_Universal;
|
|
|
|
| 26 |
} else {
|
| 27 |
+
new Yoast_GA_JS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
|
| 32 |
/**
|
| 54 |
return $guid;
|
| 55 |
}
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
}
|
| 58 |
|
| 59 |
}
|
frontend/class-ga-js.php
CHANGED
|
@@ -5,36 +5,18 @@
|
|
| 5 |
|
| 6 |
if ( ! class_exists( 'Yoast_GA_JS' ) ) {
|
| 7 |
|
| 8 |
-
class Yoast_GA_JS extends
|
| 9 |
-
public $link_regex;
|
| 10 |
-
|
| 11 |
-
public function __construct() {
|
| 12 |
-
|
| 13 |
-
$this->options = Yoast_GA_Options::instance()->options;
|
| 14 |
-
$this->link_regex = $this->get_regex();
|
| 15 |
-
|
| 16 |
-
add_action( 'wp_head', array( $this, 'tracking' ), 8 );
|
| 17 |
-
|
| 18 |
-
if ( $this->options['track_outbound'] == 1 ) {
|
| 19 |
-
// Check for outbound
|
| 20 |
-
add_filter( 'the_content', array( $this, 'the_content' ), 99 );
|
| 21 |
-
add_filter( 'widget_text', array( $this, 'widget_content' ), 99 );
|
| 22 |
-
add_filter( 'wp_list_bookmarks', array( $this, 'widget_content' ), 99 );
|
| 23 |
-
add_filter( 'wp_nav_menu', array( $this, 'widget_content' ), 99 );
|
| 24 |
-
add_filter( 'the_excerpt', array( $this, 'the_content' ), 99 );
|
| 25 |
-
add_filter( 'comment_text', array( $this, 'comment_text' ), 99 );
|
| 26 |
-
}
|
| 27 |
-
}
|
| 28 |
|
| 29 |
/**
|
| 30 |
* Function to output the GA Tracking code in the wp_head()
|
| 31 |
*
|
| 32 |
* @param bool $return_array
|
|
|
|
| 33 |
*/
|
| 34 |
public function tracking( $return_array = false ) {
|
| 35 |
global $wp_query;
|
| 36 |
|
| 37 |
-
if (
|
| 38 |
$gaq_push = array();
|
| 39 |
|
| 40 |
// Running action for adding possible code
|
|
@@ -156,7 +138,7 @@ if ( ! class_exists( 'Yoast_GA_JS' ) ) {
|
|
| 156 |
*
|
| 157 |
* @return mixed
|
| 158 |
*/
|
| 159 |
-
|
| 160 |
$link = $this->get_target( $label, $matches );
|
| 161 |
|
| 162 |
// bail early for links that we can't handle
|
|
@@ -201,123 +183,6 @@ if ( ! class_exists( 'Yoast_GA_JS' ) ) {
|
|
| 201 |
return '<a href="' . $full_url . '" ' . $link['link_attributes'] . '>' . $link['link_text'] . '</a>';
|
| 202 |
}
|
| 203 |
|
| 204 |
-
/**
|
| 205 |
-
* Parse article link
|
| 206 |
-
*
|
| 207 |
-
* @param $matches
|
| 208 |
-
*
|
| 209 |
-
* @return mixed
|
| 210 |
-
*/
|
| 211 |
-
public function parse_article_link( $matches ) {
|
| 212 |
-
return $this->output_parse_link( 'outbound-article', $matches );
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
/**
|
| 216 |
-
* Parse comment link
|
| 217 |
-
*
|
| 218 |
-
* @param $matches
|
| 219 |
-
*
|
| 220 |
-
* @return mixed
|
| 221 |
-
*/
|
| 222 |
-
public function parse_comment_link( $matches ) {
|
| 223 |
-
return $this->output_parse_link( 'outbound-comment', $matches );
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
/**
|
| 227 |
-
* Parse widget link
|
| 228 |
-
*
|
| 229 |
-
* @param $matches
|
| 230 |
-
*
|
| 231 |
-
* @return mixed
|
| 232 |
-
*/
|
| 233 |
-
public function parse_widget_link( $matches ) {
|
| 234 |
-
return $this->output_parse_link( 'outbound-widget', $matches );
|
| 235 |
-
}
|
| 236 |
-
|
| 237 |
-
/**
|
| 238 |
-
* Parse menu link
|
| 239 |
-
*
|
| 240 |
-
* @param $matches
|
| 241 |
-
*
|
| 242 |
-
* @return mixed
|
| 243 |
-
*/
|
| 244 |
-
public function parse_nav_menu( $matches ) {
|
| 245 |
-
return $this->output_parse_link( 'outbound-menu', $matches );
|
| 246 |
-
}
|
| 247 |
-
|
| 248 |
-
/**
|
| 249 |
-
* Parse the_content or the_excerpt for links
|
| 250 |
-
*
|
| 251 |
-
* @param $text
|
| 252 |
-
*
|
| 253 |
-
* @return mixed
|
| 254 |
-
*/
|
| 255 |
-
public function the_content( $text ) {
|
| 256 |
-
if ( false == $this->do_tracking() ) {
|
| 257 |
-
return $text;
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
-
if ( ! is_feed() ) {
|
| 261 |
-
$text = preg_replace_callback( $this->link_regex, array( $this, 'parse_article_link' ), $text );
|
| 262 |
-
}
|
| 263 |
-
|
| 264 |
-
return $text;
|
| 265 |
-
}
|
| 266 |
-
|
| 267 |
-
/**
|
| 268 |
-
* Parse the widget content for links
|
| 269 |
-
*
|
| 270 |
-
* @param $text
|
| 271 |
-
*
|
| 272 |
-
* @return mixed
|
| 273 |
-
*/
|
| 274 |
-
public function widget_content( $text ) {
|
| 275 |
-
if ( ! $this->do_tracking() ) {
|
| 276 |
-
return $text;
|
| 277 |
-
}
|
| 278 |
-
$text = preg_replace_callback( $this->link_regex, array( $this, 'parse_widget_link' ), $text );
|
| 279 |
-
|
| 280 |
-
return $text;
|
| 281 |
-
}
|
| 282 |
-
|
| 283 |
-
/**
|
| 284 |
-
* Parse the nav menu for links
|
| 285 |
-
*
|
| 286 |
-
* @param $text
|
| 287 |
-
*
|
| 288 |
-
* @return mixed
|
| 289 |
-
*/
|
| 290 |
-
public function nav_menu( $text ) {
|
| 291 |
-
if ( ! $this->do_tracking() ) {
|
| 292 |
-
return $text;
|
| 293 |
-
}
|
| 294 |
-
|
| 295 |
-
if ( ! is_feed() ) {
|
| 296 |
-
$text = preg_replace_callback( $this->link_regex, array( $this, 'parse_nav_menu' ), $text );
|
| 297 |
-
}
|
| 298 |
-
|
| 299 |
-
return $text;
|
| 300 |
-
}
|
| 301 |
-
|
| 302 |
-
/**
|
| 303 |
-
* Parse comment text for links
|
| 304 |
-
*
|
| 305 |
-
* @param $text
|
| 306 |
-
*
|
| 307 |
-
* @return mixed
|
| 308 |
-
*/
|
| 309 |
-
public function comment_text( $text ) {
|
| 310 |
-
if ( ! $this->do_tracking() ) {
|
| 311 |
-
return $text;
|
| 312 |
-
}
|
| 313 |
-
|
| 314 |
-
if ( ! is_feed() ) {
|
| 315 |
-
$text = preg_replace_callback( $this->link_regex, array( $this, 'parse_comment_link' ), $text );
|
| 316 |
-
}
|
| 317 |
-
|
| 318 |
-
return $text;
|
| 319 |
-
}
|
| 320 |
-
|
| 321 |
}
|
| 322 |
|
| 323 |
}
|
| 5 |
|
| 6 |
if ( ! class_exists( 'Yoast_GA_JS' ) ) {
|
| 7 |
|
| 8 |
+
class Yoast_GA_JS extends Yoast_GA_Tracking {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Function to output the GA Tracking code in the wp_head()
|
| 12 |
*
|
| 13 |
* @param bool $return_array
|
| 14 |
+
* @return array
|
| 15 |
*/
|
| 16 |
public function tracking( $return_array = false ) {
|
| 17 |
global $wp_query;
|
| 18 |
|
| 19 |
+
if ( $this->do_tracking && ! is_preview() ) {
|
| 20 |
$gaq_push = array();
|
| 21 |
|
| 22 |
// Running action for adding possible code
|
| 138 |
*
|
| 139 |
* @return mixed
|
| 140 |
*/
|
| 141 |
+
protected function output_parse_link( $label, $matches ) {
|
| 142 |
$link = $this->get_target( $label, $matches );
|
| 143 |
|
| 144 |
// bail early for links that we can't handle
|
| 183 |
return '<a href="' . $full_url . '" ' . $link['link_attributes'] . '>' . $link['link_text'] . '</a>';
|
| 184 |
}
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
|
| 188 |
}
|
frontend/class-universal.php
CHANGED
|
@@ -5,25 +5,7 @@
|
|
| 5 |
|
| 6 |
if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
|
| 7 |
|
| 8 |
-
class Yoast_GA_Universal extends
|
| 9 |
-
public $link_regex;
|
| 10 |
-
|
| 11 |
-
public function __construct() {
|
| 12 |
-
$this->options = Yoast_GA_Options::instance()->options;
|
| 13 |
-
$this->link_regex = $this->get_regex();
|
| 14 |
-
|
| 15 |
-
add_action( 'wp_head', array( $this, 'tracking' ), 8 );
|
| 16 |
-
|
| 17 |
-
if ( $this->options['track_outbound'] == 1 ) {
|
| 18 |
-
// Check for outbound option
|
| 19 |
-
add_filter( 'the_content', array( $this, 'the_content' ), 99 );
|
| 20 |
-
add_filter( 'widget_text', array( $this, 'widget_content' ), 99 );
|
| 21 |
-
add_filter( 'wp_list_bookmarks', array( $this, 'widget_content' ), 99 );
|
| 22 |
-
add_filter( 'wp_nav_menu', array( $this, 'widget_content' ), 99 );
|
| 23 |
-
add_filter( 'the_excerpt', array( $this, 'the_content' ), 99 );
|
| 24 |
-
add_filter( 'comment_text', array( $this, 'comment_text' ), 99 );
|
| 25 |
-
}
|
| 26 |
-
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Function to output the GA Tracking code in the wp_head()
|
|
@@ -31,7 +13,7 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
|
|
| 31 |
public function tracking( $return_array = false ) {
|
| 32 |
global $wp_query;
|
| 33 |
|
| 34 |
-
if ( $this->do_tracking
|
| 35 |
$gaq_push = array();
|
| 36 |
|
| 37 |
// Running action for adding possible code
|
|
@@ -148,7 +130,7 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
|
|
| 148 |
*
|
| 149 |
* @return mixed
|
| 150 |
*/
|
| 151 |
-
|
| 152 |
$link = $this->get_target( $label, $matches );
|
| 153 |
|
| 154 |
// bail early for links that we can't handle
|
|
@@ -196,121 +178,5 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
|
|
| 196 |
|
| 197 |
}
|
| 198 |
|
| 199 |
-
/**
|
| 200 |
-
* Parse article link
|
| 201 |
-
*
|
| 202 |
-
* @param $matches
|
| 203 |
-
*
|
| 204 |
-
* @return mixed
|
| 205 |
-
*/
|
| 206 |
-
public function parse_article_link( $matches ) {
|
| 207 |
-
return $this->output_parse_link( 'outbound-article', $matches );
|
| 208 |
-
}
|
| 209 |
-
|
| 210 |
-
/**
|
| 211 |
-
* Parse comment link
|
| 212 |
-
*
|
| 213 |
-
* @param $matches
|
| 214 |
-
*
|
| 215 |
-
* @return mixed
|
| 216 |
-
*/
|
| 217 |
-
public function parse_comment_link( $matches ) {
|
| 218 |
-
return $this->output_parse_link( 'outbound-comment', $matches );
|
| 219 |
-
}
|
| 220 |
-
|
| 221 |
-
/**
|
| 222 |
-
* Parse widget link
|
| 223 |
-
*
|
| 224 |
-
* @param $matches
|
| 225 |
-
*
|
| 226 |
-
* @return mixed
|
| 227 |
-
*/
|
| 228 |
-
public function parse_widget_link( $matches ) {
|
| 229 |
-
return $this->output_parse_link( 'outbound-widget', $matches );
|
| 230 |
-
}
|
| 231 |
-
|
| 232 |
-
/**
|
| 233 |
-
* Parse menu link
|
| 234 |
-
*
|
| 235 |
-
* @param $matches
|
| 236 |
-
*
|
| 237 |
-
* @return mixed
|
| 238 |
-
*/
|
| 239 |
-
public function parse_nav_menu( $matches ) {
|
| 240 |
-
return $this->output_parse_link( 'outbound-menu', $matches );
|
| 241 |
-
}
|
| 242 |
-
|
| 243 |
-
/**
|
| 244 |
-
* Parse the_content or the_excerpt for links
|
| 245 |
-
*
|
| 246 |
-
* @param $text
|
| 247 |
-
*
|
| 248 |
-
* @return mixed
|
| 249 |
-
*/
|
| 250 |
-
public function the_content( $text ) {
|
| 251 |
-
if ( false == $this->do_tracking() ) {
|
| 252 |
-
return $text;
|
| 253 |
-
}
|
| 254 |
-
|
| 255 |
-
if ( ! is_feed() ) {
|
| 256 |
-
$text = preg_replace_callback( $this->link_regex, array( $this, 'parse_article_link' ), $text );
|
| 257 |
-
}
|
| 258 |
-
|
| 259 |
-
return $text;
|
| 260 |
-
}
|
| 261 |
-
|
| 262 |
-
/**
|
| 263 |
-
* Parse the widget content for links
|
| 264 |
-
*
|
| 265 |
-
* @param $text
|
| 266 |
-
*
|
| 267 |
-
* @return mixed
|
| 268 |
-
*/
|
| 269 |
-
public function widget_content( $text ) {
|
| 270 |
-
if ( ! $this->do_tracking() ) {
|
| 271 |
-
return $text;
|
| 272 |
-
}
|
| 273 |
-
$text = preg_replace_callback( $this->link_regex, array( $this, 'parse_widget_link' ), $text );
|
| 274 |
-
|
| 275 |
-
return $text;
|
| 276 |
-
}
|
| 277 |
-
|
| 278 |
-
/**
|
| 279 |
-
* Parse the nav menu for links
|
| 280 |
-
*
|
| 281 |
-
* @param $text
|
| 282 |
-
*
|
| 283 |
-
* @return mixed
|
| 284 |
-
*/
|
| 285 |
-
public function nav_menu( $text ) {
|
| 286 |
-
if ( ! $this->do_tracking() ) {
|
| 287 |
-
return $text;
|
| 288 |
-
}
|
| 289 |
-
|
| 290 |
-
if ( ! is_feed() ) {
|
| 291 |
-
$text = preg_replace_callback( $this->link_regex, array( $this, 'parse_nav_menu' ), $text );
|
| 292 |
-
}
|
| 293 |
-
|
| 294 |
-
return $text;
|
| 295 |
-
}
|
| 296 |
-
|
| 297 |
-
/**
|
| 298 |
-
* Parse comment text for links
|
| 299 |
-
*
|
| 300 |
-
* @param $text
|
| 301 |
-
*
|
| 302 |
-
* @return mixed
|
| 303 |
-
*/
|
| 304 |
-
public function comment_text( $text ) {
|
| 305 |
-
if ( ! $this->do_tracking() ) {
|
| 306 |
-
return $text;
|
| 307 |
-
}
|
| 308 |
-
|
| 309 |
-
if ( ! is_feed() ) {
|
| 310 |
-
$text = preg_replace_callback( $this->link_regex, array( $this, 'parse_comment_link' ), $text );
|
| 311 |
-
}
|
| 312 |
-
|
| 313 |
-
return $text;
|
| 314 |
-
}
|
| 315 |
}
|
| 316 |
}
|
| 5 |
|
| 6 |
if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
|
| 7 |
|
| 8 |
+
class Yoast_GA_Universal extends Yoast_GA_Tracking {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Function to output the GA Tracking code in the wp_head()
|
| 13 |
public function tracking( $return_array = false ) {
|
| 14 |
global $wp_query;
|
| 15 |
|
| 16 |
+
if ( $this->do_tracking && ! is_preview() ) {
|
| 17 |
$gaq_push = array();
|
| 18 |
|
| 19 |
// Running action for adding possible code
|
| 130 |
*
|
| 131 |
* @return mixed
|
| 132 |
*/
|
| 133 |
+
protected function output_parse_link( $label, $matches ) {
|
| 134 |
$link = $this->get_target( $label, $matches );
|
| 135 |
|
| 136 |
// bail early for links that we can't handle
|
| 178 |
|
| 179 |
}
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
}
|
| 182 |
}
|
frontend/views/tracking-universal.php
CHANGED
|
@@ -20,4 +20,4 @@
|
|
| 20 |
?>
|
| 21 |
|
| 22 |
</script>
|
| 23 |
-
<!-- / Yoast Google Analytics -->
|
| 20 |
?>
|
| 21 |
|
| 22 |
</script>
|
| 23 |
+
<!-- / Yoast Google Analytics -->
|
googleanalytics.php
CHANGED
|
@@ -4,7 +4,7 @@ Plugin Name: Google Analytics by Yoast
|
|
| 4 |
Plugin URI: https://yoast.com/wordpress/plugins/google-analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=wpgaplugin&utm_content=v504
|
| 5 |
Description: This plugin makes it simple to add Google Analytics to your WordPress blog, adding lots of features, eg. error page, search result and automatic clickout and download tracking.
|
| 6 |
Author: Team Yoast
|
| 7 |
-
Version: 5.2.
|
| 8 |
Requires at least: 3.8
|
| 9 |
Author URI: https://yoast.com/
|
| 10 |
License: GPL v3
|
|
@@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
| 30 |
|
| 31 |
// This plugin was originally based on Rich Boakes' Analytics plugin: http://boakes.org/analytics, but has since been rewritten and refactored multiple times.
|
| 32 |
|
| 33 |
-
define( 'GAWP_VERSION', '5.2.
|
| 34 |
|
| 35 |
define( 'GAWP_FILE', __FILE__ );
|
| 36 |
|
| 4 |
Plugin URI: https://yoast.com/wordpress/plugins/google-analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=wpgaplugin&utm_content=v504
|
| 5 |
Description: This plugin makes it simple to add Google Analytics to your WordPress blog, adding lots of features, eg. error page, search result and automatic clickout and download tracking.
|
| 6 |
Author: Team Yoast
|
| 7 |
+
Version: 5.2.8
|
| 8 |
Requires at least: 3.8
|
| 9 |
Author URI: https://yoast.com/
|
| 10 |
License: GPL v3
|
| 30 |
|
| 31 |
// This plugin was originally based on Rich Boakes' Analytics plugin: http://boakes.org/analytics, but has since been rewritten and refactored multiple times.
|
| 32 |
|
| 33 |
+
define( 'GAWP_VERSION', '5.2.8' );
|
| 34 |
|
| 35 |
define( 'GAWP_FILE', __FILE__ );
|
| 36 |
|
includes/class-autoload.php
CHANGED
|
@@ -16,8 +16,8 @@ if ( ! class_exists( 'Yoast_GA_Autoload' ) ) {
|
|
| 16 |
'yoast_ga_options' => 'includes/class-options',
|
| 17 |
'yoast_ga_utils' => 'includes/class-utils',
|
| 18 |
|
| 19 |
-
|
| 20 |
// Frontend classes
|
|
|
|
| 21 |
'yoast_ga_frontend' => 'frontend/class-frontend',
|
| 22 |
'yoast_ga_universal' => 'frontend/class-universal',
|
| 23 |
'yoast_ga_js' => 'frontend/class-ga-js',
|
|
@@ -26,7 +26,6 @@ if ( ! class_exists( 'Yoast_GA_Autoload' ) ) {
|
|
| 26 |
'yoast_ga_admin' => 'admin/class-admin',
|
| 27 |
'yoast_ga_admin_menu' => 'admin/class-admin-menu',
|
| 28 |
'yoast_google_analytics' => 'admin/class-google-analytics',
|
| 29 |
-
'yoast_ga_admin_ga_js' => 'admin/class-admin-ga-js',
|
| 30 |
'yoast_ga_admin_assets' => 'admin/class-admin-assets',
|
| 31 |
'yoast_ga_admin_form' => 'admin/class-admin-form',
|
| 32 |
|
| 16 |
'yoast_ga_options' => 'includes/class-options',
|
| 17 |
'yoast_ga_utils' => 'includes/class-utils',
|
| 18 |
|
|
|
|
| 19 |
// Frontend classes
|
| 20 |
+
'yoast_ga_tracking' => 'frontend/abstract-class-tracking',
|
| 21 |
'yoast_ga_frontend' => 'frontend/class-frontend',
|
| 22 |
'yoast_ga_universal' => 'frontend/class-universal',
|
| 23 |
'yoast_ga_js' => 'frontend/class-ga-js',
|
| 26 |
'yoast_ga_admin' => 'admin/class-admin',
|
| 27 |
'yoast_ga_admin_menu' => 'admin/class-admin-menu',
|
| 28 |
'yoast_google_analytics' => 'admin/class-google-analytics',
|
|
|
|
| 29 |
'yoast_ga_admin_assets' => 'admin/class-admin-assets',
|
| 30 |
'yoast_ga_admin_form' => 'admin/class-admin-form',
|
| 31 |
|
readme.txt
CHANGED
|
@@ -4,7 +4,7 @@ Donate link: https://yoast.com/donate/
|
|
| 4 |
Tags: analytics, google analytics, statistics, tracking, stats, google, yoast
|
| 5 |
Requires at least: 3.8
|
| 6 |
Tested up to: 4.1
|
| 7 |
-
Stable tag: 5.2.
|
| 8 |
|
| 9 |
Track your WordPress site easily with the latest tracking codes and lots added data for search result pages and error pages.
|
| 10 |
|
|
@@ -49,6 +49,14 @@ This section describes how to install the plugin and get it working.
|
|
| 49 |
|
| 50 |
== Changelog ==
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
= 5.2.7 =
|
| 53 |
|
| 54 |
Release Date: December 18th, 2014
|
| 4 |
Tags: analytics, google analytics, statistics, tracking, stats, google, yoast
|
| 5 |
Requires at least: 3.8
|
| 6 |
Tested up to: 4.1
|
| 7 |
+
Stable tag: 5.2.8
|
| 8 |
|
| 9 |
Track your WordPress site easily with the latest tracking codes and lots added data for search result pages and error pages.
|
| 10 |
|
| 49 |
|
| 50 |
== Changelog ==
|
| 51 |
|
| 52 |
+
= 5.2.8 =
|
| 53 |
+
|
| 54 |
+
Release Date: January 8th, 2015
|
| 55 |
+
|
| 56 |
+
* Bugfixes:
|
| 57 |
+
* Makes sure reauthentication notice is only shown on the GA dashboard page.
|
| 58 |
+
* Fixes a couple of situations in which the GA reauthentication notice was shown erroneously.
|
| 59 |
+
|
| 60 |
= 5.2.7 =
|
| 61 |
|
| 62 |
Release Date: December 18th, 2014
|
