Version Description
- Fix : Google Analytics connection: update OAuth2 authorization
Download this release
Release Info
Developer | JoomUnited |
Plugin | WP Meta SEO |
Version | 4.4.8 |
Comparing to | |
See all releases |
Code changes from version 4.4.7 to 4.4.8
- assets/css/main.css +3 -0
- inc/class.metaseo-admin.php +9 -251
- inc/class.metaseo-metabox.php +1 -1
- inc/google-tag-manager/wpms-tagmanager-api.php +6 -11
- inc/google_analytics/wpmsgapi.php +8 -28
- inc/google_analytics/wpmstools.php +318 -0
- inc/install-wizard/content/viewGoogleAnalytics.php +1 -12
- inc/install-wizard/handler-wizard.php +2 -97
- inc/pages/google-services/gg-services-connect.php +19 -46
- languages/wp-meta-seo-en_US.mo +0 -0
- readme.txt +5 -2
- wp-meta-seo.php +48 -2
assets/css/main.css
CHANGED
@@ -925,6 +925,9 @@ input[type=checkbox]:focus {
|
|
925 |
line-height: 22px;
|
926 |
min-height: 30px;
|
927 |
}
|
|
|
|
|
|
|
928 |
|
929 |
.wp-meta-seo_page_metaseo_content_meta .wpms-form-table .custom-bulk-content-metatitle {
|
930 |
height: 32px;
|
925 |
line-height: 22px;
|
926 |
min-height: 30px;
|
927 |
}
|
928 |
+
.wp-meta-seo_page_metaseo_google_analytics .wpms_ga_info .ju-setting-label {
|
929 |
+
min-width: 160px;
|
930 |
+
}
|
931 |
|
932 |
.wp-meta-seo_page_metaseo_content_meta .wpms-form-table .custom-bulk-content-metatitle {
|
933 |
height: 32px;
|
inc/class.metaseo-admin.php
CHANGED
@@ -4002,232 +4002,6 @@ class MetaSeoAdmin
|
|
4002 |
$this->error_timeout = $midnight - time();
|
4003 |
}
|
4004 |
|
4005 |
-
/**
|
4006 |
-
* Get Google analytics 4 properties
|
4007 |
-
*
|
4008 |
-
* @param string $account_id GA4 account ID
|
4009 |
-
*
|
4010 |
-
* @return array
|
4011 |
-
*/
|
4012 |
-
public function get_ga4_properties($account_id)
|
4013 |
-
{
|
4014 |
-
$query_url = 'https://analyticsadmin.googleapis.com/v1alpha/properties';
|
4015 |
-
$query_url = add_query_arg('access_token', $this->google_alanytics['googleCredentials']['access_token'], $query_url);
|
4016 |
-
$properties = array();
|
4017 |
-
$pageToken = null;
|
4018 |
-
do {
|
4019 |
-
try {
|
4020 |
-
$additional = array();
|
4021 |
-
$additional['filter'] = 'parent:accounts/' . $account_id;
|
4022 |
-
$additional['pageSize'] = 40;
|
4023 |
-
if ($pageToken) {
|
4024 |
-
$additional['pageToken'] = $pageToken;
|
4025 |
-
}
|
4026 |
-
|
4027 |
-
$call_args = array();
|
4028 |
-
$call_args['method'] = 'GET';
|
4029 |
-
$call_args['body'] = $additional;
|
4030 |
-
$response = wp_remote_request($query_url, $call_args);
|
4031 |
-
if (!is_wp_error($response)) {
|
4032 |
-
$body = wp_remote_retrieve_body($response);
|
4033 |
-
$body = json_decode($body);
|
4034 |
-
}
|
4035 |
-
|
4036 |
-
$items = isset($body->properties) ? $body->properties : array();
|
4037 |
-
$properties = array_merge($properties, $items);
|
4038 |
-
if (isset($body->nextPageToken)) {
|
4039 |
-
$pageToken = $body->nextPageToken;
|
4040 |
-
} else {
|
4041 |
-
$pageToken = null;
|
4042 |
-
}
|
4043 |
-
} catch (Exception $e) {
|
4044 |
-
$pageToken = null;
|
4045 |
-
}
|
4046 |
-
} while ($pageToken);
|
4047 |
-
|
4048 |
-
return $properties;
|
4049 |
-
}
|
4050 |
-
|
4051 |
-
/**
|
4052 |
-
* Retrieve all data stream google analytics 4 property
|
4053 |
-
*
|
4054 |
-
* @param string $property_id GA4 property ID
|
4055 |
-
*
|
4056 |
-
* @return array
|
4057 |
-
*/
|
4058 |
-
public function webDataStreamsList($property_id)
|
4059 |
-
{
|
4060 |
-
$query_url = 'https://analyticsadmin.googleapis.com/v1alpha/properties/' . $property_id . '/dataStreams';
|
4061 |
-
$query_url = add_query_arg('access_token', $this->google_alanytics['googleCredentials']['access_token'], $query_url);
|
4062 |
-
$webDataStreams = array();
|
4063 |
-
$pageToken = null;
|
4064 |
-
do {
|
4065 |
-
try {
|
4066 |
-
$additional = array();
|
4067 |
-
$additional['pageSize'] = 40;
|
4068 |
-
if ($pageToken) {
|
4069 |
-
$additional['pageToken'] = $pageToken;
|
4070 |
-
}
|
4071 |
-
|
4072 |
-
$call_args = array();
|
4073 |
-
$call_args['method'] = 'GET';
|
4074 |
-
$call_args['body'] = $additional;
|
4075 |
-
|
4076 |
-
$response = wp_remote_request($query_url, $call_args);
|
4077 |
-
if (!is_wp_error($response)) {
|
4078 |
-
$body = wp_remote_retrieve_body($response);
|
4079 |
-
$body = json_decode($body);
|
4080 |
-
}
|
4081 |
-
|
4082 |
-
$items = isset($body->dataStreams) ? $body->dataStreams : array();
|
4083 |
-
$webDataStreams = array_merge($webDataStreams, $items);
|
4084 |
-
if (isset($body->nextPageToken)) {
|
4085 |
-
$pageToken = $body->nextPageToken;
|
4086 |
-
} else {
|
4087 |
-
$pageToken = null;
|
4088 |
-
}
|
4089 |
-
} catch (Exception $e) {
|
4090 |
-
$pageToken = null;
|
4091 |
-
}
|
4092 |
-
} while ($pageToken);
|
4093 |
-
|
4094 |
-
return $webDataStreams;
|
4095 |
-
}
|
4096 |
-
|
4097 |
-
/**
|
4098 |
-
* Retrieves all Google Analytics Views with details
|
4099 |
-
*
|
4100 |
-
* @return array
|
4101 |
-
*/
|
4102 |
-
public function refreshProfiles()
|
4103 |
-
{
|
4104 |
-
try {
|
4105 |
-
$ga_dash_profile_list = array();
|
4106 |
-
$startindex = 1;
|
4107 |
-
$totalresults = 65535; // use something big
|
4108 |
-
while ($startindex < $totalresults) {
|
4109 |
-
// Get profile for google analytics 4 properties (GA4)
|
4110 |
-
$accounts = $this->service->management_accounts->listManagementAccounts();
|
4111 |
-
$accounts_id = array();
|
4112 |
-
$ga4_profile_list = array();
|
4113 |
-
$ua_profile_list = array();
|
4114 |
-
if (count($accounts) > 0) {
|
4115 |
-
foreach ($accounts as $account) {
|
4116 |
-
$accounts_id[] = $account->id;
|
4117 |
-
}
|
4118 |
-
|
4119 |
-
$ga4_properties = array();
|
4120 |
-
foreach ($accounts_id as $account_id) {
|
4121 |
-
$ga4_properties = array_merge($ga4_properties, $this->get_ga4_properties($account_id));
|
4122 |
-
}
|
4123 |
-
|
4124 |
-
if (!empty($ga4_properties)) {
|
4125 |
-
$webDataStreams = array();
|
4126 |
-
foreach ($ga4_properties as $ga4_property) {
|
4127 |
-
$streamList = $this->webDataStreamsList(str_replace('properties/', '', $ga4_property->name));
|
4128 |
-
if (!empty($streamList) && is_array($streamList)) {
|
4129 |
-
$webDataStreams = array_merge($webDataStreams, $streamList);
|
4130 |
-
}
|
4131 |
-
}
|
4132 |
-
|
4133 |
-
foreach ($webDataStreams as $profile) {
|
4134 |
-
$profile_name = $profile->name;
|
4135 |
-
$profile_name_arr = explode('/', $profile_name);
|
4136 |
-
$property_id = $profile_name_arr[1];
|
4137 |
-
$webDataStream_id = $profile_name_arr[3];
|
4138 |
-
|
4139 |
-
$ga4_profile_list[] = array(
|
4140 |
-
$profile->displayName,
|
4141 |
-
$webDataStream_id, // todo:: check this value
|
4142 |
-
$property_id,
|
4143 |
-
$profile->webStreamData->defaultUri,
|
4144 |
-
'GA4',
|
4145 |
-
'',
|
4146 |
-
'',
|
4147 |
-
'',
|
4148 |
-
$profile->webStreamData->measurementId
|
4149 |
-
);
|
4150 |
-
}
|
4151 |
-
}
|
4152 |
-
}
|
4153 |
-
|
4154 |
-
// Get profile for google universal analytics (UA)
|
4155 |
-
$profiles = $this->service->management_profiles->listManagementProfiles(
|
4156 |
-
'~all',
|
4157 |
-
'~all',
|
4158 |
-
array(
|
4159 |
-
'start-index' => $startindex
|
4160 |
-
)
|
4161 |
-
);
|
4162 |
-
$items = $profiles->getItems();
|
4163 |
-
$totalresults = $profiles->getTotalResults();
|
4164 |
-
|
4165 |
-
if ($totalresults > 0) {
|
4166 |
-
foreach ($items as $profile) {
|
4167 |
-
$timetz = new DateTimeZone($profile->getTimezone());
|
4168 |
-
$localtime = new DateTime('now', $timetz);
|
4169 |
-
$timeshift = strtotime($localtime->format('Y-m-d H:i:s')) - time();
|
4170 |
-
$ua_profile_list[] = array(
|
4171 |
-
$profile->getName(),
|
4172 |
-
$profile->getId(),
|
4173 |
-
$profile->getwebPropertyId(),
|
4174 |
-
$profile->getwebsiteUrl(),
|
4175 |
-
'UA',
|
4176 |
-
$timeshift,
|
4177 |
-
$profile->getTimezone(),
|
4178 |
-
$profile->getDefaultPage(),
|
4179 |
-
''
|
4180 |
-
);
|
4181 |
-
$startindex++;
|
4182 |
-
}
|
4183 |
-
}
|
4184 |
-
/*
|
4185 |
-
$ga_dash_profile_list[
|
4186 |
-
view_name/stream_name,
|
4187 |
-
view_id/stream_id,
|
4188 |
-
property_id
|
4189 |
-
website_url,
|
4190 |
-
type_code,
|
4191 |
-
time_shift,
|
4192 |
-
time_zone,
|
4193 |
-
default_page,
|
4194 |
-
measurementId
|
4195 |
-
]*/
|
4196 |
-
$ga_dash_profile_list = array_merge($ga4_profile_list, $ua_profile_list);
|
4197 |
-
}
|
4198 |
-
|
4199 |
-
if (empty($ga_dash_profile_list)) {
|
4200 |
-
WpmsGaTools::setCache(
|
4201 |
-
'last_error',
|
4202 |
-
date('Y-m-d H:i:s') . ': No properties were found in this account!',
|
4203 |
-
$this->error_timeout
|
4204 |
-
);
|
4205 |
-
} else {
|
4206 |
-
WpmsGaTools::deleteCache('last_error');
|
4207 |
-
}
|
4208 |
-
return $ga_dash_profile_list;
|
4209 |
-
} catch (WPMSGoogle\Service\Exception $e) {
|
4210 |
-
WpmsGaTools::setCache(
|
4211 |
-
'last_error',
|
4212 |
-
date('Y-m-d H:i:s') . ': ' . esc_html('(' . $e->getCode() . ') ' . $e->getMessage()),
|
4213 |
-
$this->error_timeout
|
4214 |
-
);
|
4215 |
-
WpmsGaTools::setCache(
|
4216 |
-
'gapi_errors',
|
4217 |
-
$e->getCode(),
|
4218 |
-
$this->error_timeout
|
4219 |
-
);
|
4220 |
-
return $ga_dash_profile_list;
|
4221 |
-
} catch (Exception $e) {
|
4222 |
-
WpmsGaTools::setCache(
|
4223 |
-
'last_error',
|
4224 |
-
date('Y-m-d H:i:s') . ': ' . esc_html($e),
|
4225 |
-
$this->error_timeout
|
4226 |
-
);
|
4227 |
-
return $ga_dash_profile_list;
|
4228 |
-
}
|
4229 |
-
}
|
4230 |
-
|
4231 |
/**
|
4232 |
* Load the form for a WPSEO admin page
|
4233 |
*
|
@@ -4304,20 +4078,14 @@ class MetaSeoAdmin
|
|
4304 |
update_option('wpms_google_alanytics', $this->google_alanytics);
|
4305 |
}
|
4306 |
|
4307 |
-
require_once '
|
4308 |
-
$this->
|
4309 |
-
|
4310 |
-
|
4311 |
-
|
4312 |
-
|
4313 |
-
$this->client->setApplicationName('WP Meta SEO');
|
4314 |
-
$this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
|
4315 |
-
$this->setErrorTimeout();
|
4316 |
-
$this->client = WpmsGaTools::setClient($this->client, $this->google_alanytics, $this->access);
|
4317 |
-
$authUrl = $this->client->createAuthUrl();
|
4318 |
|
4319 |
-
$this->
|
4320 |
-
$controller = new WpmsGapiController();
|
4321 |
|
4322 |
if (!empty($_POST['wpms_gg_access_code'])) {
|
4323 |
$wpms_gg_access_code = $_POST['wpms_gg_access_code'];
|
@@ -4356,7 +4124,7 @@ class MetaSeoAdmin
|
|
4356 |
if (!empty($this->google_alanytics['profile_list'])) {
|
4357 |
$profiles = $this->google_alanytics['profile_list'];
|
4358 |
} else {
|
4359 |
-
$profiles = $this->
|
4360 |
}
|
4361 |
|
4362 |
$this->google_alanytics['code'] = $wpms_gg_access_code;
|
@@ -4949,17 +4717,7 @@ class MetaSeoAdmin
|
|
4949 |
update_option('wpms_google_alanytics', $google_alanytics);
|
4950 |
|
4951 |
require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php';
|
4952 |
-
|
4953 |
-
require_once WPMETASEO_PLUGIN_DIR . 'inc/lib/google-api/vendor/autoload.php';
|
4954 |
-
|
4955 |
-
$client = new WPMSGoogle\Client();
|
4956 |
-
$client->setScopes(array(
|
4957 |
-
'https://www.googleapis.com/auth/analytics.readonly'
|
4958 |
-
));
|
4959 |
-
$client->setAccessType('offline');
|
4960 |
-
$client->setApplicationName('WP Meta SEO');
|
4961 |
-
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
|
4962 |
-
$client = WpmsGaTools::setClient($client, array(), array($google_alanytics['wpmsga_dash_clientid'], $google_alanytics['wpmsga_dash_clientsecret']));
|
4963 |
$authUrl = $client->createAuthUrl();
|
4964 |
|
4965 |
if (!empty($authUrl)) {
|
4002 |
$this->error_timeout = $midnight - time();
|
4003 |
}
|
4004 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4005 |
/**
|
4006 |
* Load the form for a WPSEO admin page
|
4007 |
*
|
4078 |
update_option('wpms_google_alanytics', $this->google_alanytics);
|
4079 |
}
|
4080 |
|
4081 |
+
require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php';
|
4082 |
+
if (!empty($this->google_alanytics['wpmsga_dash_clientid']) && !empty($this->google_alanytics['wpmsga_dash_clientsecret'])) {
|
4083 |
+
$this->client = WpmsGaTools::initClient($this->google_alanytics['wpmsga_dash_clientid'], $this->google_alanytics['wpmsga_dash_clientsecret']);
|
4084 |
+
$controller = new WpmsGapiController();
|
4085 |
+
$this->service = new \WPMSGoogle\Service\Analytics($this->client);
|
4086 |
+
}
|
|
|
|
|
|
|
|
|
|
|
4087 |
|
4088 |
+
$this->setErrorTimeout();
|
|
|
4089 |
|
4090 |
if (!empty($_POST['wpms_gg_access_code'])) {
|
4091 |
$wpms_gg_access_code = $_POST['wpms_gg_access_code'];
|
4124 |
if (!empty($this->google_alanytics['profile_list'])) {
|
4125 |
$profiles = $this->google_alanytics['profile_list'];
|
4126 |
} else {
|
4127 |
+
$profiles = WpmsGaTools::refreshProfiles($this->service, $getAccessToken['access_token'], $this->error_timeout);
|
4128 |
}
|
4129 |
|
4130 |
$this->google_alanytics['code'] = $wpms_gg_access_code;
|
4717 |
update_option('wpms_google_alanytics', $google_alanytics);
|
4718 |
|
4719 |
require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php';
|
4720 |
+
$client = WpmsGaTools::initClient($google_alanytics['wpmsga_dash_clientid'], $google_alanytics['wpmsga_dash_clientsecret']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4721 |
$authUrl = $client->createAuthUrl();
|
4722 |
|
4723 |
if (!empty($authUrl)) {
|
inc/class.metaseo-metabox.php
CHANGED
@@ -814,7 +814,7 @@ class WPMSEOMetabox extends WPMSEOMeta
|
|
814 |
'application_name' => 'WP Meta SEO',
|
815 |
'client_id' => $client_id,
|
816 |
'client_secret' => $client_secret,
|
817 |
-
'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob',
|
818 |
'scopes' => array('https://www.googleapis.com/auth/webmasters'),
|
819 |
);
|
820 |
|
814 |
'application_name' => 'WP Meta SEO',
|
815 |
'client_id' => $client_id,
|
816 |
'client_secret' => $client_secret,
|
817 |
+
'redirect_uri' => admin_url('admin.php?page=metaseo_settings&task=wpms_gsc&tab=settings#search_console') , // 'urn:ietf:wg:oauth:2.0:oob',
|
818 |
'scopes' => array('https://www.googleapis.com/auth/webmasters'),
|
819 |
);
|
820 |
|
inc/google-tag-manager/wpms-tagmanager-api.php
CHANGED
@@ -28,23 +28,18 @@ if (!class_exists('WpmsTagManagerController')) {
|
|
28 |
public function __construct()
|
29 |
{
|
30 |
$google_alanytics = get_option('wpms_google_alanytics');
|
31 |
-
include_once(WPMETASEO_PLUGIN_DIR . 'inc/lib/google-api/vendor/autoload.php');
|
32 |
|
33 |
-
|
34 |
-
$this->client
|
35 |
-
|
36 |
-
'https://www.googleapis.com/auth/analytics.readonly'
|
37 |
-
));
|
38 |
-
$this->client->setAccessType('offline');
|
39 |
-
$this->client->setApplicationName('WP Meta SEO');
|
40 |
-
$this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
|
41 |
$this->managequota = 'u' . get_current_user_id() . 's' . get_current_blog_id();
|
42 |
-
$this->client->setClientId($google_alanytics['wpmsga_dash_clientid']);
|
43 |
-
$this->client->setClientSecret($google_alanytics['wpmsga_dash_clientsecret']);
|
44 |
$this->tagmanager_service = new WPMSGoogle_Service_TagManager($this->client);
|
45 |
if (!empty($google_alanytics['googleCredentials'])) {
|
46 |
$token = $google_alanytics['googleCredentials'];
|
47 |
if ($token) {
|
|
|
|
|
|
|
48 |
$this->client->setAccessToken($token);
|
49 |
}
|
50 |
}
|
28 |
public function __construct()
|
29 |
{
|
30 |
$google_alanytics = get_option('wpms_google_alanytics');
|
|
|
31 |
|
32 |
+
require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php';
|
33 |
+
$this->client = WpmsGaTools::initClient($google_alanytics['wpmsga_dash_clientid'], $google_alanytics['wpmsga_dash_clientsecret']);
|
34 |
+
|
|
|
|
|
|
|
|
|
|
|
35 |
$this->managequota = 'u' . get_current_user_id() . 's' . get_current_blog_id();
|
|
|
|
|
36 |
$this->tagmanager_service = new WPMSGoogle_Service_TagManager($this->client);
|
37 |
if (!empty($google_alanytics['googleCredentials'])) {
|
38 |
$token = $google_alanytics['googleCredentials'];
|
39 |
if ($token) {
|
40 |
+
if (WpmsGaTools::isTokenExpired($token)) {
|
41 |
+
$token = WpmsGaTools::getAccessTokenFromRefresh($google_alanytics['wpmsga_dash_clientid'], $google_alanytics['wpmsga_dash_clientsecret'], $token) ;
|
42 |
+
}
|
43 |
$this->client->setAccessToken($token);
|
44 |
}
|
45 |
}
|
inc/google_analytics/wpmsgapi.php
CHANGED
@@ -60,42 +60,22 @@ if (!class_exists('WpmsGapiController')) {
|
|
60 |
parent::__construct();
|
61 |
$google_alanytics = get_option('wpms_google_alanytics');
|
62 |
$this->wpmsga = WPMSGA();
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
// $curlversion = curl_version();
|
68 |
-
// if (isset($curlversion['version']) && (version_compare(PHP_VERSION, '5.3.0') >= 0)
|
69 |
-
// && version_compare($curlversion['version'], '7.10.8') >= 0 && defined('GADWP_IP_VERSION')
|
70 |
-
// && GADWP_IP_VERSION) {
|
71 |
-
// $config->setClassConfig(
|
72 |
-
// 'Google_IO_Curl',
|
73 |
-
// array(
|
74 |
-
// 'options' => array(
|
75 |
-
// CURLOPT_IPRESOLVE => GADWP_IP_VERSION
|
76 |
-
// )
|
77 |
-
// )
|
78 |
-
// ); // Force CURL_IPRESOLVE_V4 or CURL_IPRESOLVE_V6
|
79 |
-
// }
|
80 |
-
// }
|
81 |
-
|
82 |
-
$this->client = new WPMSGoogle\Client();
|
83 |
-
$this->client->setScopes(array(
|
84 |
-
'https://www.googleapis.com/auth/tagmanager.edit.containers',
|
85 |
-
'https://www.googleapis.com/auth/analytics.readonly'
|
86 |
-
));
|
87 |
-
$this->client->setAccessType('offline');
|
88 |
-
$this->client->setApplicationName('WP Meta SEO');
|
89 |
-
$this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
|
90 |
$this->setErrorTimeout();
|
91 |
$this->managequota = 'u' . get_current_user_id() . 's' . get_current_blog_id();
|
92 |
-
|
93 |
$this->service = new WPMSGoogle\Service\Analytics($this->client);
|
94 |
$this->service_ga4 = new WPMSGoogle\Service\AnalyticsData($this->client);
|
95 |
if (!empty($google_alanytics['googleCredentials'])) {
|
96 |
$token = $google_alanytics['googleCredentials'];
|
97 |
if ($token) {
|
98 |
try {
|
|
|
|
|
|
|
99 |
$this->client->setAccessToken($token);
|
100 |
} catch (WPMSGoogle\Service\Exception $e) {
|
101 |
WpmsGaTools::setCache(
|
60 |
parent::__construct();
|
61 |
$google_alanytics = get_option('wpms_google_alanytics');
|
62 |
$this->wpmsga = WPMSGA();
|
63 |
+
|
64 |
+
require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php';
|
65 |
+
$this->client = WpmsGaTools::initClient($google_alanytics['wpmsga_dash_clientid'], $google_alanytics['wpmsga_dash_clientsecret']);
|
66 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
$this->setErrorTimeout();
|
68 |
$this->managequota = 'u' . get_current_user_id() . 's' . get_current_blog_id();
|
69 |
+
|
70 |
$this->service = new WPMSGoogle\Service\Analytics($this->client);
|
71 |
$this->service_ga4 = new WPMSGoogle\Service\AnalyticsData($this->client);
|
72 |
if (!empty($google_alanytics['googleCredentials'])) {
|
73 |
$token = $google_alanytics['googleCredentials'];
|
74 |
if ($token) {
|
75 |
try {
|
76 |
+
if (WpmsGaTools::isTokenExpired($token)) {
|
77 |
+
$token = WpmsGaTools::getAccessTokenFromRefresh($google_alanytics['wpmsga_dash_clientid'], $google_alanytics['wpmsga_dash_clientsecret'], $token) ;
|
78 |
+
}
|
79 |
$this->client->setAccessToken($token);
|
80 |
} catch (WPMSGoogle\Service\Exception $e) {
|
81 |
WpmsGaTools::setCache(
|
inc/google_analytics/wpmstools.php
CHANGED
@@ -19,6 +19,37 @@ if (!class_exists('WpmsGaTools')) {
|
|
19 |
*/
|
20 |
class WpmsGaTools
|
21 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
/**
|
23 |
* Get google analytics client
|
24 |
*
|
@@ -41,6 +72,293 @@ if (!class_exists('WpmsGaTools')) {
|
|
41 |
return $client;
|
42 |
}
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
/**
|
45 |
* Get selected profile
|
46 |
*
|
19 |
*/
|
20 |
class WpmsGaTools
|
21 |
{
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Init google analytics client
|
25 |
+
*
|
26 |
+
* @param string $clientId Google client ID
|
27 |
+
* @param string $clientSecret Google client secret
|
28 |
+
*
|
29 |
+
* @return mixed
|
30 |
+
*/
|
31 |
+
public static function initClient($clientId, $clientSecret)
|
32 |
+
{
|
33 |
+
require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsgapi.php';
|
34 |
+
require_once WPMETASEO_PLUGIN_DIR . 'inc/lib/google-api/vendor/autoload.php';
|
35 |
+
|
36 |
+
$client = new WPMSGoogle\Client();
|
37 |
+
$client->setScopes(array(
|
38 |
+
'https://www.googleapis.com/auth/analytics.readonly'
|
39 |
+
));
|
40 |
+
$client->setAccessType('offline');
|
41 |
+
$client->setApprovalPrompt('force');
|
42 |
+
$client->setApplicationName('WP Meta SEO');
|
43 |
+
// $client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
|
44 |
+
$redirectUrl = admin_url('admin.php?page=metaseo_google_analytics&view=wpms_gg_service_data&task=wpms_ga');
|
45 |
+
$client->setRedirectUri($redirectUrl);
|
46 |
+
|
47 |
+
$client->setClientId($clientId);
|
48 |
+
$client->setClientSecret($clientSecret);
|
49 |
+
|
50 |
+
return $client;
|
51 |
+
}
|
52 |
+
|
53 |
/**
|
54 |
* Get google analytics client
|
55 |
*
|
72 |
return $client;
|
73 |
}
|
74 |
|
75 |
+
/**
|
76 |
+
* Check token expired
|
77 |
+
*
|
78 |
+
* @param array $token Token
|
79 |
+
*
|
80 |
+
* @return boolean
|
81 |
+
*/
|
82 |
+
public static function isTokenExpired($token)
|
83 |
+
{
|
84 |
+
$current = time();
|
85 |
+
if ($token['created'] + $token['expires_in'] < $current) {
|
86 |
+
return true;
|
87 |
+
}
|
88 |
+
return false;
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Get access token from refresh token
|
93 |
+
*
|
94 |
+
* @param string $clientId Client Id
|
95 |
+
* @param string $clientSecret Client secret
|
96 |
+
* @param array $token Token
|
97 |
+
*
|
98 |
+
* @return array
|
99 |
+
*/
|
100 |
+
public static function getAccessTokenFromRefresh($clientId, $clientSecret, $token)
|
101 |
+
{
|
102 |
+
if (isset($token['refresh_token'])) {
|
103 |
+
$curl_args = array(
|
104 |
+
'user-agent' => null,
|
105 |
+
'timeout' => 90,
|
106 |
+
'sslverify' => false,
|
107 |
+
'method' => 'POST',
|
108 |
+
'cookies' => array(),
|
109 |
+
'body' => array(
|
110 |
+
'client_id' => $clientId,
|
111 |
+
'client_secret' => $clientSecret,
|
112 |
+
'refresh_token' => $token['refresh_token'],
|
113 |
+
'grant_type' => 'refresh_token'
|
114 |
+
)
|
115 |
+
);
|
116 |
+
$response = wp_remote_request('https://accounts.google.com/o/oauth2/token', $curl_args);
|
117 |
+
|
118 |
+
if (!is_wp_error($response)) {
|
119 |
+
$body = wp_remote_retrieve_body($response);
|
120 |
+
$body = json_decode($body);
|
121 |
+
|
122 |
+
if (!empty($body->access_token)) {
|
123 |
+
$token['access_token'] = $body->access_token;
|
124 |
+
if (isset($body->refresh_token)) {
|
125 |
+
$token['refresh_token'] = $body->refresh_token;
|
126 |
+
}
|
127 |
+
$token['expires_in'] = $body->expires_in;
|
128 |
+
$token['created'] = time();
|
129 |
+
|
130 |
+
$google_analytics = get_option('wpms_google_alanytics');
|
131 |
+
$google_analytics['googleCredentials'] = $token;
|
132 |
+
update_option('wpms_google_alanytics', $google_analytics);
|
133 |
+
}
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
return $token;
|
138 |
+
}
|
139 |
+
|
140 |
+
/**
|
141 |
+
* Retrieves all Google Analytics Views with details
|
142 |
+
*
|
143 |
+
* @param object $service Google service
|
144 |
+
* @param string $access_token Access token
|
145 |
+
* @param object $error_timeout Error timeout
|
146 |
+
*
|
147 |
+
* @return array
|
148 |
+
*/
|
149 |
+
public static function refreshProfiles($service, $access_token, $error_timeout)
|
150 |
+
{
|
151 |
+
try {
|
152 |
+
$ga_dash_profile_list = array();
|
153 |
+
$startindex = 1;
|
154 |
+
$totalresults = 65535; // use something big
|
155 |
+
while ($startindex < $totalresults) {
|
156 |
+
// Get profile for google analytics 4 properties (GA4)
|
157 |
+
$accounts = $service->management_accounts->listManagementAccounts();
|
158 |
+
$accounts_id = array();
|
159 |
+
$ga4_profile_list = array();
|
160 |
+
$ua_profile_list = array();
|
161 |
+
if (count($accounts) > 0) {
|
162 |
+
foreach ($accounts as $account) {
|
163 |
+
$accounts_id[] = $account->id;
|
164 |
+
}
|
165 |
+
|
166 |
+
$ga4_properties = array();
|
167 |
+
foreach ($accounts_id as $account_id) {
|
168 |
+
$ga4_properties = array_merge($ga4_properties, self::get_ga4_properties($account_id, $access_token));
|
169 |
+
}
|
170 |
+
|
171 |
+
if (!empty($ga4_properties)) {
|
172 |
+
$webDataStreams = array();
|
173 |
+
foreach ($ga4_properties as $ga4_property) {
|
174 |
+
$streamList = self::webDataStreamsList(str_replace('properties/', '', $ga4_property->name), $access_token);
|
175 |
+
if (!empty($streamList) && is_array($streamList)) {
|
176 |
+
$webDataStreams = array_merge($webDataStreams, $streamList);
|
177 |
+
}
|
178 |
+
}
|
179 |
+
|
180 |
+
foreach ($webDataStreams as $profile) {
|
181 |
+
$profile_name = $profile->name;
|
182 |
+
$profile_name_arr = explode('/', $profile_name);
|
183 |
+
$property_id = $profile_name_arr[1];
|
184 |
+
$webDataStream_id = $profile_name_arr[3];
|
185 |
+
|
186 |
+
$ga4_profile_list[] = array(
|
187 |
+
$profile->displayName,
|
188 |
+
$webDataStream_id, // todo:: check this value
|
189 |
+
$property_id,
|
190 |
+
$profile->webStreamData->defaultUri,
|
191 |
+
'GA4',
|
192 |
+
'',
|
193 |
+
'',
|
194 |
+
'',
|
195 |
+
$profile->webStreamData->measurementId
|
196 |
+
);
|
197 |
+
}
|
198 |
+
}
|
199 |
+
}
|
200 |
+
|
201 |
+
// Get profile for google universal analytics (UA)
|
202 |
+
$profiles = $service->management_profiles->listManagementProfiles(
|
203 |
+
'~all',
|
204 |
+
'~all',
|
205 |
+
array(
|
206 |
+
'start-index' => $startindex
|
207 |
+
)
|
208 |
+
);
|
209 |
+
$items = $profiles->getItems();
|
210 |
+
$totalresults = $profiles->getTotalResults();
|
211 |
+
|
212 |
+
if ($totalresults > 0) {
|
213 |
+
foreach ($items as $profile) {
|
214 |
+
$timetz = new DateTimeZone($profile->getTimezone());
|
215 |
+
$localtime = new DateTime('now', $timetz);
|
216 |
+
$timeshift = strtotime($localtime->format('Y-m-d H:i:s')) - time();
|
217 |
+
$ua_profile_list[] = array(
|
218 |
+
$profile->getName(),
|
219 |
+
$profile->getId(),
|
220 |
+
$profile->getwebPropertyId(),
|
221 |
+
$profile->getwebsiteUrl(),
|
222 |
+
'UA',
|
223 |
+
$timeshift,
|
224 |
+
$profile->getTimezone(),
|
225 |
+
$profile->getDefaultPage(),
|
226 |
+
''
|
227 |
+
);
|
228 |
+
$startindex++;
|
229 |
+
}
|
230 |
+
}
|
231 |
+
|
232 |
+
$ga_dash_profile_list = array_merge($ga4_profile_list, $ua_profile_list);
|
233 |
+
}
|
234 |
+
|
235 |
+
if (empty($ga_dash_profile_list)) {
|
236 |
+
self::setCache(
|
237 |
+
'last_error',
|
238 |
+
date('Y-m-d H:i:s') . ': No properties were found in this account!',
|
239 |
+
$error_timeout
|
240 |
+
);
|
241 |
+
} else {
|
242 |
+
self::deleteCache('last_error');
|
243 |
+
}
|
244 |
+
return $ga_dash_profile_list;
|
245 |
+
} catch (WPMSGoogle\Service\Exception $e) {
|
246 |
+
self::setCache(
|
247 |
+
'last_error',
|
248 |
+
date('Y-m-d H:i:s') . ': ' . esc_html('(' . $e->getCode() . ') ' . $e->getMessage()),
|
249 |
+
$error_timeout
|
250 |
+
);
|
251 |
+
self::setCache(
|
252 |
+
'gapi_errors',
|
253 |
+
$e->getCode(),
|
254 |
+
$error_timeout
|
255 |
+
);
|
256 |
+
return $ga_dash_profile_list;
|
257 |
+
} catch (Exception $e) {
|
258 |
+
self::setCache(
|
259 |
+
'last_error',
|
260 |
+
date('Y-m-d H:i:s') . ': ' . esc_html($e),
|
261 |
+
$error_timeout
|
262 |
+
);
|
263 |
+
return $ga_dash_profile_list;
|
264 |
+
}
|
265 |
+
}
|
266 |
+
|
267 |
+
|
268 |
+
/**
|
269 |
+
* Get Google analytics 4 properties
|
270 |
+
*
|
271 |
+
* @param string $account_id GA4 account ID
|
272 |
+
* @param string $access_token Access token
|
273 |
+
*
|
274 |
+
* @return array
|
275 |
+
*/
|
276 |
+
public static function get_ga4_properties($account_id, $access_token)
|
277 |
+
{
|
278 |
+
$query_url = 'https://analyticsadmin.googleapis.com/v1alpha/properties';
|
279 |
+
$query_url = add_query_arg('access_token', $access_token, $query_url);
|
280 |
+
$properties = array();
|
281 |
+
$pageToken = null;
|
282 |
+
do {
|
283 |
+
try {
|
284 |
+
$additional = array();
|
285 |
+
$additional['filter'] = 'parent:accounts/' . $account_id;
|
286 |
+
$additional['pageSize'] = 40;
|
287 |
+
if ($pageToken) {
|
288 |
+
$additional['pageToken'] = $pageToken;
|
289 |
+
}
|
290 |
+
|
291 |
+
$call_args = array();
|
292 |
+
$call_args['method'] = 'GET';
|
293 |
+
$call_args['body'] = $additional;
|
294 |
+
$response = wp_remote_request($query_url, $call_args);
|
295 |
+
if (!is_wp_error($response)) {
|
296 |
+
$body = wp_remote_retrieve_body($response);
|
297 |
+
$body = json_decode($body);
|
298 |
+
}
|
299 |
+
|
300 |
+
$items = isset($body->properties) ? $body->properties : array();
|
301 |
+
$properties = array_merge($properties, $items);
|
302 |
+
if (isset($body->nextPageToken)) {
|
303 |
+
$pageToken = $body->nextPageToken;
|
304 |
+
} else {
|
305 |
+
$pageToken = null;
|
306 |
+
}
|
307 |
+
} catch (Exception $e) {
|
308 |
+
$pageToken = null;
|
309 |
+
}
|
310 |
+
} while ($pageToken);
|
311 |
+
|
312 |
+
return $properties;
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Retrieve all data stream google analytics 4 property
|
317 |
+
*
|
318 |
+
* @param string $property_id GA4 property ID
|
319 |
+
* @param string $access_token Access token
|
320 |
+
*
|
321 |
+
* @return array
|
322 |
+
*/
|
323 |
+
public static function webDataStreamsList($property_id, $access_token)
|
324 |
+
{
|
325 |
+
$query_url = 'https://analyticsadmin.googleapis.com/v1alpha/properties/' . $property_id . '/dataStreams';
|
326 |
+
$query_url = add_query_arg('access_token', $access_token, $query_url);
|
327 |
+
$webDataStreams = array();
|
328 |
+
$pageToken = null;
|
329 |
+
do {
|
330 |
+
try {
|
331 |
+
$additional = array();
|
332 |
+
$additional['pageSize'] = 40;
|
333 |
+
if ($pageToken) {
|
334 |
+
$additional['pageToken'] = $pageToken;
|
335 |
+
}
|
336 |
+
|
337 |
+
$call_args = array();
|
338 |
+
$call_args['method'] = 'GET';
|
339 |
+
$call_args['body'] = $additional;
|
340 |
+
|
341 |
+
$response = wp_remote_request($query_url, $call_args);
|
342 |
+
if (!is_wp_error($response)) {
|
343 |
+
$body = wp_remote_retrieve_body($response);
|
344 |
+
$body = json_decode($body);
|
345 |
+
}
|
346 |
+
|
347 |
+
$items = isset($body->dataStreams) ? $body->dataStreams : array();
|
348 |
+
$webDataStreams = array_merge($webDataStreams, $items);
|
349 |
+
if (isset($body->nextPageToken)) {
|
350 |
+
$pageToken = $body->nextPageToken;
|
351 |
+
} else {
|
352 |
+
$pageToken = null;
|
353 |
+
}
|
354 |
+
} catch (Exception $e) {
|
355 |
+
$pageToken = null;
|
356 |
+
}
|
357 |
+
} while ($pageToken);
|
358 |
+
|
359 |
+
return $webDataStreams;
|
360 |
+
}
|
361 |
+
|
362 |
/**
|
363 |
* Get selected profile
|
364 |
*
|
inc/install-wizard/content/viewGoogleAnalytics.php
CHANGED
@@ -7,18 +7,7 @@ $step = isset($_GET['step']) ? sanitize_key($_GET['step']) : '';
|
|
7 |
$next_link = $wizard->getNextLink($step);
|
8 |
|
9 |
require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php';
|
10 |
-
|
11 |
-
require_once WPMETASEO_PLUGIN_DIR . 'inc/lib/google-api/vendor/autoload.php';
|
12 |
-
|
13 |
-
$client = new WPMSGoogle\Client();
|
14 |
-
$client->setScopes(array(
|
15 |
-
'https://www.googleapis.com/auth/tagmanager.edit.containers',
|
16 |
-
'https://www.googleapis.com/auth/analytics.readonly'
|
17 |
-
));
|
18 |
-
$client->setAccessType('offline');
|
19 |
-
$client->setApplicationName('WP Meta SEO');
|
20 |
-
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
|
21 |
-
$client = WpmsGaTools::setClient($client, array(), array(WPMS_CLIENTID, WPMS_CLIENTSECRET));
|
22 |
$authUrl = $client->createAuthUrl();
|
23 |
|
24 |
?>
|
7 |
$next_link = $wizard->getNextLink($step);
|
8 |
|
9 |
require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php';
|
10 |
+
$client = WpmsGaTools::initClient(WPMS_CLIENTID, WPMS_CLIENTSECRET);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
$authUrl = $client->createAuthUrl();
|
12 |
|
13 |
?>
|
inc/install-wizard/handler-wizard.php
CHANGED
@@ -106,18 +106,7 @@ class WpmsHandlerWizard
|
|
106 |
$error_timeout = $midnight - time();
|
107 |
|
108 |
require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php';
|
109 |
-
|
110 |
-
require_once WPMETASEO_PLUGIN_DIR . 'inc/lib/google-api/vendor/autoload.php';
|
111 |
-
|
112 |
-
$client = new WPMSGoogle\Client();
|
113 |
-
$client->setScopes(array(
|
114 |
-
'https://www.googleapis.com/auth/tagmanager.edit.containers',
|
115 |
-
'https://www.googleapis.com/auth/analytics.readonly'
|
116 |
-
));
|
117 |
-
$client->setAccessType('offline');
|
118 |
-
$client->setApplicationName('WP Meta SEO');
|
119 |
-
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
|
120 |
-
$client = WpmsGaTools::setClient($client, array(), array(WPMS_CLIENTID, WPMS_CLIENTSECRET));
|
121 |
$service = new WPMSGoogle_Service_Analytics($client);
|
122 |
$google_alanytics = array();
|
123 |
if (!stripos('x' . $wpms_ga_code, 'UA-', 1)) {
|
@@ -155,7 +144,7 @@ class WpmsHandlerWizard
|
|
155 |
if (!empty($google_alanytics['profile_list'])) {
|
156 |
$profiles = $google_alanytics['profile_list'];
|
157 |
} else {
|
158 |
-
$profiles =
|
159 |
}
|
160 |
|
161 |
$google_alanytics['code'] = $wpms_ga_code;
|
@@ -189,88 +178,4 @@ class WpmsHandlerWizard
|
|
189 |
wp_safe_redirect(esc_url_raw($wizard->getNextLink($current_step)));
|
190 |
exit;
|
191 |
}
|
192 |
-
|
193 |
-
/**
|
194 |
-
* Retrieves all Google Analytics Views with details
|
195 |
-
*
|
196 |
-
* @param object $service Google analytics server
|
197 |
-
* @param string $error_timeout Timeout
|
198 |
-
*
|
199 |
-
* @return array
|
200 |
-
*/
|
201 |
-
public static function refreshProfiles($service, $error_timeout)
|
202 |
-
{
|
203 |
-
try {
|
204 |
-
$ga_dash_profile_list = array();
|
205 |
-
$startindex = 1;
|
206 |
-
$totalresults = 65535; // use something big
|
207 |
-
while ($startindex < $totalresults) {
|
208 |
-
$profiles = $service->management_profiles->listManagementProfiles(
|
209 |
-
'~all',
|
210 |
-
'~all',
|
211 |
-
array(
|
212 |
-
'start-index' => $startindex
|
213 |
-
)
|
214 |
-
);
|
215 |
-
$items = $profiles->getItems();
|
216 |
-
|
217 |
-
$totalresults = $profiles->getTotalResults();
|
218 |
-
|
219 |
-
if ($totalresults > 0) {
|
220 |
-
foreach ($items as $profile) {
|
221 |
-
$timetz = new DateTimeZone($profile->getTimezone());
|
222 |
-
$localtime = new DateTime('now', $timetz);
|
223 |
-
$timeshift = strtotime($localtime->format('Y-m-d H:i:s')) - time();
|
224 |
-
$ga_dash_profile_list[] = array(
|
225 |
-
$profile->getName(),
|
226 |
-
$profile->getId(),
|
227 |
-
$profile->getwebPropertyId(),
|
228 |
-
$profile->getwebsiteUrl(),
|
229 |
-
$timeshift,
|
230 |
-
$profile->getTimezone(),
|
231 |
-
$profile->getDefaultPage()
|
232 |
-
);
|
233 |
-
$startindex ++;
|
234 |
-
}
|
235 |
-
}
|
236 |
-
}
|
237 |
-
|
238 |
-
if (empty($ga_dash_profile_list)) {
|
239 |
-
WpmsGaTools::setCache(
|
240 |
-
'last_error',
|
241 |
-
date('Y-m-d H:i:s') . ': No properties were found in this account!',
|
242 |
-
$error_timeout
|
243 |
-
);
|
244 |
-
} else {
|
245 |
-
WpmsGaTools::deleteCache('last_error');
|
246 |
-
}
|
247 |
-
return $ga_dash_profile_list;
|
248 |
-
} catch (WPMSGoogle_IO_Exception $e) {
|
249 |
-
WpmsGaTools::setCache(
|
250 |
-
'last_error',
|
251 |
-
date('Y-m-d H:i:s') . ': ' . esc_html($e),
|
252 |
-
$error_timeout
|
253 |
-
);
|
254 |
-
return $ga_dash_profile_list;
|
255 |
-
} catch (WPMSGoogle_Service_Exception $e) {
|
256 |
-
WpmsGaTools::setCache(
|
257 |
-
'last_error',
|
258 |
-
date('Y-m-d H:i:s') . ': ' . esc_html('(' . $e->getCode() . ') ' . $e->getMessage()),
|
259 |
-
$error_timeout
|
260 |
-
);
|
261 |
-
WpmsGaTools::setCache(
|
262 |
-
'gapi_errors',
|
263 |
-
$e->getCode(),
|
264 |
-
$error_timeout
|
265 |
-
);
|
266 |
-
return $ga_dash_profile_list;
|
267 |
-
} catch (Exception $e) {
|
268 |
-
WpmsGaTools::setCache(
|
269 |
-
'last_error',
|
270 |
-
date('Y-m-d H:i:s') . ': ' . esc_html($e),
|
271 |
-
$error_timeout
|
272 |
-
);
|
273 |
-
return $ga_dash_profile_list;
|
274 |
-
}
|
275 |
-
}
|
276 |
}
|
106 |
$error_timeout = $midnight - time();
|
107 |
|
108 |
require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php';
|
109 |
+
$client = WpmsGaTools::initClient(WPMS_CLIENTID, WPMS_CLIENTSECRET);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
$service = new WPMSGoogle_Service_Analytics($client);
|
111 |
$google_alanytics = array();
|
112 |
if (!stripos('x' . $wpms_ga_code, 'UA-', 1)) {
|
144 |
if (!empty($google_alanytics['profile_list'])) {
|
145 |
$profiles = $google_alanytics['profile_list'];
|
146 |
} else {
|
147 |
+
$profiles = WpmsGaTools::refreshProfiles($service, $getAccessToken['access_token'], $error_timeout);
|
148 |
}
|
149 |
|
150 |
$google_alanytics['code'] = $wpms_ga_code;
|
178 |
wp_safe_redirect(esc_url_raw($wizard->getNextLink($current_step)));
|
179 |
exit;
|
180 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
}
|
inc/pages/google-services/gg-services-connect.php
CHANGED
@@ -15,10 +15,7 @@
|
|
15 |
<?php
|
16 |
$display_body_info = '';
|
17 |
$display_body_access = 'style=display:none;';
|
18 |
-
|
19 |
-
$display_body_info = 'style=display:none;';
|
20 |
-
$display_body_access = '';
|
21 |
-
}
|
22 |
?>
|
23 |
<form name="input" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" method="post" style="margin-top: 20px">
|
24 |
<?php wp_nonce_field('gadash_form', 'gadash_security'); ?>
|
@@ -39,27 +36,27 @@
|
|
39 |
value="<?php echo esc_attr((!empty($this->google_alanytics['wpmsga_dash_clientsecret'])) ? $this->google_alanytics['wpmsga_dash_clientsecret'] : '') ?>">
|
40 |
</div>
|
41 |
</div>
|
42 |
-
<div class="wpms_row_full save-ga-field">
|
43 |
-
<input type="button" class="ju-button save-ga-infomation orange-button" <?php echo esc_attr($display_body_access)?>
|
44 |
-
value="<?php esc_html_e('Save and Continue', 'wp-meta-seo') ?>" />
|
45 |
-
<img class="save-ga-loader" src="<?php echo esc_url(WPMETASEO_PLUGIN_URL . '/assets/images/ajax-loader1.gif') ?>" width="50px"
|
46 |
-
style="display:none;margin-left:10px;vertical-align: middle" />
|
47 |
-
</div>
|
48 |
-
</div>
|
49 |
-
<div class="ju-settings-option wpms_ga_access background-none" <?php echo esc_attr($display_body_access) ?>>
|
50 |
<div class="wpms_row_full">
|
51 |
-
<
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
</div>
|
54 |
<div class="wpms_row_full">
|
55 |
-
<label class="ju-setting-label" title="<?php esc_attr_e('
|
56 |
-
<?php esc_html_e('
|
57 |
</label>
|
58 |
<div class="ju-switch-button">
|
59 |
-
<input type="text" class="wpms-large-input" id="
|
60 |
</div>
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
63 |
</div>
|
64 |
</div>
|
65 |
|
@@ -73,26 +70,6 @@
|
|
73 |
}
|
74 |
});
|
75 |
|
76 |
-
$('input#ga_dash_code').on('change', function () {
|
77 |
-
if ($(this).val() !== '') {
|
78 |
-
$('button#wpms-gg-get-accesscode').html('Save and Apply');
|
79 |
-
$('button#wpms-gg-get-accesscode').attr('name', 'ga_dash_authorize');
|
80 |
-
$('button#wpms-gg-get-accesscode').attr('data-type', 'save');
|
81 |
-
} else {
|
82 |
-
$('button#wpms-gg-get-accesscode').html('Generate Access Code');
|
83 |
-
$('button#wpms-gg-get-accesscode').removeAttr('name');
|
84 |
-
$('button#wpms-gg-get-accesscode').attr('data-type', 'link');
|
85 |
-
}
|
86 |
-
});
|
87 |
-
|
88 |
-
$('button#wpms-gg-get-accesscode').on('click', function (e) {
|
89 |
-
if ($(this).attr('data-type') === 'link') {
|
90 |
-
e.preventDefault();
|
91 |
-
window.open($(this).attr('data-href'),"_blank");
|
92 |
-
return false;
|
93 |
-
}
|
94 |
-
});
|
95 |
-
|
96 |
$('input.save-ga-infomation').click(function () {
|
97 |
var wpmsga_dash_clientid = $('input[name="wpmsga_dash_clientid"').val();
|
98 |
var wpmsga_dash_clientsecret = $('input[name="wpmsga_dash_clientsecret"').val();
|
@@ -110,10 +87,9 @@
|
|
110 |
},
|
111 |
success: function (res) {
|
112 |
if (res.status) {
|
113 |
-
|
114 |
-
$('.wpms_ga_info').hide();
|
115 |
$('.save-ga-field .save-ga-loader').hide();
|
116 |
-
|
117 |
}
|
118 |
}
|
119 |
});
|
@@ -127,12 +103,9 @@
|
|
127 |
}
|
128 |
});
|
129 |
|
130 |
-
$('.wpms-ga-back-information').click(function () {
|
131 |
-
$('.wpms_ga_access').hide();
|
132 |
-
$('.wpms_ga_info').show('fade');
|
133 |
-
})
|
134 |
});
|
135 |
</script>
|
|
|
136 |
</form>
|
137 |
</div>
|
138 |
</div>
|
15 |
<?php
|
16 |
$display_body_info = '';
|
17 |
$display_body_access = 'style=display:none;';
|
18 |
+
|
|
|
|
|
|
|
19 |
?>
|
20 |
<form name="input" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" method="post" style="margin-top: 20px">
|
21 |
<?php wp_nonce_field('gadash_form', 'gadash_security'); ?>
|
36 |
value="<?php echo esc_attr((!empty($this->google_alanytics['wpmsga_dash_clientsecret'])) ? $this->google_alanytics['wpmsga_dash_clientsecret'] : '') ?>">
|
37 |
</div>
|
38 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
<div class="wpms_row_full">
|
40 |
+
<label class="ju-setting-label" title="<?php esc_attr_e('JavaScript origins', 'wp-meta-seo') ?>">
|
41 |
+
<?php esc_html_e('JavaScript origins', 'wp-meta-seo'); ?>
|
42 |
+
</label>
|
43 |
+
<div class="ju-switch-button">
|
44 |
+
<input type="text" readonly class="wpms-large-input" id="wpms_ga_js_origins" name="wpms_ga_js_origins" value="<?php echo esc_attr(site_url()); ?>" size="60" />
|
45 |
+
</div>
|
46 |
</div>
|
47 |
<div class="wpms_row_full">
|
48 |
+
<label class="ju-setting-label" title="<?php esc_attr_e('Redirect URIs', 'wp-meta-seo') ?>">
|
49 |
+
<?php esc_html_e('Redirect URIs', 'wp-meta-seo'); ?>
|
50 |
</label>
|
51 |
<div class="ju-switch-button">
|
52 |
+
<input type="text" readonly class="wpms-large-input" id="wpms_ga_redirect_uris" name="wpms_ga_redirect_uris" value="<?php echo esc_attr(admin_url('admin.php?page=metaseo_google_analytics&view=wpms_gg_service_data&task=wpms_ga')) ?>" size="140" />
|
53 |
</div>
|
54 |
+
</div>
|
55 |
+
<div class="wpms_row_full save-ga-field">
|
56 |
+
<input type="button" class="ju-button save-ga-infomation orange-button"
|
57 |
+
value="<?php esc_html_e('Save and Connect', 'wp-meta-seo') ?>" />
|
58 |
+
<img class="save-ga-loader" src="<?php echo esc_url(WPMETASEO_PLUGIN_URL . '/assets/images/ajax-loader1.gif') ?>" width="50px"
|
59 |
+
style="display:none;margin-left:10px;vertical-align: middle" />
|
60 |
</div>
|
61 |
</div>
|
62 |
|
70 |
}
|
71 |
});
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
$('input.save-ga-infomation').click(function () {
|
74 |
var wpmsga_dash_clientid = $('input[name="wpmsga_dash_clientid"').val();
|
75 |
var wpmsga_dash_clientsecret = $('input[name="wpmsga_dash_clientsecret"').val();
|
87 |
},
|
88 |
success: function (res) {
|
89 |
if (res.status) {
|
90 |
+
|
|
|
91 |
$('.save-ga-field .save-ga-loader').hide();
|
92 |
+
window.location.href = res.authUrl;
|
93 |
}
|
94 |
}
|
95 |
});
|
103 |
}
|
104 |
});
|
105 |
|
|
|
|
|
|
|
|
|
106 |
});
|
107 |
</script>
|
108 |
+
|
109 |
</form>
|
110 |
</div>
|
111 |
</div>
|
languages/wp-meta-seo-en_US.mo
CHANGED
Binary file
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: JoomUnited
|
3 |
Tags: google, webmaster tools, keywords, meta, meta description, meta keywords, meta title, robots meta, search engine optimization, seo, wordpress seo, yahoo, image optimization, image resize, custom post seo, redirect, redirection, 301, broken link
|
4 |
Requires at least: 4.7
|
5 |
-
Tested up to:
|
6 |
-
Stable tag: 4.4.
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -259,6 +259,9 @@ Yes WP Meta SEO is compatible with Gutenberg editor since 3.7 version.
|
|
259 |
|
260 |
== Changelog ==
|
261 |
|
|
|
|
|
|
|
262 |
= 4.4.7 =
|
263 |
* Fix : Escape the breadcrumb separator before outputting it to the page
|
264 |
|
2 |
Contributors: JoomUnited
|
3 |
Tags: google, webmaster tools, keywords, meta, meta description, meta keywords, meta title, robots meta, search engine optimization, seo, wordpress seo, yahoo, image optimization, image resize, custom post seo, redirect, redirection, 301, broken link
|
4 |
Requires at least: 4.7
|
5 |
+
Tested up to: 6.0
|
6 |
+
Stable tag: 4.4.8
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
259 |
|
260 |
== Changelog ==
|
261 |
|
262 |
+
= 4.4.8 =
|
263 |
+
* Fix : Google Analytics connection: update OAuth2 authorization
|
264 |
+
|
265 |
= 4.4.7 =
|
266 |
* Fix : Escape the breadcrumb separator before outputting it to the page
|
267 |
|
wp-meta-seo.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Plugin Name: WP Meta SEO
|
5 |
* Plugin URI: http://www.joomunited.com/wordpress-products/wp-meta-seo
|
6 |
* Description: WP Meta SEO is a plugin for WordPress to fill meta for content, images and main SEO info in a single view.
|
7 |
-
* Version: 4.4.
|
8 |
* Text Domain: wp-meta-seo
|
9 |
* Domain Path: /languages
|
10 |
* Author: JoomUnited
|
@@ -133,7 +133,7 @@ if (!defined('WPMSEO_VERSION')) {
|
|
133 |
/**
|
134 |
* Plugin version
|
135 |
*/
|
136 |
-
define('WPMSEO_VERSION', '4.4.
|
137 |
}
|
138 |
|
139 |
if (!defined('WPMS_CLIENTID')) {
|
@@ -441,6 +441,52 @@ if (is_admin()) {
|
|
441 |
}
|
442 |
|
443 |
include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsga.php');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
} else {
|
445 |
/**
|
446 |
* Outputs the breadcrumb
|
4 |
* Plugin Name: WP Meta SEO
|
5 |
* Plugin URI: http://www.joomunited.com/wordpress-products/wp-meta-seo
|
6 |
* Description: WP Meta SEO is a plugin for WordPress to fill meta for content, images and main SEO info in a single view.
|
7 |
+
* Version: 4.4.8
|
8 |
* Text Domain: wp-meta-seo
|
9 |
* Domain Path: /languages
|
10 |
* Author: JoomUnited
|
133 |
/**
|
134 |
* Plugin version
|
135 |
*/
|
136 |
+
define('WPMSEO_VERSION', '4.4.8');
|
137 |
}
|
138 |
|
139 |
if (!defined('WPMS_CLIENTID')) {
|
441 |
}
|
442 |
|
443 |
include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsga.php');
|
444 |
+
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Not a form, nonce is not required
|
445 |
+
if (isset($_GET['task']) && $_GET['task'] === 'wpms_ga') {
|
446 |
+
if (!empty($_GET['code'])) {
|
447 |
+
$google_analytics = get_option('wpms_google_alanytics');
|
448 |
+
|
449 |
+
if (is_array($google_analytics)) {
|
450 |
+
$google_analytics['code'] = $_GET['code'];
|
451 |
+
|
452 |
+
require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php';
|
453 |
+
$ggClient = WpmsGaTools::initClient($google_analytics['wpmsga_dash_clientid'], $google_analytics['wpmsga_dash_clientsecret']);
|
454 |
+
|
455 |
+
try {
|
456 |
+
$ggClient->authenticate($google_analytics['code']);
|
457 |
+
$getAccessToken = $ggClient->getAccessToken();
|
458 |
+
|
459 |
+
if ($getAccessToken) {
|
460 |
+
$ggClient->setAccessToken($getAccessToken);
|
461 |
+
$google_analytics['googleCredentials'] = $getAccessToken;
|
462 |
+
|
463 |
+
if (empty($google_alanytics['profile_list'])) {
|
464 |
+
$service = new WPMSGoogle_Service_Analytics($ggClient);
|
465 |
+
$midnight = strtotime('tomorrow 00:00:00'); // UTC midnight
|
466 |
+
$midnight = $midnight + 8 * 3600; // UTC 8 AM
|
467 |
+
$error_timeout = $midnight - time();
|
468 |
+
|
469 |
+
$profiles = WpmsGaTools::refreshProfiles($service, $getAccessToken['access_token'], $error_timeout);
|
470 |
+
$google_analytics['profile_list'] = $profiles;
|
471 |
+
}
|
472 |
+
|
473 |
+
update_option('wpms_google_alanytics', $google_analytics);
|
474 |
+
// Do redirect
|
475 |
+
$redirectUrl = admin_url('admin.php?page=metaseo_google_analytics&view=wpms_gg_service_data');
|
476 |
+
header('Location: '.$redirectUrl, true, 302);
|
477 |
+
exit;
|
478 |
+
}
|
479 |
+
} catch (WPMSGoogle\Service\Exception $e) {
|
480 |
+
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Log error for debug
|
481 |
+
error_log($e->getMessage());
|
482 |
+
} catch (Exception $e) {
|
483 |
+
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Log error for debug
|
484 |
+
error_log($e->getMessage());
|
485 |
+
}
|
486 |
+
}
|
487 |
+
}
|
488 |
+
// phpcs:enable
|
489 |
+
}
|
490 |
} else {
|
491 |
/**
|
492 |
* Outputs the breadcrumb
|