| 1 |
<?php |
| 2 |
/** |
| 3 |
* Author: Alin Marcu |
| 4 |
* Author URI: https://deconf.com |
| 5 |
* Copyright 2013 Alin Marcu |
| 6 |
* License: GPLv2 or later |
| 7 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 8 |
*/ |
| 9 |
//@formatter:off |
| 10 |
// Exit if accessed directly |
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit(); |
| 13 |
} |
| 14 |
|
| 15 |
use Deconf\AIWP\Google\Service\Exception as GoogleServiceException; |
| 16 |
|
| 17 |
final class AIWP_Settings { |
| 18 |
|
| 19 |
private static function update_options( $who ) { |
| 20 |
$aiwp = AIWP(); |
| 21 |
$message = ''; |
| 22 |
$network_settings = false; |
| 23 |
$options = $aiwp->config->options; // Get current options |
| 24 |
if ( isset( $_REQUEST['options']['aiwp_hidden'] ) && isset( $_REQUEST['options'] ) && ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) && 'Reset' != $who ) { |
| 25 |
$new_options = $aiwp->config->validate_data( $_REQUEST['options'] ); |
| 26 |
if ( 'tracking' == $who ) { |
| 27 |
$options['ga_anonymize_ip'] = 0; |
| 28 |
$options['ga_optout'] = 0; |
| 29 |
$options['ga_event_tracking'] = 0; |
| 30 |
$options['ga_enhanced_links'] = 0; |
| 31 |
$options['ga_event_precision'] = 0; |
| 32 |
$options['ga_event_bouncerate'] = 0; |
| 33 |
$options['ga_crossdomain_tracking'] = 0; |
| 34 |
$options['ga_aff_tracking'] = 0; |
| 35 |
$options['ga_hash_tracking'] = 0; |
| 36 |
$options['ga_formsubmit_tracking'] = 0; |
| 37 |
$options['ga_force_ssl'] = 0; |
| 38 |
$options['ga_pagescrolldepth_tracking'] = 0; |
| 39 |
$options['ga_samesite'] = ''; |
| 40 |
$options['tm_pagescrolldepth_tracking'] = 0; |
| 41 |
$options['tm_optout'] = 0; |
| 42 |
$options['amp_tracking_analytics'] = 0; |
| 43 |
$options['amp_tracking_clientidapi'] = 0; |
| 44 |
$options['amp_tracking_tagmanager'] = 0; |
| 45 |
$options['optimize_pagehiding'] = 0; |
| 46 |
$options['optimize_tracking'] = 0; |
| 47 |
$options['trackingcode_infooter'] = 0; |
| 48 |
if ( isset( $_REQUEST['options']['ga_tracking_code'] ) ) { |
| 49 |
$new_options['ga_tracking_code'] = trim( $new_options['ga_tracking_code'], "\t" ); |
| 50 |
} |
| 51 |
if ( empty( $new_options['track_exclude'] ) ) { |
| 52 |
$new_options['track_exclude'] = array(); |
| 53 |
} |
| 54 |
} elseif ( 'backend' == $who ) { |
| 55 |
$options['switch_profile'] = 0; |
| 56 |
$options['backend_item_reports'] = 0; |
| 57 |
$options['dashboard_widget'] = 0; |
| 58 |
if ( empty( $new_options['access_back'] ) ) { |
| 59 |
$new_options['access_back'][] = 'administrator'; |
| 60 |
} |
| 61 |
} elseif ( 'frontend' == $who ) { |
| 62 |
$options['frontend_item_reports'] = 0; |
| 63 |
if ( empty( $new_options['access_front'] ) ) { |
| 64 |
$new_options['access_front'][] = 'administrator'; |
| 65 |
} |
| 66 |
} elseif ( 'general' == $who ) { |
| 67 |
$options['user_api'] = 0; |
| 68 |
} elseif ( 'network' == $who ) { |
| 69 |
$options['user_api'] = 0; |
| 70 |
$options['network_mode'] = 0; |
| 71 |
$options['superadmin_tracking'] = 0; |
| 72 |
$network_settings = true; |
| 73 |
} |
| 74 |
$options = array_merge( $options, $new_options ); |
| 75 |
$aiwp->config->options = $options; |
| 76 |
$aiwp->config->set_plugin_options( $network_settings ); |
| 77 |
} |
| 78 |
return $options; |
| 79 |
} |
| 80 |
|
| 81 |
private static function navigation_tabs( $tabs ) { |
| 82 |
echo '<h2 class="nav-tab-wrapper">'; |
| 83 |
foreach ( $tabs as $tab => $name ) { |
| 84 |
echo "<a class='nav-tab' id='tab-".esc_attr( $tab )."' href='#top#aiwp-".esc_attr( $tab )."'>". esc_html( $name ) ."</a>"; |
| 85 |
} |
| 86 |
echo '</h2>'; |
| 87 |
} |
| 88 |
|
| 89 |
private static function html_form_begin( $text, $action, $message ) { |
| 90 |
?> |
| 91 |
<form name="aiwp_form" method="post" action="<?php echo esc_url( $action ); ?>"> |
| 92 |
<div class="wrap"> |
| 93 |
<?php echo "<h2>" . esc_html( $text ) . "</h2>"; ?> |
| 94 |
<?php if (isset($message)) echo wp_kses( $message, array( 'div' => array( 'class' => array(), 'id' => array() ), 'p' => array(), 'a' => array( 'href' => array() ) ) ); ?> |
| 95 |
<hr> |
| 96 |
</div> |
| 97 |
<div id="poststuff" class="aiwp"> |
| 98 |
<div id="post-body" class="metabox-holder columns-2"> |
| 99 |
<div id="post-body-content"> |
| 100 |
<div class="settings-wrapper"> |
| 101 |
<div class="inside"> |
| 102 |
<input type="hidden" name="options[aiwp_hidden]" value="Y"> |
| 103 |
<?php wp_nonce_field('aiwp_form','aiwp_security'); ?> |
| 104 |
<?php |
| 105 |
} |
| 106 |
|
| 107 |
private static function html_form_end() { |
| 108 |
?> |
| 109 |
|
| 110 |
|
| 111 |
</form> |
| 112 |
<?php |
| 113 |
} |
| 114 |
|
| 115 |
private static function html_switch_button( $option_name, $option_value, $option_id, $checked, $option_text, $disabled = false, $onchange = false ) { |
| 116 |
if ( $disabled ){ |
| 117 |
return; |
| 118 |
} |
| 119 |
?> |
| 120 |
<tr> |
| 121 |
<td colspan="2" class="aiwp-settings-title"> |
| 122 |
<div class="button-primary aiwp-settings-switchoo"> |
| 123 |
<input type="checkbox" name="<?php echo esc_attr( $option_name ); ?>" value="<?php echo esc_attr( $option_value ); ?>" class="aiwp-settings-switchoo-checkbox" id="<?php echo esc_attr( $option_id ); ?>" <?php checked( $checked, 1 ); ?> <?php disabled( $disabled, true );?> <?php if ($onchange) {echo ' onchange="this.form.submit()"'; } ?>> |
| 124 |
<label class="aiwp-settings-switchoo-label" for="<?php echo esc_attr( $option_id ); ?>"> |
| 125 |
<div class="aiwp-settings-switchoo-inner"></div> |
| 126 |
<div class="aiwp-settings-switchoo-switch"></div> |
| 127 |
</label> |
| 128 |
</div> |
| 129 |
<div class="switch-desc"><?php echo " " . esc_html( $option_text );?></div> |
| 130 |
</td> |
| 131 |
</tr> |
| 132 |
<?php |
| 133 |
} |
| 134 |
|
| 135 |
private static function html_section_delimiter( $title = false, $withhr = true, $withspan = true, $disabled = false ) { |
| 136 |
?> |
| 137 |
<tr> |
| 138 |
<td <?php if ( $withspan ) echo 'colspan="2"'; ?>> |
| 139 |
<?php if ( $withhr ) echo "<hr>"; if ( $title ) echo "<h2>" . esc_html( $title ) . "</h2>";?> |
| 140 |
</td> |
| 141 |
</tr> |
| 142 |
<?php |
| 143 |
} |
| 144 |
|
| 145 |
public static function frontend_settings() { |
| 146 |
$aiwp = AIWP(); |
| 147 |
$message = ''; |
| 148 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 149 |
return; |
| 150 |
} |
| 151 |
$options = self::update_options( 'frontend' ); |
| 152 |
if ( isset( $_REQUEST['options']['aiwp_hidden'] ) ) { |
| 153 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "Settings saved.", 'analytics-insights' ) . "</p></div>"; |
| 154 |
if ( ! ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) ) { |
| 155 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 156 |
} |
| 157 |
} |
| 158 |
?> |
| 159 |
<?php self::html_form_begin(__( "Google Analytics Frontend Settings", 'analytics-insights' ), $_SERVER['REQUEST_URI'], $message)?> |
| 160 |
<table class="aiwp-settings-options"> |
| 161 |
<?php self::html_section_delimiter(__( "Permissions", 'analytics-insights' ), false); ?> |
| 162 |
<tr> |
| 163 |
<td class="roles aiwp-settings-title"> |
| 164 |
<label for="access_front"><?php _e("Show stats to:", 'analytics-insights' ); ?></label> |
| 165 |
</td> |
| 166 |
<td class="aiwp-settings-roles"> |
| 167 |
<table> |
| 168 |
<tr> |
| 169 |
<?php if ( ! isset( $wp_roles ) ) : $wp_roles = new WP_Roles(); endif; ?> |
| 170 |
<?php $i = 0; ?> |
| 171 |
<?php foreach ( $wp_roles->role_names as $role => $name ) : ?> |
| 172 |
<?php if ( 'subscriber' != $role ) : ?> |
| 173 |
<?php $i++; ?> |
| 174 |
<td> |
| 175 |
<label> |
| 176 |
<input type="checkbox" name="options[access_front][]" value="<?php echo esc_attr( $role ); ?>" <?php if ( in_array($role,$options['access_front']) || 'administrator' == $role ) echo 'checked="checked"'; if ( 'administrator' == $role ) echo 'disabled="disabled"';?> /><?php echo esc_attr( $name ); ?></label> |
| 177 |
</td> |
| 178 |
<?php endif; ?> |
| 179 |
<?php if ( 0 == $i % 4 ) : ?> |
| 180 |
</tr> |
| 181 |
<tr> |
| 182 |
<?php endif; ?> |
| 183 |
<?php endforeach; ?> |
| 184 |
|
| 185 |
|
| 186 |
</table> |
| 187 |
</td> |
| 188 |
</tr> |
| 189 |
<?php self::html_switch_button('options[frontend_item_reports]', 1, 'frontend_item_reports', $options['frontend_item_reports'], __("enable web page reports on frontend", 'analytics-insights') ); ?> |
| 190 |
<?php self::html_section_delimiter(); ?> |
| 191 |
<tr> |
| 192 |
<td colspan="2" class="submit"> |
| 193 |
<input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'analytics-insights' ) ?>" /> |
| 194 |
</td> |
| 195 |
</tr> |
| 196 |
</table> |
| 197 |
<?php self::html_form_end(); ?> |
| 198 |
<?php AIWP_Tools::load_view( 'admin/views/settings-sidebar.php', array() ); |
| 199 |
} |
| 200 |
|
| 201 |
public static function backend_settings() { |
| 202 |
$aiwp = AIWP(); |
| 203 |
$message = ''; |
| 204 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 205 |
return; |
| 206 |
} |
| 207 |
$options = self::update_options( 'backend' ); |
| 208 |
if ( isset( $_REQUEST['options']['aiwp_hidden'] ) ) { |
| 209 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "Settings saved.", 'analytics-insights' ) . "</p></div>"; |
| 210 |
if ( ! ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) ) { |
| 211 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 212 |
} |
| 213 |
} |
| 214 |
?> |
| 215 |
<?php self::html_form_begin(__( "Google Analytics Backend Settings", 'analytics-insights' ), $_SERVER['REQUEST_URI'], $message)?> |
| 216 |
<table class="aiwp-settings-options"> |
| 217 |
<?php self::html_section_delimiter(__( "Permissions", 'analytics-insights' ), false); ?> |
| 218 |
<tr> |
| 219 |
<td class="roles aiwp-settings-title"> |
| 220 |
<label for="access_back"><?php _e("Show stats to:", 'analytics-insights' ); ?></label> |
| 221 |
</td> |
| 222 |
<td class="aiwp-settings-roles"> |
| 223 |
<table> |
| 224 |
<tr> |
| 225 |
<?php if ( ! isset( $wp_roles ) ) : ?> |
| 226 |
<?php $wp_roles = new WP_Roles(); ?> |
| 227 |
<?php endif; ?> |
| 228 |
<?php $i = 0; ?> |
| 229 |
<?php foreach ( $wp_roles->role_names as $role => $name ) : ?> |
| 230 |
<?php if ( 'subscriber' != $role ) : ?> |
| 231 |
<?php $i++; ?> |
| 232 |
<td> |
| 233 |
<label> |
| 234 |
<input type="checkbox" name="options[access_back][]" value="<?php echo esc_attr( $role ); ?>" <?php if ( in_array($role,$options['access_back']) || 'administrator' == $role ) echo 'checked="checked"'; if ( 'administrator' == $role ) echo 'disabled="disabled"';?> /> <?php echo esc_attr( $name ); ?></label> |
| 235 |
</td> |
| 236 |
<?php endif; ?> |
| 237 |
<?php if ( 0 == $i % 4 ) : ?> |
| 238 |
</tr> |
| 239 |
<tr> |
| 240 |
<?php endif; ?> |
| 241 |
<?php endforeach; ?> |
| 242 |
|
| 243 |
|
| 244 |
</table> |
| 245 |
</td> |
| 246 |
</tr> |
| 247 |
<?php self::html_switch_button('options[switch_profile]', 1, 'switch_profile', $options['switch_profile'], __( "enable Switch Property functionality", 'analytics-insights') ); ?> |
| 248 |
<?php self::html_switch_button('options[backend_item_reports]', 1, 'backend_item_reports', $options['backend_item_reports'], __( "enable reports on Posts List and Pages List", 'analytics-insights') ); ?> |
| 249 |
<?php self::html_switch_button('options[dashboard_widget]', 1, 'dashboard_widget', $options['dashboard_widget'], __( "enable the main Dashboard Widget", 'analytics-insights') ); ?> |
| 250 |
<?php self::html_section_delimiter(__( "Real-Time Settings", 'analytics-insights' )); ?> |
| 251 |
<tr> |
| 252 |
<td colspan="2" class="aiwp-settings-title"> <?php _e("Maximum number of pages to display on real-time tab:", 'analytics-insights'); ?> |
| 253 |
<input type="number" name="options[ga_realtime_pages]" id="ga_realtime_pages" value="<?php echo (int)$options['ga_realtime_pages']; ?>" size="3"> |
| 254 |
</td> |
| 255 |
</tr> |
| 256 |
<?php self::html_section_delimiter(__( "Location Settings", 'analytics-insights' )); ?> |
| 257 |
<tr> |
| 258 |
<td class="aiwp-settings-title"> |
| 259 |
<label for="ga_target_geomap"><?php _e("Target Map Country:", 'analytics-insights' ); ?></label> |
| 260 |
</td> |
| 261 |
<td> |
| 262 |
<select id="ga_target_geomap" name="options[ga_target_geomap]"> |
| 263 |
<?php $country_codes = AIWP_Tools::get_countrycodes(); ?> |
| 264 |
<?php foreach ( $country_codes as $key => $value ) : ?> |
| 265 |
<?php if ( $value ) : ?> |
| 266 |
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $options['ga_target_geomap'] ); ?> > |
| 267 |
<?php echo esc_html( $value ) ?> |
| 268 |
</option> |
| 269 |
<?php endif; ?> |
| 270 |
<?php endforeach; ?> |
| 271 |
</select> |
| 272 |
</td> |
| 273 |
</tr> |
| 274 |
</tr> |
| 275 |
<?php self::html_section_delimiter(__( "Google Maps Settings", 'analytics-insights' )); ?> |
| 276 |
<tr> |
| 277 |
<tr> |
| 278 |
<td colspan="2" class="aiwp-settings-title"> |
| 279 |
<?php echo __("API Key:", 'analytics-insights'); ?> |
| 280 |
<input type="text" style="text-align: center;" name="options[maps_api_key]" value="<?php echo esc_attr($options['maps_api_key']); ?>" size="50"> |
| 281 |
</td> |
| 282 |
</tr> |
| 283 |
<?php self::html_section_delimiter(__( "404 Errors Report", 'analytics-insights' )); ?> |
| 284 |
<tr> |
| 285 |
<td colspan="2" class="aiwp-settings-title"> |
| 286 |
<?php echo __("404 Page Title contains:", 'analytics-insights'); ?> |
| 287 |
<input type="text" style="text-align: center;" name="options[pagetitle_404]" value="<?php echo esc_attr($options['pagetitle_404']); ?>" size="20"> |
| 288 |
</td> |
| 289 |
</tr> |
| 290 |
<?php self::html_section_delimiter(); ?> |
| 291 |
<tr> |
| 292 |
<td colspan="2" class="submit"> |
| 293 |
<input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'analytics-insights' ) ?>" /> |
| 294 |
</td> |
| 295 |
</tr> |
| 296 |
</table> |
| 297 |
<?php self::html_form_end(); ?> |
| 298 |
<?php |
| 299 |
AIWP_Tools::load_view( 'admin/views/settings-sidebar.php', array() ); |
| 300 |
} |
| 301 |
|
| 302 |
public static function tracking_settings() { |
| 303 |
$aiwp = AIWP(); |
| 304 |
$message = ''; |
| 305 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 306 |
return; |
| 307 |
} |
| 308 |
$options = self::update_options( 'tracking' ); |
| 309 |
if ( isset( $_REQUEST['options']['aiwp_hidden'] ) ) { |
| 310 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "Settings saved.", 'analytics-insights' ) . "</p></div>"; |
| 311 |
if ( ! ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) ) { |
| 312 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 313 |
} |
| 314 |
} |
| 315 |
if ( 'ga4tracking' == $options['tracking_type'] ) { |
| 316 |
$tabs = array( 'basic' => __( "Basic Settings", 'analytics-insights' ), 'events' => __( "Events Tracking", 'analytics-insights' ), 'custom' => __( "Custom Definitions", 'analytics-insights' ), 'exclude' => __( "Exclude Tracking", 'analytics-insights' ), 'advanced' => __( "Advanced Settings", 'analytics-insights' ), 'integration' => __( "Integration", 'analytics-insights' ) ); |
| 317 |
} else if ( 'tagmanager' == $options['tracking_type'] ) { |
| 318 |
$tabs = array( 'basic' => __( "Basic Settings", 'analytics-insights' ), 'tmdatalayervars' => __( "DataLayer Variables", 'analytics-insights' ), 'exclude' => __( "Exclude Tracking", 'analytics-insights' ), 'tmadvanced' => __( "Advanced Settings", 'analytics-insights' ), 'tmintegration' => __( "Integration", 'analytics-insights' ) ); |
| 319 |
} else { |
| 320 |
$tabs = array( 'basic' => __( "Basic Settings", 'analytics-insights' ) ); |
| 321 |
} |
| 322 |
?> |
| 323 |
<?php self::html_form_begin(__( "Google Analytics Tracking Code", 'analytics-insights' ), '', $message)?> |
| 324 |
<?php self::navigation_tabs( $tabs ); ?> |
| 325 |
<div id="aiwp-basic"> |
| 326 |
<table class="aiwp-settings-options"> |
| 327 |
<?php self::html_section_delimiter(__( "Tracking Settings", 'analytics-insights' ), false); ?> |
| 328 |
<tr> |
| 329 |
<td class="aiwp-settings-title"> |
| 330 |
<label for="tracking_type"><?php _e("Tracking Type:", 'analytics-insights' ); ?></label> |
| 331 |
</td> |
| 332 |
<td> |
| 333 |
<select id="tracking_type" name="options[tracking_type]" onchange="this.form.submit()"> |
| 334 |
<?php if ( $aiwp->config->options['webstream_jail'] ) : ?> |
| 335 |
<option value="ga4tracking" <?php selected( $options['tracking_type'], 'ga4tracking' ); ?>><?php _e("Google Analytics 4", 'analytics-insights');?></option> |
| 336 |
<?php endif; ?> |
| 337 |
<option value="tagmanager" <?php selected( $options['tracking_type'], 'tagmanager' ); ?>><?php _e("Tag Manager", 'analytics-insights');?></option> |
| 338 |
<option value="disabled" <?php selected( $options['tracking_type'], 'disabled' ); ?>><?php _e("Disabled", 'analytics-insights');?></option> |
| 339 |
</select> |
| 340 |
</td> |
| 341 |
</tr> |
| 342 |
<?php if ( 'ga4tracking' == $options['tracking_type'] ) : ?> |
| 343 |
<tr> |
| 344 |
<td class="aiwp-settings-title"></td> |
| 345 |
<td> |
| 346 |
<?php if ( 'ga4tracking' == $options['tracking_type'] && $aiwp->config->options['webstream_jail'] ) : ?> |
| 347 |
<?php $webstream_info = AIWP_Tools::get_selected_profile( $aiwp->config->options['ga4_webstreams_list'], $aiwp->config->options['webstream_jail'] ); ?> |
| 348 |
<?php $webstream_info[5] = isset( $webstream_info[5] ) ? $webstream_info[5] : '' ?> |
| 349 |
<pre><?php echo __( "Stream Name:", 'analytics-insights' ) . "\t" . esc_html( $webstream_info[0] ) . "<br />" . __( "Stream ID:", 'analytics-insights' ) . "\t" . esc_html( $webstream_info[1] ) . "<br />" . __( "Stream URL:", 'analytics-insights' ) . "\t" . esc_html( $webstream_info[2] ) . "<br />" . __( "Measurement ID:", 'analytics-insights' ) . "\t" . esc_html( $webstream_info[3] ) . "<br />" . __( "Time Zone:", 'analytics-insights' ) . "\t" . esc_html( $webstream_info[5] );?></pre> |
| 350 |
<?php endif; ?> |
| 351 |
</td> |
| 352 |
</tr> |
| 353 |
<?php elseif ( 'tagmanager' == $options['tracking_type'] ) : ?> |
| 354 |
<tr> |
| 355 |
<td class="aiwp-settings-title"> |
| 356 |
<label for="tracking_type"><?php _e("Web Container ID:", 'analytics-insights' ); ?></label> |
| 357 |
</td> |
| 358 |
<td> |
| 359 |
<input type="text" name="options[web_containerid]" value="<?php echo esc_attr($options['web_containerid']); ?>" size="15"> |
| 360 |
</td> |
| 361 |
</tr> |
| 362 |
<?php endif; ?> |
| 363 |
<tr> |
| 364 |
<td class="aiwp-settings-title"> |
| 365 |
<label for="trackingcode_infooter"><?php _e("Code Placement:", 'analytics-insights' ); ?></label> |
| 366 |
</td> |
| 367 |
<td> |
| 368 |
<select id="trackingcode_infooter" name="options[trackingcode_infooter]"> |
| 369 |
<option value="0" <?php selected( $options['trackingcode_infooter'], 0 ); ?>><?php _e("HTML Head", 'analytics-insights');?></option> |
| 370 |
<option value="1" <?php selected( $options['trackingcode_infooter'], 1 ); ?>><?php _e("HTML Body", 'analytics-insights');?></option> |
| 371 |
</select> |
| 372 |
</td> |
| 373 |
</tr> |
| 374 |
</table> |
| 375 |
</div> |
| 376 |
<div id="aiwp-events"> |
| 377 |
<table class="aiwp-settings-options"> |
| 378 |
<?php self::html_section_delimiter(__( "Events Tracking", 'analytics-insights' ), false); ?> |
| 379 |
<?php self::html_switch_button('options[ga_event_tracking]', 1, 'ga_event_tracking', $options['ga_event_tracking'], __( "track downloads, mailto, telephone and outbound links", 'analytics-insights') ); ?> |
| 380 |
<?php self::html_switch_button('options[ga_aff_tracking]', 1, 'ga_aff_tracking', $options['ga_aff_tracking'], __( "track affiliate links", 'analytics-insights') ); ?> |
| 381 |
<?php self::html_switch_button('options[ga_hash_tracking]', 1, 'ga_hash_tracking', $options['ga_hash_tracking'], __( "track fragment identifiers, hashmarks (#) in URI links", 'analytics-insights') ); ?> |
| 382 |
<?php self::html_switch_button('options[ga_formsubmit_tracking]', 1, 'ga_formsubmit_tracking', $options['ga_formsubmit_tracking'], __( "track form submit actions", 'analytics-insights') ); ?> |
| 383 |
<?php self::html_switch_button('options[ga_pagescrolldepth_tracking]', 1, 'ga_pagescrolldepth_tracking', $options['ga_pagescrolldepth_tracking'], __( "track page scrolling depth", 'analytics-insights') ); ?> |
| 384 |
<tr> |
| 385 |
<td class="aiwp-settings-title"> |
| 386 |
<label for="ga_event_downloads"><?php _e("Downloads Regex:", 'analytics-insights'); ?></label> |
| 387 |
</td> |
| 388 |
<td> |
| 389 |
<input type="text" id="ga_event_downloads" name="options[ga_event_downloads]" value="<?php echo esc_attr($options['ga_event_downloads']); ?>" size="50"> |
| 390 |
</td> |
| 391 |
</tr> |
| 392 |
<tr> |
| 393 |
<td class="aiwp-settings-title"> |
| 394 |
<label for="ga_event_affiliates"><?php _e("Affiliates Regex:", 'analytics-insights'); ?></label> |
| 395 |
</td> |
| 396 |
<td> |
| 397 |
<input type="text" id="ga_event_affiliates" name="options[ga_event_affiliates]" value="<?php echo esc_attr($options['ga_event_affiliates']); ?>" size="50"> |
| 398 |
</td> |
| 399 |
</tr> |
| 400 |
<tr> |
| 401 |
<td class="aiwp-settings-title"> |
| 402 |
<label for="trackingevents_infooter"><?php _e("Code Placement:", 'analytics-insights' ); ?></label> |
| 403 |
</td> |
| 404 |
<td> |
| 405 |
<select id="trackingevents_infooter" name="options[trackingevents_infooter]"> |
| 406 |
<option value="0" <?php selected( $options['trackingevents_infooter'], 0 ); ?>><?php _e("HTML Head", 'analytics-insights');?></option> |
| 407 |
<option value="1" <?php selected( $options['trackingevents_infooter'], 1 ); ?>><?php _e("HTML Body", 'analytics-insights');?></option> |
| 408 |
</select> |
| 409 |
</td> |
| 410 |
</tr> |
| 411 |
</table> |
| 412 |
</div> |
| 413 |
<div id="aiwp-custom"> |
| 414 |
<table class="aiwp-settings-options"> |
| 415 |
<?php self::html_section_delimiter(__( "Custom Dimensions", 'analytics-insights' ), false); ?> |
| 416 |
<?php $dimprefix = 'ga4tracking' == $options['tracking_type'] ? 'aiwp_dim_' : 'dimension' ?> |
| 417 |
<tr> |
| 418 |
<td class="aiwp-settings-title"> |
| 419 |
<label for="ga_author_dimindex"><?php _e("Authors:", 'analytics-insights' ); ?></label> |
| 420 |
</td> |
| 421 |
<td> |
| 422 |
<select id="ga_author_dimindex" name="options[ga_author_dimindex]"> |
| 423 |
<?php for ($i=0;$i<21;$i++) : ?> |
| 424 |
<option value="<?php echo (int) $i;?>" <?php selected( $options['ga_author_dimindex'], $i ); ?>><?php echo 0 == $i ?'Disabled':$dimprefix . ' ' .(int) $i; ?></option> |
| 425 |
<?php endfor; ?> |
| 426 |
</select> |
| 427 |
</td> |
| 428 |
</tr> |
| 429 |
<tr> |
| 430 |
<td class="aiwp-settings-title"> |
| 431 |
<label for="ga_pubyear_dimindex"><?php _e("Publication Year:", 'analytics-insights' ); ?></label> |
| 432 |
</td> |
| 433 |
<td> |
| 434 |
<select id="ga_pubyear_dimindex" name="options[ga_pubyear_dimindex]"> |
| 435 |
<?php for ($i=0;$i<21;$i++) : ?> |
| 436 |
<option value="<?php echo (int) $i;?>" <?php selected( $options['ga_pubyear_dimindex'], $i ); ?>><?php echo 0 == $i ?'Disabled':$dimprefix . ' ' .(int) $i; ?></option> |
| 437 |
<?php endfor; ?> |
| 438 |
</select> |
| 439 |
</td> |
| 440 |
</tr> |
| 441 |
<tr> |
| 442 |
<td class="aiwp-settings-title"> |
| 443 |
<label for="ga_pubyearmonth_dimindex"><?php _e("Publication Month:", 'analytics-insights' ); ?></label> |
| 444 |
</td> |
| 445 |
<td> |
| 446 |
<select id="ga_pubyearmonth_dimindex" name="options[ga_pubyearmonth_dimindex]"> |
| 447 |
<?php for ($i=0;$i<21;$i++) : ?> |
| 448 |
<option value="<?php echo (int) $i;?>" <?php selected( $options['ga_pubyearmonth_dimindex'], $i ); ?>><?php echo 0 == $i ?'Disabled':$dimprefix . ' ' .(int) $i; ?></option> |
| 449 |
<?php endfor; ?> |
| 450 |
</select> |
| 451 |
</td> |
| 452 |
</tr> |
| 453 |
<tr> |
| 454 |
<td class="aiwp-settings-title"> |
| 455 |
<label for="ga_category_dimindex"><?php _e("Categories:", 'analytics-insights' ); ?></label> |
| 456 |
</td> |
| 457 |
<td> |
| 458 |
<select id="ga_category_dimindex" name="options[ga_category_dimindex]"> |
| 459 |
<?php for ($i=0;$i<21;$i++) : ?> |
| 460 |
<option value="<?php echo (int) $i;?>" <?php selected( $options['ga_category_dimindex'], $i ); ?>><?php echo 0 == $i ? 'Disabled':$dimprefix . ' ' .(int) $i; ?></option> |
| 461 |
<?php endfor; ?> |
| 462 |
</select> |
| 463 |
</td> |
| 464 |
</tr> |
| 465 |
<tr> |
| 466 |
<td class="aiwp-settings-title"> |
| 467 |
<label for="ga_user_dimindex"><?php _e("User Type:", 'analytics-insights' ); ?></label> |
| 468 |
</td> |
| 469 |
<td> |
| 470 |
<select id="ga_user_dimindex" name="options[ga_user_dimindex]"> |
| 471 |
<?php for ($i=0;$i<21;$i++) : ?> |
| 472 |
<option value="<?php echo (int) $i;?>" <?php selected( $options['ga_user_dimindex'], $i ); ?>><?php echo 0 == $i ? 'Disabled':$dimprefix . ' ' .(int) $i; ?></option> |
| 473 |
<?php endfor; ?> |
| 474 |
</select> |
| 475 |
</td> |
| 476 |
</tr> |
| 477 |
<tr> |
| 478 |
<td class="aiwp-settings-title"> |
| 479 |
<label for="ga_tag_dimindex"><?php _e("Tags:", 'analytics-insights' ); ?></label> |
| 480 |
</td> |
| 481 |
<td> |
| 482 |
<select id="ga_tag_dimindex" name="options[ga_tag_dimindex]"> |
| 483 |
<?php for ($i=0;$i<21;$i++) : ?> |
| 484 |
<option value="<?php echo (int) $i;?>" <?php selected( $options['ga_tag_dimindex'], $i ); ?>><?php echo 0 == $i ? 'Disabled':$dimprefix . ' ' .(int) $i; ?></option> |
| 485 |
<?php endfor; ?> |
| 486 |
</select> |
| 487 |
</td> |
| 488 |
</tr> |
| 489 |
</table> |
| 490 |
</div> |
| 491 |
<div id="aiwp-tmdatalayervars"> |
| 492 |
<table class="aiwp-settings-options"> |
| 493 |
<?php self::html_section_delimiter(__( "Main Variables", 'analytics-insights' ), false); ?> |
| 494 |
<tr> |
| 495 |
<td class="aiwp-settings-title"> |
| 496 |
<label for="tm_author_var"><?php _e("Authors:", 'analytics-insights' ); ?></label> |
| 497 |
</td> |
| 498 |
<td> |
| 499 |
<select id="tm_author_var" name="options[tm_author_var]"> |
| 500 |
<option value="1" <?php selected( $options['tm_author_var'], 1 ); ?>>aiwpAuthor</option> |
| 501 |
<option value="0" <?php selected( $options['tm_author_var'], 0 ); ?>><?php _e( "Disabled", 'analytics-insights' ); ?></option> |
| 502 |
</select> |
| 503 |
</td> |
| 504 |
</tr> |
| 505 |
<tr> |
| 506 |
<td class="aiwp-settings-title"> |
| 507 |
<label for="tm_pubyear_var"><?php _e("Publication Year:", 'analytics-insights' ); ?></label> |
| 508 |
</td> |
| 509 |
<td> |
| 510 |
<select id="tm_pubyear_var" name="options[tm_pubyear_var]"> |
| 511 |
<option value="1" <?php selected( $options['tm_pubyear_var'], 1 ); ?>>aiwpPublicationYear</option> |
| 512 |
<option value="0" <?php selected( $options['tm_pubyear_var'], 0 ); ?>><?php _e( "Disabled", 'analytics-insights' ); ?></option> |
| 513 |
</select> |
| 514 |
</td> |
| 515 |
</tr> |
| 516 |
<tr> |
| 517 |
<td class="aiwp-settings-title"> |
| 518 |
<label for="tm_pubyearmonth_var"><?php _e("Publication Month:", 'analytics-insights' ); ?></label> |
| 519 |
</td> |
| 520 |
<td> |
| 521 |
<select id="tm_pubyearmonth_var" name="options[tm_pubyearmonth_var]"> |
| 522 |
<option value="1" <?php selected( $options['tm_pubyearmonth_var'], 1 ); ?>>aiwpPublicationYearMonth</option> |
| 523 |
<option value="0" <?php selected( $options['tm_pubyearmonth_var'], 0 ); ?>><?php _e( "Disabled", 'analytics-insights' ); ?></option> |
| 524 |
</select> |
| 525 |
</td> |
| 526 |
</tr> |
| 527 |
<tr> |
| 528 |
<td class="aiwp-settings-title"> |
| 529 |
<label for="tm_category_var"><?php _e("Categories:", 'analytics-insights' ); ?></label> |
| 530 |
</td> |
| 531 |
<td> |
| 532 |
<select id="tm_category_var" name="options[tm_category_var]"> |
| 533 |
<option value="1" <?php selected( $options['tm_category_var'], 1 ); ?>>aiwpCategory</option> |
| 534 |
<option value="0" <?php selected( $options['tm_category_var'], 0 ); ?>><?php _e( "Disabled", 'analytics-insights' ); ?></option> |
| 535 |
</select> |
| 536 |
</td> |
| 537 |
</tr> |
| 538 |
<tr> |
| 539 |
<td class="aiwp-settings-title"> |
| 540 |
<label for="tm_user_var"><?php _e("User Type:", 'analytics-insights' ); ?></label> |
| 541 |
</td> |
| 542 |
<td> |
| 543 |
<select id="tm_user_var" name="options[tm_user_var]"> |
| 544 |
<option value="1" <?php selected( $options['tm_user_var'], 1 ); ?>>aiwpUser</option> |
| 545 |
<option value="0" <?php selected( $options['tm_user_var'], 0 ); ?>><?php _e( "Disabled", 'analytics-insights' ); ?></option> |
| 546 |
</select> |
| 547 |
</td> |
| 548 |
</tr> |
| 549 |
<tr> |
| 550 |
<td class="aiwp-settings-title"> |
| 551 |
<label for="tm_tag_var"><?php _e("Tags:", 'analytics-insights' ); ?></label> |
| 552 |
</td> |
| 553 |
<td> |
| 554 |
<select id="tm_tag_var" name="options[tm_tag_var]"> |
| 555 |
<option value="1" <?php selected( $options['tm_tag_var'], 1 ); ?>>aiwpTag</option> |
| 556 |
<option value="0" <?php selected( $options['tm_tag_var'], 0 ); ?>><?php _e( "Disabled", 'analytics-insights' ); ?></option> |
| 557 |
</select> |
| 558 |
</td> |
| 559 |
</tr> |
| 560 |
</table> |
| 561 |
</div> |
| 562 |
<div id="aiwp-advanced"> |
| 563 |
<table class="aiwp-settings-options"> |
| 564 |
<?php self::html_section_delimiter(__( "Advanced Tracking", 'analytics-insights' ), false); ?> |
| 565 |
<tr> |
| 566 |
<td class="aiwp-settings-title"> |
| 567 |
<label for="ga_user_samplerate"><?php _e("User Sample Rate:", 'analytics-insights'); ?></label> |
| 568 |
</td> |
| 569 |
<td> |
| 570 |
<input type="number" id="ga_user_samplerate" name="options[ga_user_samplerate]" value="<?php echo (int)($options['ga_user_samplerate']); ?>" max="100" min="1"> |
| 571 |
% |
| 572 |
</td> |
| 573 |
</tr> |
| 574 |
<?php self::html_switch_button('options[ga_anonymize_ip]', 1, 'ga_anonymize_ip', $options['ga_anonymize_ip'], __( "anonymize IPs while tracking", 'analytics-insights') ); ?> |
| 575 |
<?php self::html_switch_button('options[ga_event_bouncerate]', 1, 'ga_event_bouncerate', $options['ga_event_bouncerate'], __( "exclude events from bounce-rate and time on page calculation", 'analytics-insights') ); ?> |
| 576 |
<?php self::html_switch_button('options[ga_enhanced_links]', 1, 'ga_enhanced_links', $options['ga_enhanced_links'], __( "enable enhanced link attribution", 'analytics-insights') ); ?> |
| 577 |
<?php self::html_switch_button('options[ga_event_precision]', 1, 'ga_event_precision', $options['ga_event_precision'], __( "use hitCallback to increase event tracking accuracy", 'analytics-insights') ); ?> |
| 578 |
<?php self::html_switch_button('options[ga_optout]', 1, 'ga_optout', $options['ga_optout'], __( "enable support for user opt-out", 'analytics-insights') ); ?> |
| 579 |
<?php self::html_section_delimiter(__( "Cross-domain Tracking", 'analytics-insights' ), false); ?> |
| 580 |
<?php self::html_switch_button('options[ga_crossdomain_tracking]', 1, 'ga_crossdomain_tracking', $options['ga_crossdomain_tracking'], __( "enable cross domain tracking", 'analytics-insights') ); ?> |
| 581 |
<tr> |
| 582 |
<td class="aiwp-settings-title"> |
| 583 |
<label for="ga_crossdomain_list"><?php _e("Cross Domains:", 'analytics-insights'); ?></label> |
| 584 |
</td> |
| 585 |
<td> |
| 586 |
<input type="text" id="ga_crossdomain_list" name="options[ga_crossdomain_list]" value="<?php echo esc_attr($options['ga_crossdomain_list']); ?>" size="50"> |
| 587 |
</td> |
| 588 |
</tr> |
| 589 |
<?php self::html_section_delimiter(__( "Cookie Customization", 'analytics-insights' ), false); ?> |
| 590 |
<tr> |
| 591 |
<td class="aiwp-settings-title"> |
| 592 |
<label for="ga_cookiedomain"><?php _e("Cookie Domain:", 'analytics-insights'); ?></label> |
| 593 |
</td> |
| 594 |
<td> |
| 595 |
<input type="text" id="ga_cookiedomain" name="options[ga_cookiedomain]" value="<?php echo esc_attr($options['ga_cookiedomain']); ?>" size="50"> |
| 596 |
</td> |
| 597 |
</tr> |
| 598 |
<tr> |
| 599 |
<td class="aiwp-settings-title"> |
| 600 |
<label for="ga_cookiename"><?php _e("Cookie Name:", 'analytics-insights'); ?></label> |
| 601 |
</td> |
| 602 |
<td> |
| 603 |
<input type="text" id="ga_cookiename" name="options[ga_cookiename]" value="<?php echo esc_attr($options['ga_cookiename']); ?>" size="50"> |
| 604 |
</td> |
| 605 |
</tr> |
| 606 |
<tr> |
| 607 |
<td class="aiwp-settings-title"> |
| 608 |
<label for="ga_cookieexpires"><?php _e("Cookie Expires:", 'analytics-insights'); ?></label> |
| 609 |
</td> |
| 610 |
<td> |
| 611 |
<input type="text" id="ga_cookieexpires" name="options[ga_cookieexpires]" value="<?php echo esc_attr($options['ga_cookieexpires']); ?>" size="10"> |
| 612 |
<?php _e("seconds", 'analytics-insights' ); ?> |
| 613 |
</td> |
| 614 |
</tr> |
| 615 |
<tr> |
| 616 |
<td class="aiwp-settings-title"> |
| 617 |
<label for="ga_samesite"><?php _e("SameSite Attribute:", 'analytics-insights' ); ?></label> |
| 618 |
</td> |
| 619 |
<td> |
| 620 |
<select id="ga_samesite" name="options[ga_samesite]"> |
| 621 |
<option value="" <?php selected( $options['ga_samesite'], '' ); ?>><?php _e("Disabled", 'analytics-insights');?></option> |
| 622 |
<option value="Strict" <?php selected( $options['ga_samesite'], 'Strict' ); ?>><?php _e("Strict", 'analytics-insights');?></option> |
| 623 |
<option value="Lax" <?php selected( $options['ga_samesite'], 'Lax' ); ?>><?php _e("Lax", 'analytics-insights');?></option> |
| 624 |
<option value="None" <?php selected( $options['ga_samesite'], 'None' ); ?>><?php _e("None", 'analytics-insights');?></option> |
| 625 |
</select> |
| 626 |
</td> |
| 627 |
</tr> |
| 628 |
</table> |
| 629 |
</div> |
| 630 |
<div id="aiwp-integration"> |
| 631 |
<table class="aiwp-settings-options"> |
| 632 |
<?php self::html_section_delimiter(__( "Accelerated Mobile Pages (AMP)", 'analytics-insights' ), false); ?> |
| 633 |
<?php self::html_switch_button('options[amp_tracking_analytics]', 1, 'amp_tracking_analytics', $options['amp_tracking_analytics'], __( "enable tracking for Accelerated Mobile Pages (AMP)", 'analytics-insights') ); ?> |
| 634 |
<?php self::html_section_delimiter(__( "Optimize", 'analytics-insights' ), false); ?> |
| 635 |
<?php self::html_switch_button('options[optimize_tracking]', 1, 'optimize_tracking', $options['optimize_tracking'], __( "enable Optimize tracking", 'analytics-insights') ); ?> |
| 636 |
<?php self::html_switch_button('options[optimize_pagehiding]', 1, 'optimize_pagehiding', $options['optimize_pagehiding'], __( "enable Page Hiding support", 'analytics-insights') ); ?> |
| 637 |
<tr> |
| 638 |
<td class="aiwp-settings-title"> |
| 639 |
<label for="tracking_type"><?php _e("Container ID:", 'analytics-insights' ); ?></label> |
| 640 |
</td> |
| 641 |
<td> |
| 642 |
<input type="text" name="options[optimize_containerid]" value="<?php echo esc_attr($options['optimize_containerid']); ?>" size="15"> |
| 643 |
</td> |
| 644 |
</tr> |
| 645 |
</table> |
| 646 |
</div> |
| 647 |
<div id="aiwp-tmadvanced"> |
| 648 |
<table class="aiwp-settings-options"> |
| 649 |
<?php self::html_section_delimiter(__( "Advanced Tracking", 'analytics-insights' ), false); ?> |
| 650 |
<?php self::html_switch_button('options[tm_optout]', 1, 'tm_optout', $options['tm_optout'], __( "enable support for user opt-out", 'analytics-insights') ); ?> |
| 651 |
</table> |
| 652 |
</div> |
| 653 |
<div id="aiwp-tmintegration"> |
| 654 |
<table class="aiwp-settings-options"> |
| 655 |
<?php self::html_section_delimiter(__( "Accelerated Mobile Pages (AMP)", 'analytics-insights' ), false); ?> |
| 656 |
<?php self::html_switch_button('options[amp_tracking_tagmanager]', 1, 'amp_tracking_tagmanager', $options['amp_tracking_tagmanager'], __( "enable tracking for Accelerated Mobile Pages (AMP)", 'analytics-insights') ); ?> |
| 657 |
<tr> |
| 658 |
<td class="aiwp-settings-title"> |
| 659 |
<label for="tracking_type"><?php _e("AMP Container ID:", 'analytics-insights' ); ?></label> |
| 660 |
</td> |
| 661 |
<td> |
| 662 |
<input type="text" name="options[amp_containerid]" value="<?php echo esc_attr($options['amp_containerid']); ?>" size="15"> |
| 663 |
</td> |
| 664 |
</tr> |
| 665 |
</table> |
| 666 |
</div> |
| 667 |
<div id="aiwp-exclude"> |
| 668 |
<table class="aiwp-settings-options"> |
| 669 |
<?php self::html_section_delimiter(__( "Exclude Tracking", 'analytics-insights' ), false); ?> |
| 670 |
<tr> |
| 671 |
<td class="roles aiwp-settings-title"> |
| 672 |
<label for="track_exclude"><?php _e("Exclude tracking for:", 'analytics-insights' ); ?></label> |
| 673 |
</td> |
| 674 |
<td class="aiwp-settings-roles"> |
| 675 |
<table> |
| 676 |
<tr> |
| 677 |
<?php if ( ! isset( $wp_roles ) ) : ?> |
| 678 |
<?php $wp_roles = new WP_Roles(); ?> |
| 679 |
<?php endif; ?> |
| 680 |
<?php $i = 0; ?> |
| 681 |
<?php foreach ( $wp_roles->role_names as $role => $name ) : ?> |
| 682 |
<?php if ( 'subscriber' != $role ) : ?> |
| 683 |
<?php $i++; ?> |
| 684 |
<td> |
| 685 |
<label> |
| 686 |
<input type="checkbox" name="options[track_exclude][]" value="<?php echo esc_attr( $role ); ?>" <?php if (in_array($role,$options['track_exclude'])) echo 'checked="checked"'; ?> /> <?php echo esc_attr( $name ); ?></label> |
| 687 |
</td> |
| 688 |
<?php endif; ?> |
| 689 |
<?php if ( 0 == $i % 4 ) : ?> |
| 690 |
</tr> |
| 691 |
<tr> |
| 692 |
<?php endif; ?> |
| 693 |
<?php endforeach; ?> |
| 694 |
|
| 695 |
|
| 696 |
</table> |
| 697 |
</td> |
| 698 |
</tr> |
| 699 |
</table> |
| 700 |
</div> |
| 701 |
<table class="aiwp-settings-options"> |
| 702 |
<?php self::html_section_delimiter(); ?> |
| 703 |
<tr> |
| 704 |
<td colspan="2" class="submit"> |
| 705 |
<input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'analytics-insights' ) ?>" /> |
| 706 |
</td> |
| 707 |
</tr> |
| 708 |
</table> |
| 709 |
<?php self::html_form_end(); ?> |
| 710 |
<?php |
| 711 |
AIWP_Tools::load_view( 'admin/views/settings-sidebar.php', array() ); |
| 712 |
} |
| 713 |
|
| 714 |
public static function errors_debugging() { |
| 715 |
$aiwp = AIWP(); |
| 716 |
$message = ''; |
| 717 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 718 |
return; |
| 719 |
} |
| 720 |
$anonim = AIWP_Tools::anonymize_options( $aiwp->config->options ); |
| 721 |
$options = self::update_options( 'frontend' ); |
| 722 |
?> |
| 723 |
<?php self::html_form_begin(__( "Google Analytics Errors & Debugging", 'analytics-insights' ), $_SERVER['REQUEST_URI'], $message)?> |
| 724 |
<?php $tabs = array( 'errors' => __( "Errors & Details", 'analytics-insights' ), 'config' => __( "Plugin Settings", 'analytics-insights' ), 'sysinfo' => __( "System", 'analytics-insights' ) ); ?> |
| 725 |
<?php self::navigation_tabs( $tabs ); ?> |
| 726 |
<div id="aiwp-errors"> |
| 727 |
<table class="aiwp-settings-logdata"> |
| 728 |
<?php self::html_section_delimiter(__( "Detected Errors", 'analytics-insights' ), false, false); ?> |
| 729 |
<tr> |
| 730 |
<td> |
| 731 |
<?php $errors_count = AIWP_Tools::get_cache( 'errors_count' ); ?> |
| 732 |
<pre class="aiwp-settings-logdata"><?php echo '<span>' . __("Count: ", 'analytics-insights') . '</span>' . (int)$errors_count;?></pre> |
| 733 |
<?php $error = AIWP_Tools::get_cache( 'api_errors' ) ?> |
| 734 |
<?php $ajax_error = AIWP_Tools::get_cache( 'ajax_errors' ) ?> |
| 735 |
<?php $error_code = isset( $error[0] ) ? $error[0] : 'None' ?> |
| 736 |
<?php $error_reason = ( isset( $error[1] ) && !empty($error[1]) ) ? print_r( $error[1], true) : 'None' ?> |
| 737 |
<?php $error_ajax = $ajax_error ? print_r( $ajax_error , true) : 'None' ?> |
| 738 |
<?php $error_details = isset( $error[2] ) ? print_r( $error[2], true) : 'None' ?> |
| 739 |
<pre class="aiwp-settings-logdata"><?php echo '<span>' . __("Ajax Error Code: ", 'analytics-insights') . '</span>' . esc_html( $error_ajax );?></pre> |
| 740 |
<pre class="aiwp-settings-logdata"><?php echo '<span>' . __("API Error Code: ", 'analytics-insights') . '</span>' . esc_html( $error_code );?></pre> |
| 741 |
<pre class="aiwp-settings-logdata"><?php echo '<span>' . __("API Error Reason: ", 'analytics-insights') . '</span>' . "\n" . esc_html( $error_reason );?></pre> |
| 742 |
<?php $error_details = str_replace( 'Deconf_', 'Google_', $error_details); ?> |
| 743 |
<pre class="aiwp-settings-logdata"><?php echo '<span>' . __("API Error Details: ", 'analytics-insights') . '</span>' . "\n" . esc_html( $error_details );?></pre> |
| 744 |
<br /> |
| 745 |
<hr> |
| 746 |
</td> |
| 747 |
</tr> |
| 748 |
<?php self::html_section_delimiter(__( "Sampled Data", 'analytics-insights' ), false, false); ?> |
| 749 |
<tr> |
| 750 |
<td> |
| 751 |
<?php $sampling = AIWP_TOOLS::get_cache( 'sampleddata' ); ?> |
| 752 |
<?php if ( $sampling ) :?> |
| 753 |
<?php printf( __( "Last Detected on %s.", 'analytics-insights' ), '<strong>'. esc_html( $sampling['date'] ) . '</strong>' );?><br /> |
| 754 |
<?php printf( __( "The report was based on %s of sessions.", 'analytics-insights' ), '<strong>'. esc_html( $sampling['percent'] ) . '</strong>' );?><br /> |
| 755 |
<?php printf( __( "Sessions ratio: %s.", 'analytics-insights' ), '<strong>'. esc_html( $sampling['sessions'] ) . '</strong>' ); ?> |
| 756 |
<?php else :?> |
| 757 |
<?php _e( "None", 'analytics-insights' ); ?> |
| 758 |
<?php endif;?> |
| 759 |
</td> |
| 760 |
</tr> |
| 761 |
</table> |
| 762 |
</div> |
| 763 |
<div id="aiwp-config"> |
| 764 |
<table class="aiwp-settings-options"> |
| 765 |
<?php self::html_section_delimiter(__( "Plugin Configuration", 'analytics-insights' ), false, false); ?> |
| 766 |
<tr> |
| 767 |
<td> |
| 768 |
<pre class="aiwp-settings-logdata"><?php echo esc_html( print_r( $anonim, true ) );?></pre> |
| 769 |
<br /> |
| 770 |
<hr> |
| 771 |
</td> |
| 772 |
</tr> |
| 773 |
</table> |
| 774 |
</div> |
| 775 |
<div id="aiwp-sysinfo"> |
| 776 |
<table class="aiwp-settings-options"> |
| 777 |
<?php self::html_section_delimiter(__( "System Information", 'analytics-insights' ), false, false); ?> |
| 778 |
<tr> |
| 779 |
<td> |
| 780 |
<pre class="aiwp-settings-logdata"><?php echo esc_html( AIWP_Tools::system_info() );?></pre> |
| 781 |
<br /> |
| 782 |
<hr> |
| 783 |
</td> |
| 784 |
</tr> |
| 785 |
</table> |
| 786 |
</div> |
| 787 |
<?php self::html_form_end(); ?> |
| 788 |
<?php |
| 789 |
AIWP_Tools::load_view( 'admin/views/settings-sidebar.php', array() ); |
| 790 |
} |
| 791 |
|
| 792 |
public static function general_settings() { |
| 793 |
$aiwp = AIWP(); |
| 794 |
$message = ''; |
| 795 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 796 |
return; |
| 797 |
} |
| 798 |
$options = self::update_options( 'general' ); |
| 799 |
printf( '<div id="gapi-warning" class="updated"><p>%1$s <a href="https://deconf.com/analytics-insights-google-analytics-dashboard-wordpress/?utm_source=aiwp_config&utm_medium=link&utm_content=general_screen&utm_campaign=aiwp">%2$s</a></p></div>', __( 'Loading the required libraries. If this results in a blank screen or a fatal error, try this solution:', 'analytics-insights' ), __( 'Library conflicts between WordPress plugins', 'analytics-insights' ) ); |
| 800 |
if ( null === $aiwp->gapi_controller ) { |
| 801 |
$aiwp->gapi_controller = new AIWP_GAPI_Controller(); |
| 802 |
} |
| 803 |
echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>'; |
| 804 |
|
| 805 |
if ( isset( $_REQUEST['aiwp_access_code'] ) || isset( $_REQUEST['code'] ) ){ |
| 806 |
|
| 807 |
if ( isset( $_REQUEST['state'] ) && wp_verify_nonce( $_REQUEST['state'], 'aiwp_state' ) ) { |
| 808 |
|
| 809 |
if ( isset( $_REQUEST['code'] ) ){ |
| 810 |
$aiwp_access_code = sanitize_text_field( $_REQUEST['code'] ); |
| 811 |
} else { |
| 812 |
$aiwp_access_code = sanitize_text_field( $_REQUEST['aiwp_access_code'] ); |
| 813 |
} |
| 814 |
|
| 815 |
AIWP_Tools::delete_cache( 'api_errors' ); |
| 816 |
AIWP_Tools::delete_cache( 'ajax_errors' ); |
| 817 |
|
| 818 |
$token = $aiwp->gapi_controller->authenticate( $aiwp_access_code ); |
| 819 |
|
| 820 |
$aiwp->config->options['token'] = $token; |
| 821 |
|
| 822 |
$aiwp->config->set_plugin_options(); |
| 823 |
|
| 824 |
$options = self::update_options( 'general' ); |
| 825 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "Plugin authorization succeeded.", 'analytics-insights' ) . "</p></div>"; |
| 826 |
if ( $aiwp->config->options['token'] ) { |
| 827 |
|
| 828 |
$webstreams = $aiwp->gapi_controller->refresh_profiles_ga4(); |
| 829 |
if ( is_array( $webstreams ) && ! empty( $webstreams ) ) { |
| 830 |
$aiwp->config->options['ga4_webstreams_list'] = $webstreams; |
| 831 |
if ( ! $aiwp->config->options['webstream_jail'] ) { |
| 832 |
$property = AIWP_Tools::guess_default_domain( $webstreams, 2 ); |
| 833 |
$aiwp->config->options['webstream_jail'] = $property; |
| 834 |
} |
| 835 |
$aiwp->config->set_plugin_options(); |
| 836 |
$options = self::update_options( 'general' ); |
| 837 |
} |
| 838 |
|
| 839 |
} |
| 840 |
|
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
if ( isset( $_REQUEST['Clear'] ) ) { |
| 845 |
if ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) { |
| 846 |
AIWP_Tools::clear_cache(); |
| 847 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "Cleared Cache.", 'analytics-insights' ) . "</p></div>"; |
| 848 |
} else { |
| 849 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 850 |
} |
| 851 |
} |
| 852 |
if ( isset( $_REQUEST['Reset'] ) ) { |
| 853 |
if ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) { |
| 854 |
$aiwp->gapi_controller->reset_token( true, true ); |
| 855 |
AIWP_Tools::clear_cache(); |
| 856 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "Token Reseted and Revoked.", 'analytics-insights' ) . "</p></div>"; |
| 857 |
$options = self::update_options( 'Reset' ); |
| 858 |
} else { |
| 859 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 860 |
} |
| 861 |
} |
| 862 |
if ( isset( $_REQUEST['Reset_Err'] ) ) { |
| 863 |
if ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) { |
| 864 |
AIWP_Tools::delete_cache( 'api_errors' ); |
| 865 |
AIWP_Tools::delete_cache( 'ajax_errors' ); |
| 866 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "All errors reseted.", 'analytics-insights' ) . "</p></div>"; |
| 867 |
} else { |
| 868 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 869 |
} |
| 870 |
} |
| 871 |
if ( isset( $_REQUEST['options']['aiwp_hidden'] ) && ! isset( $_REQUEST['Clear'] ) && ! isset( $_REQUEST['Reset'] ) && ! isset( $_REQUEST['Reset_Err'] ) ) { |
| 872 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "Settings saved.", 'analytics-insights' ) . "</p></div>"; |
| 873 |
if ( ! ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) ) { |
| 874 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 875 |
} |
| 876 |
} |
| 877 |
if ( isset( $_REQUEST['Hide'] ) ) { |
| 878 |
if ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) { |
| 879 |
$message = "<div class='updated' id='aiwp-action'><p>" . __( "All other domains/properties were removed.", 'analytics-insights' ) . "</p></div>"; |
| 880 |
$lock_property = AIWP_Tools::get_selected_profile( $aiwp->config->options['ga4_webstreams_list'], $aiwp->config->options['webstream_jail'] ); |
| 881 |
if ( empty( $lock_property ) ) { |
| 882 |
$aiwp->config->options['ga4_webstreams_list'] = ''; |
| 883 |
} else { |
| 884 |
$aiwp->config->options['ga4_webstreams_list'] = array( $lock_property ); |
| 885 |
} |
| 886 |
$options = self::update_options( 'general' ); |
| 887 |
} else { |
| 888 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 889 |
} |
| 890 |
} |
| 891 |
?> |
| 892 |
<?php self::html_form_begin(__( "Google Analytics Settings", 'analytics-insights' ), admin_url( 'admin.php?page=aiwp_settings' ), $message)?> |
| 893 |
<table class="aiwp-settings-options"> |
| 894 |
<?php self::html_section_delimiter(__( "Plugin Authorization", 'analytics-insights' ), false); ?> |
| 895 |
<tr> |
| 896 |
<td colspan="2" class="aiwp-settings-info"> |
| 897 |
<?php printf(__('New to Google Analytics? You should follow this %1$s before proceeding to authorization.', 'analytics-insights'), sprintf('<a href="%1$s" target="_blank">%2$s</a>', 'https://deconf.com/how-to-add-google-analytics-to-wordpress-easy-way/?utm_source=aiwp_config&utm_medium=link&utm_content=authorization-tutorial&utm_campaign=aiwp', __("step-by-step tutorial", 'analytics-insights')));?> |
| 898 |
</td> |
| 899 |
</tr> |
| 900 |
<?php if (! $options['token'] || ($options['user_api'] && ! $options['network_mode'])) : ?> |
| 901 |
<tr> |
| 902 |
<td colspan="2" class="aiwp-settings-info"> |
| 903 |
<input name="options[user_api]" type="checkbox" id="user_api" value="1" <?php checked( $options['user_api'], 1 ); ?> onchange="this.form.submit()" <?php echo ($options['network_mode'])?'disabled="disabled"':''; ?> /><?php echo " ".__("developer mode (requires advanced API knowledge)", 'analytics-insights' );?> |
| 904 |
</td> |
| 905 |
</tr> |
| 906 |
<?php endif; ?> |
| 907 |
<?php if ($options['user_api'] && ! $options['network_mode']) : ?> |
| 908 |
<tr> |
| 909 |
<td class="aiwp-settings-title"> |
| 910 |
<label for="options[client_id]"><?php _e("Client ID:", 'analytics-insights'); ?></label> |
| 911 |
</td> |
| 912 |
<td> |
| 913 |
<input type="text" name="options[client_id]" value="<?php echo esc_attr( $options['client_id'] ); ?>" size="40" required="required"> |
| 914 |
</td> |
| 915 |
</tr> |
| 916 |
<tr> |
| 917 |
<td class="aiwp-settings-title"> |
| 918 |
<label for="options[client_secret]"><?php _e("Client Secret:", 'analytics-insights'); ?></label> |
| 919 |
</td> |
| 920 |
<td> |
| 921 |
<input type="text" name="options[client_secret]" value="<?php echo esc_attr( $options['client_secret'] ); ?>" size="40" required="required"> |
| 922 |
<?php if ( !$options['token'] ) : ?> |
| 923 |
<input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Credentials', 'analytics-insights' ) ?>" /> |
| 924 |
<?php endif; ?> |
| 925 |
</td> |
| 926 |
</tr> |
| 927 |
<?php endif; ?> |
| 928 |
<?php if ( $options['token'] ) : ?> |
| 929 |
<tr> |
| 930 |
<td colspan="2"> |
| 931 |
<button type="submit" name="Reset" class="button button-secondary" <?php echo $options['network_mode']?'disabled="disabled"':''; ?>><?php _e( "Clear Authorization", 'analytics-insights' ); ?></button> |
| 932 |
<button type="submit" name="Clear" class="button button-secondary"><?php _e( "Clear Cache", 'analytics-insights' ); ?></button> |
| 933 |
<button type="submit" name="Reset_Err" class="button button-secondary"><?php _e( "Reset Errors", 'analytics-insights' ); ?></button> |
| 934 |
</td> |
| 935 |
</tr> |
| 936 |
<?php self::html_section_delimiter(); ?> |
| 937 |
<?php self::html_section_delimiter(__( "General Settings", 'analytics-insights' ), false); ?> |
| 938 |
<tr> |
| 939 |
<td class="aiwp-settings-title"> |
| 940 |
<label for="webstream_jail"><?php _e("Google Analaytics 4:", 'analytics-insights' ); ?></label> |
| 941 |
</td> |
| 942 |
<td> |
| 943 |
<select id="webstream_jail" <?php disabled(empty($options['ga4_webstreams_list']) || 1 == count($options['ga4_webstreams_list']), true); ?> name="options[webstream_jail]"> |
| 944 |
<?php if ( ! empty( $options['ga4_webstreams_list'] ) ) : ?> |
| 945 |
<?php foreach ( $options['ga4_webstreams_list'] as $items ) : ?> |
| 946 |
<?php if ( $items[2] ) : ?> |
| 947 |
<option value="<?php echo esc_attr( $items[1] ); ?>" <?php selected( $items[1], $options['webstream_jail'] ); ?> title="<?php _e( "Stream Name:", 'analytics-insights' ); ?> <?php echo esc_attr( $items[0] ); ?>"> |
| 948 |
<?php echo esc_html( AIWP_Tools::strip_protocol( $items[2] ) )?> ⇒ <?php echo esc_attr( $items[0] ); ?> |
| 949 |
</option> |
| 950 |
<?php endif; ?> |
| 951 |
<?php endforeach; ?> |
| 952 |
<?php endif; ?> |
| 953 |
</select> |
| 954 |
</td> |
| 955 |
</tr> |
| 956 |
<?php if ( $options['webstream_jail'] && !empty( $aiwp->config->options['ga4_webstreams_list'] ) ) : ?> |
| 957 |
<tr> |
| 958 |
<td class="aiwp-settings-title"></td> |
| 959 |
<td> |
| 960 |
<?php $webstream_info = AIWP_Tools::get_selected_profile( $aiwp->config->options['ga4_webstreams_list'], $aiwp->config->options['webstream_jail'] ); ?> |
| 961 |
<?php $webstream_info[5] = isset( $webstream_info[5] ) ? $webstream_info[5] : '' ?> |
| 962 |
<pre><?php echo __( "Stream Name:", 'analytics-insights' ) . "\t" . esc_html( $webstream_info[0] ) . "<br />" . __( "Stream ID:", 'analytics-insights' ) . "\t" . esc_html( $webstream_info[1] ) . "<br />" . __( "Stream URL:", 'analytics-insights' ) . "\t" . esc_html( $webstream_info[2] ) . "<br />" . __( "Measurement ID:", 'analytics-insights' ) . "\t" . esc_html( $webstream_info[3] ) . "<br />" . __( "Time Zone:", 'analytics-insights' ) . "\t" . esc_html( $webstream_info[5] );?></pre> |
| 963 |
</td> |
| 964 |
</tr> |
| 965 |
<?php endif; ?> |
| 966 |
<tr> |
| 967 |
<td> </td> |
| 968 |
</tr> |
| 969 |
<tr> |
| 970 |
<td class="aiwp-settings-title"> |
| 971 |
<label for="theme_color"><?php _e("Theme Color:", 'analytics-insights' ); ?></label> |
| 972 |
</td> |
| 973 |
<td> |
| 974 |
<input type="text" id="theme_color" class="theme_color" name="options[theme_color]" value="<?php echo esc_attr( $options['theme_color'] ); ?>" size="10"> |
| 975 |
</td> |
| 976 |
</tr> |
| 977 |
<tr> |
| 978 |
<td> </td> |
| 979 |
</tr> |
| 980 |
<tr> |
| 981 |
<td colspan="2" class="submit"> |
| 982 |
<input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'analytics-insights' ) ?>" /> |
| 983 |
<?php if ( ( is_array( $options['ga4_webstreams_list'] ) && count( $options['ga4_webstreams_list'] ) > 1 ) ): ?> |
| 984 |
<input type="submit" name="Hide" class="button button-secondary" " value="<?php _e( "Lock Selection", 'analytics-insights' ); ?>" /> |
| 985 |
<?php endif; ?> |
| 986 |
</td> |
| 987 |
</tr> |
| 988 |
<?php else : ?> |
| 989 |
<?php self::html_section_delimiter(); ?> |
| 990 |
<tr> |
| 991 |
<td colspan="2"> |
| 992 |
<?php $auth = $aiwp->gapi_controller->createAuthUrl();?> |
| 993 |
<button type="submit" class="button button-secondary" formaction="<?php echo esc_url_raw( $auth ); ?>" <?php echo $options['network_mode']?'disabled="disabled"':''; ?>><?php _e( "Authorize Plugin", 'analytics-insights' ); ?></button> |
| 994 |
<button type="submit" name="Clear" class="button button-secondary"><?php _e( "Clear Cache", 'analytics-insights' ); ?></button> |
| 995 |
</td> |
| 996 |
</tr> |
| 997 |
<?php self::html_section_delimiter(); ?> |
| 998 |
</table> |
| 999 |
<?php self::html_form_end(); ?> |
| 1000 |
<?php AIWP_Tools::load_view( 'admin/views/settings-sidebar.php', array() ); ?> |
| 1001 |
<?php return; ?> |
| 1002 |
<?php endif; ?> |
| 1003 |
</table> |
| 1004 |
<?php |
| 1005 |
AIWP_Tools::load_view( 'admin/views/settings-sidebar.php', array() ); |
| 1006 |
} |
| 1007 |
|
| 1008 |
// Network Settings |
| 1009 |
public static function general_settings_network() { |
| 1010 |
$aiwp = AIWP(); |
| 1011 |
$message = ''; |
| 1012 |
if ( ! current_user_can( 'manage_network_options' ) ) { |
| 1013 |
return; |
| 1014 |
} |
| 1015 |
$options = self::update_options( 'network' ); |
| 1016 |
/* |
| 1017 |
* Include GAPI |
| 1018 |
*/ |
| 1019 |
echo '<div id="gapi-warning" class="updated"><p>' . __( 'Loading the required libraries. If this results in a blank screen or a fatal error, try this solution:', 'analytics-insights' ) . ' <a href="https://deconf.com/analytics-insights-google-analytics-dashboard-wordpress/?utm_source=aiwp_config&utm_medium=link&utm_content=general_screen&utm_campaign=aiwp">Library conflicts between WordPress plugins</a></p></div>'; |
| 1020 |
if ( null === $aiwp->gapi_controller ) { |
| 1021 |
$aiwp->gapi_controller = new AIWP_GAPI_Controller(); |
| 1022 |
} |
| 1023 |
echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>'; |
| 1024 |
if ( isset( $_REQUEST['aiwp_access_code'] ) || isset( $_REQUEST['code'] ) ){ |
| 1025 |
|
| 1026 |
if ( isset( $_REQUEST['state'] ) && wp_verify_nonce( $_REQUEST['state'], 'aiwp_state' ) ) { |
| 1027 |
|
| 1028 |
if ( isset( $_REQUEST['code'] ) ){ |
| 1029 |
$aiwp_access_code = sanitize_text_field( $_REQUEST['code'] ); |
| 1030 |
} else { |
| 1031 |
$aiwp_access_code = sanitize_text_field( $_REQUEST['aiwp_access_code'] ); |
| 1032 |
} |
| 1033 |
|
| 1034 |
$aiwp_access_code = sanitize_text_field( $_REQUEST['aiwp_access_code'] ); |
| 1035 |
|
| 1036 |
$token = $aiwp->gapi_controller->authenticate( $aiwp_access_code ); |
| 1037 |
$aiwp->config->options['token'] = $token; |
| 1038 |
$aiwp->config->set_plugin_options( true ); |
| 1039 |
$options = self::update_options( 'network' ); |
| 1040 |
$message = "<div class='updated' id='aiwp-action'><p>" . __( "Plugin authorization succeeded.", 'analytics-insights' ) . "</p></div>"; |
| 1041 |
if ( is_multisite() ) { // Cleanup errors on the entire network |
| 1042 |
foreach ( AIWP_Tools::get_sites( array( 'number' => apply_filters( 'aiwp_sites_limit', 100 ) ) ) as $blog ) { |
| 1043 |
switch_to_blog( $blog['blog_id'] ); |
| 1044 |
AIWP_Tools::delete_cache( 'api_errors' ); |
| 1045 |
AIWP_Tools::delete_cache( 'ajax_errors' ); |
| 1046 |
restore_current_blog(); |
| 1047 |
} |
| 1048 |
} else { |
| 1049 |
AIWP_Tools::delete_cache( 'api_errors' ); |
| 1050 |
AIWP_Tools::delete_cache( 'ajax_errors' ); |
| 1051 |
} |
| 1052 |
if ( $aiwp->config->options['token'] ) { |
| 1053 |
$webstreams = $aiwp->gapi_controller->refresh_profiles_ga4(); |
| 1054 |
if ( is_array( $webstreams ) && ! empty( $webstreams ) ) { |
| 1055 |
$aiwp->config->options['ga4_webstreams_list'] = $webstreams; |
| 1056 |
if ( isset( $aiwp->config->options['webstream_jail'] ) && ! $aiwp->config->options['webstream_jail'] ) { |
| 1057 |
// $property = AIWP_Tools::guess_default_domain( $webstreams, 2 ); |
| 1058 |
// $aiwp->config->options['webstream_jail'] = $property; |
| 1059 |
} |
| 1060 |
$aiwp->config->set_plugin_options( true ); |
| 1061 |
$options = self::update_options( 'network' ); |
| 1062 |
} |
| 1063 |
} |
| 1064 |
} |
| 1065 |
} |
| 1066 |
if ( isset( $_REQUEST['Refresh'] ) ) { |
| 1067 |
if ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) { |
| 1068 |
$aiwp->config->options['ga4_webstreams_list'] = array(); |
| 1069 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "Properties refreshed.", 'analytics-insights' ) . "</p></div>"; |
| 1070 |
$options = self::update_options( 'network' ); |
| 1071 |
if ( $aiwp->config->options['token'] ) { |
| 1072 |
if ( ! empty( $aiwp->config->options['ga4_webstreams_list'] ) ) { |
| 1073 |
$webstreams = $aiwp->config->options['ga4_webstreams_list']; |
| 1074 |
} else { |
| 1075 |
$webstreams = $aiwp->gapi_controller->refresh_profiles_ga4(); |
| 1076 |
} |
| 1077 |
if ( $webstreams ) { |
| 1078 |
$aiwp->config->options['ga4_webstreams_list'] = $webstreams; |
| 1079 |
if ( isset( $aiwp->config->options['webstream_jail'] ) && ! $aiwp->config->options['webstream_jail'] ) { |
| 1080 |
// $property = AIWP_Tools::guess_default_domain( $webstreams, 2 ); |
| 1081 |
// $aiwp->config->options['webstream_jail'] = $property; |
| 1082 |
} |
| 1083 |
$aiwp->config->set_plugin_options( true ); |
| 1084 |
$options = self::update_options( 'network' ); |
| 1085 |
} |
| 1086 |
} |
| 1087 |
} else { |
| 1088 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 1089 |
} |
| 1090 |
} |
| 1091 |
if ( isset( $_REQUEST['Clear'] ) ) { |
| 1092 |
if ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) { |
| 1093 |
AIWP_Tools::clear_cache(); |
| 1094 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "Cleared Cache.", 'analytics-insights' ) . "</p></div>"; |
| 1095 |
} else { |
| 1096 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 1097 |
} |
| 1098 |
} |
| 1099 |
if ( isset( $_REQUEST['Reset'] ) ) { |
| 1100 |
if ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) { |
| 1101 |
$aiwp->gapi_controller->reset_token( true, true ); |
| 1102 |
AIWP_Tools::clear_cache(); |
| 1103 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "Token Reseted and Revoked.", 'analytics-insights' ) . "</p></div>"; |
| 1104 |
$options = self::update_options( 'Reset' ); |
| 1105 |
} else { |
| 1106 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 1107 |
} |
| 1108 |
} |
| 1109 |
if ( isset( $_REQUEST['options']['aiwp_hidden'] ) && ! isset( $_REQUEST['Clear'] ) && ! isset( $_REQUEST['Reset'] ) && ! isset( $_REQUEST['Refresh'] ) ) { |
| 1110 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "Settings saved.", 'analytics-insights' ) . "</p></div>"; |
| 1111 |
if ( ! ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) ) { |
| 1112 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 1113 |
} |
| 1114 |
} |
| 1115 |
if ( isset( $_REQUEST['Hide'] ) ) { |
| 1116 |
if ( isset( $_REQUEST['aiwp_security'] ) && wp_verify_nonce( $_REQUEST['aiwp_security'], 'aiwp_form' ) ) { |
| 1117 |
$message = "<div class='updated' id='aiwp-autodismiss'><p>" . __( "All other domains/properties were removed.", 'analytics-insights' ) . "</p></div>"; |
| 1118 |
$lock_property = AIWP_Tools::get_selected_profile( $aiwp->config->options['ga4_webstreams_list'], $aiwp->config->options['webstream_jail'] ); |
| 1119 |
if ( empty( $lock_property ) ) { |
| 1120 |
$aiwp->config->options['ga4_webstreams_list'] = array(); |
| 1121 |
} else { |
| 1122 |
$aiwp->config->options['ga4_webstreams_list'] = array( $lock_property ); |
| 1123 |
} |
| 1124 |
$options = self::update_options( 'network' ); |
| 1125 |
} else { |
| 1126 |
$message = "<div class='error' id='aiwp-autodismiss'><p>" . __( "You do not have sufficient permissions to access this page.", 'analytics-insights' ) . "</p></div>"; |
| 1127 |
} |
| 1128 |
} |
| 1129 |
?> |
| 1130 |
<?php self::html_form_begin(__( "Google Analytics Settings", 'analytics-insights' ), network_admin_url( 'admin.php?page=aiwp_settings' ), $message)?> |
| 1131 |
<table class="aiwp-settings-options"> |
| 1132 |
<?php self::html_section_delimiter(__( "Network Setup", 'analytics-insights' ), false); ?> |
| 1133 |
<?php self::html_switch_button('options[network_mode]', 1, 'network_mode', $options['network_mode'], __( "use a single Google Analytics account for the entire network", 'analytics-insights'), false, true ); ?> |
| 1134 |
<?php if ( $options['network_mode'] ) : ?> |
| 1135 |
<?php self::html_section_delimiter(); ?> |
| 1136 |
<?php self::html_section_delimiter(__( "Plugin Authorization", 'analytics-insights' ), false); ?> |
| 1137 |
<tr> |
| 1138 |
<td colspan="2" class="aiwp-settings-info"> |
| 1139 |
<?php printf(__('New to Google Analytics? You should follow this %1$s before proceeding to authorization.', 'analytics-insights'), sprintf('<a href="%1$s" target="_blank">%2$s</a>', 'https://deconf.com/how-to-add-google-analytics-to-wordpress-easy-way/?utm_source=aiwp_config&utm_medium=link&utm_content=authorizarion-screen&utm_campaign=aiwp', __("step-by-step tutorial", 'analytics-insights')));?> |
| 1140 |
</td> |
| 1141 |
</tr> |
| 1142 |
<?php if ( ! $options['token'] || $options['user_api'] ) : ?> |
| 1143 |
<tr> |
| 1144 |
<td colspan="2" class="aiwp-settings-info"> |
| 1145 |
<input name="options[user_api]" type="checkbox" id="user_api" value="1" <?php checked( $options['user_api'], 1 ); ?> onchange="this.form.submit()" /><?php echo " ".__("developer mode (requires advanced API knowledge)", 'analytics-insights' );?> |
| 1146 |
</td> |
| 1147 |
</tr> |
| 1148 |
<?php endif; ?> |
| 1149 |
<?php if ( $options['user_api'] ) : ?> |
| 1150 |
<tr> |
| 1151 |
<td class="aiwp-settings-title"> |
| 1152 |
<label for="options[client_id]"><?php _e("Client ID:", 'analytics-insights'); ?></label> |
| 1153 |
</td> |
| 1154 |
<td> |
| 1155 |
<input type="text" name="options[client_id]" value="<?php echo esc_attr( $options['client_id'] ); ?>" size="40" required="required"> |
| 1156 |
</td> |
| 1157 |
</tr> |
| 1158 |
<tr> |
| 1159 |
<td class="aiwp-settings-title"> |
| 1160 |
<label for="options[client_secret]"><?php _e("Client Secret:", 'analytics-insights'); ?></label> |
| 1161 |
</td> |
| 1162 |
<td> |
| 1163 |
<input type="text" name="options[client_secret]" value="<?php echo esc_attr( $options['client_secret'] ); ?>" size="40" required="required"> |
| 1164 |
<input type="hidden" name="options[aiwp_hidden]" value="Y"> |
| 1165 |
<?php if ( !$options['token'] ) : ?> |
| 1166 |
<input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Credentials', 'analytics-insights' ) ?>" /> |
| 1167 |
<?php endif; ?> |
| 1168 |
<?php wp_nonce_field('aiwp_form','aiwp_security'); ?> |
| 1169 |
</td> |
| 1170 |
</tr> |
| 1171 |
<?php endif; ?> |
| 1172 |
<?php if ( $options['token'] ) : ?> |
| 1173 |
<tr> |
| 1174 |
<td colspan="2"> |
| 1175 |
<button type="submit" name="Reset" class="button button-secondary"><?php _e( "Clear Authorization", 'analytics-insights' ); ?></button> |
| 1176 |
<button type="submit" name="Clear" class="button button-secondary"><?php _e( "Clear Cache", 'analytics-insights' ); ?></button> |
| 1177 |
<button type="submit" name="Refresh" class="button button-secondary"><?php _e( "Refresh Properties", 'analytics-insights' ); ?></button> |
| 1178 |
</td> |
| 1179 |
</tr> |
| 1180 |
<?php self::html_section_delimiter() ?> |
| 1181 |
<?php self::html_section_delimiter(__( "Properties/Views Settings", 'analytics-insights' ), false) ?> |
| 1182 |
<?php if ( isset( $options['network_webstream'] ) ) : ?> |
| 1183 |
<?php $options['network_webstream'] = json_decode( json_encode( $options['network_webstream'] ), false ); ?> |
| 1184 |
<?php endif; ?> |
| 1185 |
<?php foreach ( AIWP_Tools::get_sites( array( 'number' => apply_filters( 'aiwp_sites_limit', 100 ) ) ) as $blog ) : ?> |
| 1186 |
<tr> |
| 1187 |
<td class="aiwp-settings-title-s"> |
| 1188 |
<label for="network_webstream"><?php echo '<strong>'. esc_html( $blog['domain'] ) . esc_url( $blog['path'] ) .'</strong>: ';?></label> |
| 1189 |
</td> |
| 1190 |
<td> |
| 1191 |
<select id="network_webstreams-<?php echo $blog['blog_id'] ?>" class="network_webstreams" <?php disabled(empty($options['ga4_webstreams_list']) || 1 == count($options['ga4_webstreams_list']), true); ?> name="options[network_webstream][<?php echo esc_attr( $blog['blog_id'] );?>]"> |
| 1192 |
<?php if ( ! empty( $options['ga4_webstreams_list'] ) ) : ?> |
| 1193 |
<?php $temp_id = $blog['blog_id']; ?> |
| 1194 |
<?php foreach ( $options['ga4_webstreams_list'] as $items ) : ?> |
| 1195 |
<?php if ( $items[2] ) : ?> |
| 1196 |
<option value="<?php echo esc_attr( $items[1] ); ?>" <?php selected( $items[1], isset( $options['network_webstream']->$temp_id ) ? $options['network_webstream']->$temp_id : '');?> title="<?php _e( "Stream Name:", 'analytics-insights' ); ?> <?php echo esc_attr( $items[0] ); ?>"> |
| 1197 |
<?php echo esc_html( AIWP_Tools::strip_protocol( $items[2] ) )?> ⇒ <?php echo esc_attr( $items[0] ); ?> |
| 1198 |
</option> |
| 1199 |
<?php endif; ?> |
| 1200 |
<?php endforeach; ?> |
| 1201 |
<?php endif; ?> |
| 1202 |
</select> |
| 1203 |
</td> |
| 1204 |
</tr> |
| 1205 |
<?php endforeach; ?> |
| 1206 |
<?php self::html_section_delimiter(); ?> |
| 1207 |
<?php self::html_switch_button('options[superadmin_tracking]', 1, 'superadmin_tracking', $options['superadmin_tracking'], __( "exclude Super Admin tracking for the entire network", 'analytics-insights'), false, false ); ?> |
| 1208 |
<?php self::html_section_delimiter(); ?> |
| 1209 |
<tr> |
| 1210 |
<td colspan="2" class="submit"> |
| 1211 |
<input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'analytics-insights' ) ?>" /> |
| 1212 |
</td> |
| 1213 |
</tr> |
| 1214 |
<?php else : ?> |
| 1215 |
<?php self::html_section_delimiter(); ?> |
| 1216 |
<tr> |
| 1217 |
<td colspan="2"> |
| 1218 |
<?php $auth = $aiwp->gapi_controller->createAuthUrl();?> |
| 1219 |
<button type="submit" class="button button-secondary" formaction="<?php echo esc_url_raw( $auth ); ?>"><?php _e( "Authorize Plugin", 'analytics-insights' ); ?></button> |
| 1220 |
<button type="submit" name="Clear" class="button button-secondary"><?php _e( "Clear Cache", 'analytics-insights' ); ?></button> |
| 1221 |
</td> |
| 1222 |
</tr> |
| 1223 |
<?php endif; ?> |
| 1224 |
<?php self::html_section_delimiter(); ?> |
| 1225 |
</table> |
| 1226 |
<?php self::html_form_end(); ?> |
| 1227 |
<?php AIWP_Tools::load_view( 'admin/views/settings-sidebar.php', array() ); ?> |
| 1228 |
<?php return; ?> |
| 1229 |
<?php endif;?> |
| 1230 |
</table> |
| 1231 |
<?php self::html_form_end(); ?> |
| 1232 |
<?php |
| 1233 |
AIWP_Tools::load_view( 'admin/views/settings-sidebar.php', array() ); |
| 1234 |
} |
| 1235 |
} |
| 1236 |
|