From cac2ac49e556829c171fed4c30b809a6bf6fb3fe Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Fri, 2 Feb 2024 12:28:33 +0100 Subject: [PATCH] Several bugfixes, typo's and UX improvements. --- assets/src/js/admin/main.js | 2 +- src/Admin/SelfHosted.php | 46 +++++++++ src/Admin/Settings/API.php | 131 +++++++++++++++--------- src/Admin/Settings/Page.php | 199 +++++++++++++++++++++++------------- src/Plugin.php | 1 + 5 files changed, 259 insertions(+), 120 deletions(-) create mode 100644 src/Admin/SelfHosted.php diff --git a/assets/src/js/admin/main.js b/assets/src/js/admin/main.js index 67509c5f..899cf631 100644 --- a/assets/src/js/admin/main.js +++ b/assets/src/js/admin/main.js @@ -207,7 +207,7 @@ document.addEventListener('DOMContentLoaded', () => { data.append('options', JSON.stringify(options)); data.append('_nonce', plausible.nonce); - plausible.ajax(data, null, false); + plausible.ajax(data, null, false, true); } }, diff --git a/src/Admin/SelfHosted.php b/src/Admin/SelfHosted.php new file mode 100644 index 00000000..10bde5e7 --- /dev/null +++ b/src/Admin/SelfHosted.php @@ -0,0 +1,46 @@ +init(); + } + + /** + * Action and filter hooks. + * @return void + */ + private function init() { + add_filter( 'pre_update_option_plausible_analytics_settings', [ $this, 'maybe_remove_api_token' ], 10 ); + } + + /** + * @param $settings + * + * @return void + */ + public function maybe_remove_api_token( $settings ) { + if ( empty( $settings[ 'self_hosted_domain' ] ) ) { + return $settings; + } + + $settings[ 'api_token' ] = ''; + + return $settings; + } +} diff --git a/src/Admin/Settings/API.php b/src/Admin/Settings/API.php index b262d679..a9123da3 100644 --- a/src/Admin/Settings/API.php +++ b/src/Admin/Settings/API.php @@ -48,58 +48,93 @@ class API { public function settings_page() { wp_nonce_field( 'plausible_analytics_toggle_option' ); - $followed_wizard = get_option( 'plausible_analytics_wizard_done' ) || ! empty( Helpers::get_settings()[ 'self_hosted_domain' ] ); - $this->slides = [ - 'welcome' => __( 'Welcome to Plausible Analytics', 'plausible-analytics' ), - 'domain_name' => __( 'Confirm domain', 'plausible-analytics' ), - 'api_token' => __( 'Create API token', 'plausible-analytics' ), - 'enable_analytics_dashboard' => __( 'View the stats in your WP dashboard', 'plausible-analytics' ), - 'enhanced_measurements' => __( 'Enhanced measurements', 'plausible-analytics' ), - 'proxy_enabled' => __( 'Enable proxy', 'plausible-analytics' ), - 'success' => __( 'Success!', 'plausible-analytics' ), - ]; - $this->slides_description = [ - 'welcome' => sprintf( - __( - '

Plausible Analytics is an easy to use, open source, lightweight (< 1 KB) and privacy-friendly alternative to Google Analytics. We\'re super excited to have you on board!

To use our plugin, you need to register an account. To explore the product, we offer you a free 30-day trial. No credit card is required to sign up for the trial.

Have an account? Please do follow the following steps to get the most out of your Plausible experience.

', + $settings = Helpers::get_settings(); + $followed_wizard = get_option( 'plausible_analytics_wizard_done' ) || ! empty( $settings[ 'self_hosted_domain' ] ); + + /** + * On-boarding wizard. + */ + if ( ! $followed_wizard ) { + $this->slides = [ + 'welcome' => __( 'Welcome to Plausible Analytics', 'plausible-analytics' ), + 'domain_name' => __( 'Confirm domain', 'plausible-analytics' ), + 'api_token' => __( 'Create API token', 'plausible-analytics' ), + 'enable_analytics_dashboard' => __( 'View the stats in your WP dashboard', 'plausible-analytics' ), + 'enhanced_measurements' => __( 'Enhanced measurements', 'plausible-analytics' ), + 'proxy_enabled' => __( 'Enable proxy', 'plausible-analytics' ), + 'success' => __( 'Success!', 'plausible-analytics' ), + ]; + $this->slides_description = [ + 'welcome' => sprintf( + __( + '

Plausible Analytics is an easy to use, open source, lightweight (< 1 KB) and privacy-friendly alternative to Google Analytics. We\'re super excited to have you on board!

To use our plugin, you need to register an account. To explore the product, we offer you a free 30-day trial. No credit card is required to sign up for the trial.

Already have an account? Please do follow the following steps to get the most out of your Plausible experience.

', + 'plausible-analytics' + ), + 'https://plausible.io/?utm_source=WordPress&utm_medium=Referral&utm_campaign=WordPress+plugin', + 'https://plausible.io/register?utm_source=WordPress&utm_medium=Referral&utm_campaign=WordPress+plugin' + ), + 'domain_name' => __( + 'Confirm your domain name as you\'ve added it to your Plausible account.', 'plausible-analytics' ), - 'https://plausible.io/?utm_source=WordPress&utm_medium=Referral&utm_campaign=WordPress+plugin', - 'https://plausible.io/register?utm_source=WordPress&utm_medium=Referral&utm_campaign=WordPress+plugin' - ), - 'domain_name' => __( 'Confirm your domain name as you\'ve added it to your Plausible account.', 'plausible-analytics' ), - 'api_token' => __( - 'Create the API token (link opens in a new window) that we\'ll use to automate the remaining setup process. Paste the API token in the field below and click "Next".', - 'plausible-analytics' - ), - 'enable_analytics_dashboard' => __( - 'Would you like to view your site\'s stats right here in your WordPress dashboard?', - 'plausible-analytics' - ), - 'enhanced_measurements' => __( 'Enable enhanced measurements', 'plausible-analytics' ), - 'proxy_enabled' => __( - 'Run our scripts as a 1st party connection from your domain name to count visitors who use adblockers', - 'plausible-analytics' - ), - 'success' => sprintf( - __( - '

Congrats! Your traffic is now being counted without compromising the user experience and privacy of your visitors. You can now check out your intuitive, fast-loading and privacy-friendly dashboard.

Note that visits from logged in users aren\'t tracked. If you want to track visits for certain user roles, then please specify them here.

Need help? Our documentation is the best place to find most answers right away.

Still haven\'t found the answer you\'re looking for? We\'re here to help. Please contact our support.

', + 'api_token' => __( + 'Create the API token (link opens in a new window) that we\'ll use to automate your setup process. Paste the API token in the field below and click "Next".', 'plausible-analytics' ), - 'https://plausible.io', - wp_create_nonce( 'plausible_analytics_quit_wizard' ), - admin_url( 'options-general.php?page=plausible_analytics#tracked_user_roles' ), - 'https://plausible.io/docs?utm_source=WordPress&utm_medium=Referral&utm_campaign=WordPress+plugin', - 'https://plausible.io/contact?utm_source=WordPress&utm_medium=Referral&utm_campaign=WordPress+plugin' - ), - ]; + 'enable_analytics_dashboard' => __( + 'Would you like to view your site\'s stats in your WordPress dashboard?', + 'plausible-analytics' + ), + 'enhanced_measurements' => __( 'Enable enhanced measurements', 'plausible-analytics' ), + 'proxy_enabled' => __( + 'Run our script as a first party connection from your domain name to count visitors who use ad blockers', + 'plausible-analytics' + ), + 'success' => sprintf( + __( + '

Congrats! Your traffic is now being counted without compromising the user experience and privacy of your visitors. You can now check out your intuitive, fast-loading and privacy-friendly dashboard.

Note that visits from logged in users aren\'t tracked. If you want to track visits for certain user roles, then please specify them in the plugin\'s settings.

Need help? Our documentation is the best place to find most answers right away.

Still haven\'t found the answer you\'re looking for? We\'re here to help. Please contact our support.

', + 'plausible-analytics' + ), + 'https://plausible.io', + wp_create_nonce( 'plausible_analytics_quit_wizard' ), + admin_url( 'options-general.php?page=plausible_analytics#tracked_user_roles' ), + 'https://plausible.io/docs?utm_source=WordPress&utm_medium=Referral&utm_campaign=WordPress+plugin', + 'https://plausible.io/contact?utm_source=WordPress&utm_medium=Referral&utm_campaign=WordPress+plugin' + ), + ]; + + if ( ! empty( $settings ) ) { + $this->slides_description[ 'welcome' ] = sprintf( + '

%s

%s

%s

%s

%s

%s

', + __( 'Thanks for using the Plausible Analytics WordPress plugin!', 'plausible-analytics' ), + __( + 'We’ve put a lot of effort into this new release. The experience will now be much more familiar to the experience you’re used to on our website.', + 'plausible-analytics' + ), + __( + 'Plus, our brand new API eliminates many tasks that previously had to be done manually!', + 'plausible-analytics' + ), + __( + 'For instance, after inserting the API token, enable the new Authors and categories tracking and it will be displayed in your stats immediately without you needing to add those properties manually in your site settings.', + 'plausible-analytics' + ), + __( + 'This welcome screen will guide you through the process of creating the API token and introduce you to other new features we\'ve added, e.g. Revenue tracking. Click on the “Next” button below to start.', + 'plausible-analytics' + ), + __( 'We hope you’ll find this useful. Thanks again for using Plausible!', 'plausible-analytics' ), + ); + } - if ( ! $followed_wizard ) { $this->show_wizard(); return; } + /** + * Settings screen + */ $current_tab = ! empty( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general'; ?>
@@ -118,7 +153,7 @@ public function settings_page() { render_navigation(); ?>
-
+ @@ -180,7 +215,7 @@ private function show_wizard() { ?> slides as $id => $title ): ?>