'',
'slug' => 'option_not_available_in_ce',
'type' => 'hook',
],
];
const PROXY_WARNING_HOOK = [
'label' => '',
'slug' => 'proxy_warning',
'type' => 'hook',
];
const OPTION_DISABLED_BY_PROXY_HOOK = [
'label' => '',
'slug' => 'option_disabled_by_proxy',
'type' => 'hook',
];
const API_TOKEN_MISSING_HOOK = [
'label' => '',
'slug' => 'api_token_missing',
'type' => 'hook',
];
const OPTION_DISABLED_BY_MISSING_API_TOKEN_HOOK = [
'label' => '',
'slug' => 'option_disabled_by_missing_api_token',
'type' => 'hook',
];
const ENABLE_ANALYTICS_DASH_NOTICE = [
'label' => '',
'slug' => 'enable_analytics_dashboard_notice',
'type' => 'hook',
'hook_type' => 'success',
];
/**
* @var array|array[] $fields
*/
public $fields = [];
/**
* @var array $wizard_fields
*/
public $wizard_fields = [];
/**
* Constructor.
* @since 1.3.0
* @access public
* @return void
* @throws Exception
*/
public function __construct() {
$this->init();
$settings = Helpers::get_settings();
$this->fields = [
'general' => [
[
'label' => esc_html__( 'Connect your website with Plausible Analytics', 'plausible-analytics' ),
'slug' => 'connect_to_plausible_analytics',
'type' => 'group',
'desc' => sprintf(
wp_kses(
// translators: %s: URL to Plausible account settings.
__(
'Ensure your domain name matches the one in your Plausible account, then create a Plugin Token (link opens in a new window) and paste it into the \'Plugin Token\' field.',
'plausible-analytics'
),
'post'
),
Helpers::get_hosted_domain_url() . '/sites'
),
'fields' => [
[
'label' => esc_html__( 'Language Domains', 'plausible-analytics' ),
'slug' => 'domain_map',
'type' => 'domain_map',
],
],
],
[
'label' => esc_html__( 'Enhanced measurements', 'plausible-analytics' ),
'slug' => 'enhanced_measurements',
'type' => 'group',
'divide' => true,
// translators: %1$s replaced with outbound-links.
'desc' => esc_html__(
'Enable enhanced measurements that you\'d like to track.',
'plausible-analytics'
),
'fields' => [
EnhancedMeasurements::FOUR_O_FOUR => [
'label' => esc_html__( '404 error pages', 'plausible-analytics' ),
'docs' => 'https://plausible.io/docs/wordpress-integration#404-error-pages',
'slug' => 'enhanced_measurements',
'type' => 'checkbox',
'value' => EnhancedMeasurements::FOUR_O_FOUR,
'caps' => [ Capabilities::GOALS ],
],
EnhancedMeasurements::FILE_DOWNLOADS => [
'label' => esc_html__( 'File downloads', 'plausible-analytics' ),
'docs' => 'https://plausible.io/docs/wordpress-integration#file-downloads',
'slug' => 'enhanced_measurements',
'type' => 'checkbox',
'value' => EnhancedMeasurements::FILE_DOWNLOADS,
'caps' => [ Capabilities::GOALS ],
],
EnhancedMeasurements::OUTBOUND_LINKS => [
'label' => esc_html__( 'Outbound links', 'plausible-analytics' ),
'docs' => 'https://plausible.io/docs/wordpress-integration#outbound-links',
'slug' => 'enhanced_measurements',
'type' => 'checkbox',
'value' => EnhancedMeasurements::OUTBOUND_LINKS,
'caps' => [ Capabilities::GOALS ],
],
EnhancedMeasurements::PAGEVIEW_PROPS => [
'label' => esc_html__( 'Authors and categories', 'plausible-analytics' ),
'docs' => 'https://plausible.io/docs/wordpress-integration#authors-and-categories',
'slug' => 'enhanced_measurements',
'type' => 'checkbox',
'value' => EnhancedMeasurements::PAGEVIEW_PROPS,
'caps' => [ Capabilities::PROPS ],
],
EnhancedMeasurements::ECOMMERCE_REVENUE => [
'label' => esc_html__( 'Ecommerce revenue', 'plausible-analytics' ),
'docs' => 'https://plausible.io/docs/wordpress-integration#track-ecommerce-revenue',
'slug' => 'enhanced_measurements',
'type' => 'checkbox',
'value' => EnhancedMeasurements::ECOMMERCE_REVENUE,
'caps' => [
Capabilities::GOALS,
Capabilities::FUNNELS,
Capabilities::PROPS,
Capabilities::REVENUE,
],
'disabled' => ! empty( $settings['self_hosted_domain'] ),
'disabled_tooltip' => self::OPTION_NOT_AVAILABLE_IN_CE_HOOK,
],
EnhancedMeasurements::FORM_COMPLETIONS => [
'label' => esc_html__( 'Form completions', 'plausible-analytics' ),
'docs' => 'https://plausible.io/docs/wordpress-integration#form-completions',
'slug' => 'enhanced_measurements',
'type' => 'checkbox',
'value' => EnhancedMeasurements::FORM_COMPLETIONS,
'caps' => [ Capabilities::GOALS ],
],
EnhancedMeasurements::LOGGED_IN_USER_STATUS => [
'label' => esc_html__( 'Logged-in user status', 'plausible-analytics' ),
'docs' => 'https://plausible.io/docs/wordpress-integration#logged-in-user-status',
'slug' => 'enhanced_measurements',
'type' => 'checkbox',
'value' => EnhancedMeasurements::LOGGED_IN_USER_STATUS,
'caps' => [ Capabilities::PROPS ],
],
EnhancedMeasurements::SEARCH_QUERIES => [
'label' => esc_html__( 'Search queries', 'plausible-analytics' ),
'docs' => 'https://plausible.io/docs/wordpress-integration#search-queries',
'slug' => 'enhanced_measurements',
'type' => 'checkbox',
'value' => EnhancedMeasurements::SEARCH_QUERIES,
'caps' => [ Capabilities::GOALS ],
],
EnhancedMeasurements::HASH_BASED_ROUTING => [
'label' => esc_html__( 'Hash-based routing', 'plausible-analytics' ),
'docs' => 'https://plausible.io/docs/wordpress-integration#hash-based-routing',
'slug' => 'enhanced_measurements',
'type' => 'checkbox',
'value' => EnhancedMeasurements::HASH_BASED_ROUTING,
'caps' => [],
],
],
],
[
'label' => esc_html__( 'Cloaked affiliate links', 'plausible-analytics' ),
'slug' => 'cloaked_affiliate_links',
'type' => 'group',
'docs' => 'https://plausible.io/docs/wordpress-integration#cloaked-affiliate-links',
'desc' => sprintf(
// translators: %s: Example URL to affiliate product.
__(
'Enter the (partial) URLs you\'d like to track. E.g. enter /recommends/ if you want to track %s.',
'plausible-analytics'
),
get_home_url() . '/recommends/affiliate-product/'
),
'fields' => [
[
'slug' => 'affiliate_links',
'type' => 'clonable_text',
'value' => Helpers::get_settings()['affiliate_links'] ?? [],
],
],
],
[
'label' => esc_html__( 'Query parameters', 'plausible-analytics' ),
'slug' => 'query_params',
'type' => 'group',
'docs' => 'https://plausible.io/docs/wordpress-integration#query-parameters',
'desc' => sprintf(
// translators: %s: Example URL with query parameter.
__(
'Enter the query parameters you\'d like to track. E.g., enter lang if you want to track %s.',
'plausible-analytics'
),
get_home_url() . '?lang=en'
),
'fields' => [
[
'slug' => 'query_params',
'type' => 'clonable_text',
'value' => Helpers::get_settings()['query_params'] ?? [],
],
],
],
[
'label' => esc_html__( 'Bypass ad blockers', 'plausible-analytics' ),
'slug' => 'bypass_ad_blockers',
'type' => 'group',
'desc' => sprintf(
wp_kses(
// translators: 1: Proxy endpoint prefix, 2: Proxy endpoint details, 3: URL to learn more about proxy.
__(
'Concerned about ad blockers? You can run the Plausible script as a first-party connection from your domain name to count visitors who use ad blockers. The proxy uses WordPress\' API with a randomly generated endpoint, starting with %1$s and %2$s. Learn more »',
'plausible-analytics'
),
wp_kses_allowed_html( 'post' )
),
get_site_url( null, rest_get_url_prefix() ),
empty(
Helpers::get_settings()['proxy_enabled']
) ? 'a random directory/file for storing the JS file' : 'a JS file, called ' . str_replace(
ABSPATH,
'',
Helpers::get_proxy_resource( 'cache_dir' ) . Helpers::get_filename() . '.js'
),
'https://plausible.io/docs/wordpress-integration#bypass-adblockers-with-the-proxy'
),
'fields' => [
[
'label' => esc_html__( 'Enable proxy', 'plausible-analytics' ),
'slug' => 'proxy_enabled',
'type' => 'checkbox',
'value' => 'on',
'disabled' => ! empty( Helpers::get_settings()['self_hosted_domain'] ),
'disabled_tooltip' => self::OPTION_NOT_AVAILABLE_IN_CE_HOOK,
],
],
],
[
'label' => esc_html__( 'View your stats in your WordPress dashboard', 'plausible-analytics' ),
'slug' => 'is_shared_link',
'type' => 'group',
'docs' => 'https://plausible.io/docs/wordpress-integration#view-your-stats-inside-wordpress',
'desc' => esc_html__(
'View your site statistics within your WordPress Dashboard.',
'plausible-analytics'
),
'fields' => [
[
'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'] ),
],
],
],
[
'label' => esc_html__( 'Exclude specific pages from being tracked', 'plausible-analytics' ),
'slug' => 'is_exclude_pages',
'type' => 'group',
'desc' => sprintf(
'%1$s %3$s',
esc_html__(
'Exclude certain pages from being tracked. You can use an asterisk (*) to match patterns in your page URLs.',
'plausible-analytics'
),
esc_url(
'https://plausible.io/docs/wordpress-integration#exclude-specific-pages-from-tracking'
),
esc_html__( 'See syntax »', 'plausible-analytics' )
),
'fields' => [
[
'label' => esc_html__( 'Excluded pages', 'plausible-analytics' ),
'slug' => 'excluded_pages',
'type' => 'textarea',
'value' => $settings['excluded_pages'],
'placeholder' => esc_html__(
'E.g.',
'plausible-analytics'
) . '/example-page/, *keyword*, /directory*',
],
[
'label' => __( 'Save', 'plausible-analytics' ),
'slug' => 'save-excluded-pages',
'type' => 'button',
],
],
],
[
'label' => esc_html__( 'Track analytics for user roles', 'plausible-analytics' ),
'slug' => 'tracked_user_roles',
'type' => 'group',
'docs' => 'https://plausible.io/docs/wordpress-integration#exclude-admins-and-other-roles',
'desc' => esc_html__(
'By default, visits from logged in users aren\'t tracked. If you want to track visits for certain user roles then please specify them below.',
'plausible-analytics'
),
'fields' => $this->build_user_roles_array( 'tracked_user_roles' ),
'divide' => true,
],
[
'label' => esc_html__( 'Show stats dashboard to additional user roles', 'plausible-analytics' ),
'slug' => 'expand_dashboard_access',
'type' => 'group',
'docs' => 'https://plausible.io/docs/wordpress-integration#view-your-stats-inside-wordpress',
'desc' => esc_html__(
'By default, the stats dashboard is only available to logged in administrators. If you want the dashboard to be available for other logged in users, then please specify them below.',
'plausible-analytics'
),
'fields' => $this->build_user_roles_array( 'expand_dashboard_access', [ 'administrator' => true ] ),
'divide' => true,
],
[
'label' => esc_html__( 'Disable menu in toolbar', 'plausible-analytics' ),
'slug' => 'disable_toolbar_menu',
'type' => 'group',
'docs' => 'https://plausible.io/docs/wordpress-integration#disable-the-toolbar-menu',
'desc' => esc_html__(
'Check this option if you don\'t want the Plausible Analytics menu item to be added to the toolbar at the top of the screen.',
'plausible-analytics'
),
'add_sub_array' => false,
'fields' => [
'disable_toolbar_menu' => [
'label' => esc_html__( 'Disable toolbar menu', 'plausible-analytics' ),
'slug' => 'disable_toolbar_menu',
'type' => 'checkbox',
'value' => 'on',
],
],
],
],
'self-hosted' => [
[
'label' => esc_html__( 'Plausible Community Edition', 'plausible-analytics' ),
'slug' => 'is_self_hosted',
'type' => 'group',
'desc' => sprintf(
'%1$s %3$s',
wp_kses(
__(
'If you\'re using Plausible Community Edition on your own infrastructure, enter the domain name where you installed it to enable the integration with your self-hosted instance. Multisites can use the PLAUSIBLE_SELF_HOSTED_DOMAIN constant to define the URL for all subsites at once.',
'plausible-analytics'
),
'post'
),
esc_url( 'https://plausible.io/self-hosted-web-analytics/' ),
esc_html__( 'Learn more about Plausible Community Edition.', 'plausible-analytics' )
),
'fields' => [
[
'label' => esc_html__( 'Domain name', 'plausible-analytics' ),
'slug' => 'self_hosted_domain',
'type' => 'text',
'value' => defined( 'PLAUSIBLE_SELF_HOSTED_DOMAIN' ) ? PLAUSIBLE_SELF_HOSTED_DOMAIN : $settings['self_hosted_domain'],
'placeholder' => 'e.g. ' . Helpers::get_domain(),
'disabled' => Helpers::proxy_enabled(),
],
[
'label' => __( 'Save', 'plausible-analytics' ),
'slug' => 'save-self-hosted',
'type' => 'button',
'disabled' => Helpers::proxy_enabled(),
],
],
],
[
'label' => esc_html__( 'View stats in your WordPress dashboard', 'plausible-analytics' ),
'slug' => 'self_hosted_shared_link',
'type' => 'group',
'desc' => sprintf(
// translators: %s: URL to Plausible shared link documentation.
'
Shared Link under Self-Hosted Settings.', 'plausible-analytics' ), 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' ) ); ?>