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.
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(
- __(
- '
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(
+ __(
+ '
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.
',
+ __( '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(); ?>
-
+
render_quick_actions(); ?>
@@ -180,7 +215,7 @@ private function show_wizard() {
?>
slides as $id => $title ): ?>
+ space-y-6 invisible target:opacity-100 target:visible transition-opacity absolute md:min-w-full sm:max-w-full">
@@ -217,13 +252,13 @@ class="plausible-analytics-wizard-next-step no-underline gap-x-2 inline-flex rel
focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 transition-color">
-
+
-
+
diff --git a/src/Admin/Settings/Page.php b/src/Admin/Settings/Page.php
index 1ad9a13e..19385801 100644
--- a/src/Admin/Settings/Page.php
+++ b/src/Admin/Settings/Page.php
@@ -29,6 +29,8 @@ class Page extends API {
* @return void
*/
public function __construct() {
+ $this->init();
+
$settings = Helpers::get_settings();
$domain = Helpers::get_domain();
$self_hosted_domain = defined( 'PLAUSIBLE_SELF_HOSTED_DOMAIN' ) ? PLAUSIBLE_SELF_HOSTED_DOMAIN : $settings[ 'self_hosted_domain' ];
@@ -42,7 +44,7 @@ public function __construct() {
'desc' => sprintf(
wp_kses(
__(
- 'Ensure your domain name matches the one in your Plausible account, then generate the API token (link opens in a new window) and paste it into the \'API token\' field.',
+ 'Ensure your domain name matches the one in your Plausible account, then generate the API token (link opens in a new window) and paste it into the \'API token\' field.',
'plausible-analytics'
),
'post'
@@ -57,10 +59,11 @@ public function __construct() {
'value' => $domain,
],
[
- 'label' => esc_html__( 'API token', 'plausible-analytics' ),
- 'slug' => 'api_token',
- 'type' => 'text',
- 'value' => $settings[ 'api_token' ],
+ 'label' => esc_html__( 'API token', 'plausible-analytics' ),
+ 'slug' => 'api_token',
+ 'type' => 'text',
+ 'value' => $settings[ 'api_token' ],
+ 'disabled' => ! empty( $settings[ 'self_hosted_domain' ] ),
],
[
'label' => esc_html__( 'Connect', 'plausible-analytics' ),
@@ -109,11 +112,12 @@ public function __construct() {
'value' => 'tagged-events',
],
'revenue' => [
- 'label' => esc_html__( 'Ecommerce revenue', 'plausible-analytics' ),
- 'docs' => 'https://plausible.io/wordpress-analytics-plugin#how-to-track-ecommerce-revenue',
- 'slug' => 'enhanced_measurements',
- 'type' => 'checkbox',
- 'value' => 'revenue',
+ 'label' => esc_html__( 'Ecommerce revenue', 'plausible-analytics' ),
+ 'docs' => 'https://plausible.io/wordpress-analytics-plugin#how-to-track-ecommerce-revenue',
+ 'slug' => 'enhanced_measurements',
+ 'type' => 'checkbox',
+ 'value' => 'revenue',
+ 'disabled' => ! empty( $settings[ 'self_hosted_domain' ] ),
],
'pageview-props' => [
'label' => esc_html__( 'Authors and categories', 'plausible-analytics' ),
@@ -184,10 +188,11 @@ public function __construct() {
'toggle' => '',
'fields' => [
[
- 'label' => esc_html__( 'View stats in WordPress', 'plausible-analytics' ),
- 'slug' => 'enable_analytics_dashboard',
- 'type' => 'checkbox',
- 'value' => 'on',
+ 'label' => esc_html__( 'View stats in WordPress', 'plausible-analytics' ),
+ 'slug' => 'enable_analytics_dashboard',
+ 'type' => 'checkbox',
+ 'value' => 'on',
+ 'disabled' => empty( Helpers::get_settings()[ 'api_token' ] ) && empty( Helpers::get_settings()[ 'self_hosted_domain' ] ),
],
],
],
@@ -316,7 +321,7 @@ public function __construct() {
__( 'Paste the shared link in the text box to view your stats in your WordPress dashboard.', 'plausible-analytics' ) .
'' .
'',
- esc_url( 'https://plausible.io/wordpress-analytics-plugin#how-to-view-your-stats-directly-in-your-wordpress-dashboard' )
+ esc_url( 'https://plausible.io/docs/embed-dashboard' )
),
'fields' => [
[
@@ -341,6 +346,28 @@ public function __construct() {
],
];
+ if ( ! empty( $settings[ 'self_hosted_domain' ] ) ) {
+ $option_disabled_hook = [
+ [
+ 'label' => '',
+ 'slug' => 'option_disabled_by_self_hosted_domain',
+ 'type' => 'hook',
+ ],
+ ];
+
+ $fields = $this->fields[ 'general' ][ 0 ][ 'fields' ];
+
+ array_splice( $fields, 2, 0, $option_disabled_hook );
+
+ $this->fields[ 'general' ][ 0 ][ 'fields' ] = $fields;
+
+ $fields = $this->fields[ 'general' ][ 1 ][ 'fields' ];
+
+ array_splice( $fields, 5, 0, $option_disabled_hook );
+
+ $this->fields[ 'general' ][ 1 ][ 'fields' ] = $fields;
+ }
+
if ( Helpers::proxy_enabled() || ! empty( $settings[ 'self_hosted_domain' ] ) ) {
$this->fields[ 'general' ][ 2 ][ 'fields' ][] = [
'label' => '',
@@ -349,6 +376,9 @@ public function __construct() {
];
}
+ /**
+ * If View Stats is enabled, display notice.
+ */
if ( ! empty( $settings[ 'enable_analytics_dashboard' ] ) ) {
$this->fields[ 'general' ][ 3 ][ 'fields' ][] = [
'label' => '',
@@ -358,20 +388,42 @@ public function __construct() {
];
}
+ /**
+ * If proxy is enabled, disable Self-hosted fields and display a warning.
+ */
if ( Helpers::proxy_enabled() ) {
$this->fields[ 'self-hosted' ][ 0 ][ 'fields' ][] = [
'label' => '',
- 'slug' => 'self_hosted_domain_notice',
+ 'slug' => 'option_disabled_by_proxy',
'type' => 'hook',
];
$this->fields[ 'self-hosted' ][ 1 ][ 'fields' ][] = [
'label' => '',
- 'slug' => 'self_hosted_shared_link_notice',
+ 'slug' => 'option_disabled_by_proxy',
'type' => 'hook',
];
}
+ }
- $this->init();
+ /**
+ * Action hooks.
+ * @return void
+ */
+ private function init() {
+ /**
+ * Core hooks
+ */
+ add_action( 'admin_menu', [ $this, 'register_menu' ] );
+ add_action( 'in_admin_header', [ $this, 'add_background_color' ] );
+
+ /**
+ * Plugin hooks
+ */
+ add_action( 'plausible_analytics_settings_api_connect_button', [ $this, 'connect_button' ] );
+ add_action( 'plausible_analytics_settings_option_disabled_by_self_hosted_domain', [ $this, 'option_disabled_by_self_hosted_domain' ] );
+ add_action( 'plausible_analytics_settings_proxy_warning', [ $this, 'proxy_warning' ] );
+ add_action( 'plausible_analytics_settings_enable_analytics_dashboard_notice', [ $this, 'enable_analytics_dashboard_notice' ] );
+ add_action( 'plausible_analytics_settings_option_disabled_by_proxy', [ $this, 'option_disabled_by_proxy' ] );
}
/**
@@ -407,20 +459,6 @@ private function build_user_roles_array( $slug, $disable_elements = [] ) {
return $roles_array;
}
- /**
- * Action hooks.
- * @return void
- */
- private function init() {
- add_action( 'admin_menu', [ $this, 'register_menu' ] );
- add_action( 'in_admin_header', [ $this, 'add_background_color' ] );
- add_action( 'plausible_analytics_settings_api_connect_button', [ $this, 'connect_button' ] );
- add_action( 'plausible_analytics_settings_proxy_warning', [ $this, 'proxy_warning' ] );
- add_action( 'plausible_analytics_settings_enable_analytics_dashboard_notice', [ $this, 'enable_analytics_dashboard_notice' ] );
- add_action( 'plausible_analytics_settings_self_hosted_domain_notice', [ $this, 'self_hosted_warning' ] );
- add_action( 'plausible_analytics_settings_self_hosted_shared_link_notice', [ $this, 'self_hosted_warning' ] );
- }
-
/**
* Register Menu.
* @since 1.0.0
@@ -465,7 +503,7 @@ public function register_menu() {
'plausible_analytics_statistics',
[
$this,
- 'statistics_page',
+ 'render_analytics_dashboard',
]
);
@@ -482,9 +520,13 @@ public function register_menu() {
);
}
+ /**
+ * A little hack to add some classes to the core #wpcontent div.
+ * @return void
+ */
public function add_background_color() {
if ( array_key_exists( 'page', $_GET ) && $_GET[ 'page' ] == 'plausible_analytics' ) {
- echo "";
+ echo "";
}
}
@@ -494,14 +536,14 @@ public function add_background_color() {
* @access public
* @return void
*/
- public function statistics_page() {
+ public function render_analytics_dashboard() {
global $current_user;
- $settings = Helpers::get_settings();
- $domain = Helpers::get_domain();
- $shared_link = $settings[ 'shared_link' ] ?: '';
+ $settings = Helpers::get_settings();
+ $analytics_enabled = $settings[ 'enable_analytics_dashboard' ];
+ $shared_link = $settings[ 'shared_link' ] ?: '';
- if ( $settings[ 'self_hosted_domain' ] && $settings[ 'self_hosted_shared_link' ] ) {
+ if ( $settings[ 'self_hosted_domain' ] ) {
$shared_link = $settings[ 'self_hosted_shared_link' ];
}
@@ -543,7 +585,7 @@ public function statistics_page() {
* those who haven't properly set it up.
* @since v1.2.5
*/
- if ( ! empty( $shared_link ) || strpos( $shared_link, 'XXXXXX' ) !== false ) {
+ if ( ! empty( $analytics_enabled ) && ! empty( $shared_link ) || strpos( $shared_link, 'XXXXXX' ) !== false ) {
$page_url = isset( $_GET[ 'page-url' ] ) ? esc_url( $_GET[ 'page-url' ] ) : '';
// Append individual page URL if it exists.
@@ -566,10 +608,14 @@ public function statistics_page() {
if (iframe === null) {
let div = document.getElementById('plausible-analytics-stats');
- div.innerHTML = '
';
+ // Give iframe a chance to load.
+ setTimeout(
+ div.innerHTML = '
',
+ 1000
+ );
}
});
@@ -578,30 +624,33 @@ public function statistics_page() {
} else {
?>
- %3$s %4$s %5$s %7$s %8$s',
- esc_html( 'Please', 'plausible-analytics' ),
- esc_url_raw( "https://plausible.io/{$domain}/settings/visibility" ),
- esc_html( 'click here', 'plausible-analytics' ),
- esc_html(
- 'to generate your shared link from your Plausible Analytics dashboard. Make sure the link is not password protected.',
- 'plausible-analytics'
- ),
- esc_html( 'Now, copy the generated shared link and', 'plausible-analytics' ),
- admin_url( 'options-general.php?page=plausible_analytics' ),
- esc_html( 'paste here', 'plausible-analytics' ),
- esc_html(
- 'under Shared Link to view Plausible Analytics dashboard within your WordPress site.',
- 'plausible-analytics'
- )
- );
- ?>
+
+
+ Shared Link under Self-Hosted Settings.',
+ 'plausible-analytics'
+ ),
+ admin_url( 'options-general.php?page=plausible_analytics#is_shared_link' ),
+ admin_url( 'options-general.php?page=plausible_analytics&tab=self-hosted' )
+ ); ?>
+
+ click here to enable View Stats in WordPress.', 'plausible-analytics' ),
+ admin_url( 'options-general.php?page=plausible_analytics#is_shared_link' )
+ );
+ ?>
+
+
@@ -618,13 +667,7 @@ public function connect_button() {
*/
public function proxy_warning() {
if ( ! empty( Helpers::get_settings()[ 'self_hosted_domain' ] ) ) {
- echo wp_kses(
- __(
- 'This option is disabled, because the Domain Name setting is enabled under Self-Hosted settings.',
- 'plausible-analytics'
- ),
- 'post'
- );
+ $this->option_disabled_by_self_hosted_domain();
} else {
echo sprintf(
wp_kses(
@@ -639,6 +682,20 @@ public function proxy_warning() {
}
}
+ /**
+ * Show notice when API token notice is disabled.
+ * @return void
+ */
+ public function option_disabled_by_self_hosted_domain() {
+ echo wp_kses(
+ __(
+ 'This option is disabled, because the Domain Name setting is enabled under Self-Hosted settings.',
+ 'plausible-analytics'
+ ),
+ 'post'
+ );
+ }
+
/**
* Renders the analytics dashboard link if the option is enabled.
* @since 2.0.0
@@ -664,7 +721,7 @@ public function enable_analytics_dashboard_notice() {
* @since 1.3.3
* @return void
*/
- public function self_hosted_warning() {
+ public function option_disabled_by_proxy() {
if ( Helpers::proxy_enabled() ) {
echo wp_kses(
__(
diff --git a/src/Plugin.php b/src/Plugin.php
index f3697c09..315c43cf 100644
--- a/src/Plugin.php
+++ b/src/Plugin.php
@@ -40,6 +40,7 @@ public function register_services() {
new Admin\Actions();
new Admin\Module();
new Admin\Provisioning();
+ new Admin\SelfHosted();
}
new Includes\Actions();