diff --git a/simple-analytics.php b/simple-analytics.php index 2e2660b..375969b 100644 --- a/simple-analytics.php +++ b/simple-analytics.php @@ -60,6 +60,7 @@ require __DIR__ . '/src/Settings/Blocks/Fields/Checkboxes.php'; require __DIR__ . '/src/Settings/Blocks/Fields/Checkbox.php'; require __DIR__ . '/src/Settings/Blocks/Fields/IpList.php'; +require __DIR__ . '/src/Settings/Blocks/IntroBlock.php'; require __DIR__ . '/src/Settings/Tab.php'; require __DIR__ . '/src/UI/LabelComponent.php'; require __DIR__ . '/src/UI/TabListComponent.php'; @@ -77,10 +78,17 @@ $adminPage = SimpleAnalytics\Settings\AdminPage::title('Simple Analytics') ->slug('simpleanalytics') ->tab('General', function (Tab $tab) { - $tab->input(SettingName::CUSTOM_DOMAIN, 'Custom Domain') - ->placeholder('Enter your custom domain or leave it empty.') - ->description('E.g. api.example.com. Leave empty to use the default domain (most users).') - ->docs('https://docs.simpleanalytics.com/bypass-ad-blockers'); + $tab->title('Thanks for choosing Simple Analytics.'); + $tab->intro([ + 'This plugin adds Simple Analytics to your WordPress site and collects pageviews in a privacy-first way. Your stats appear in your dashboard within minutes.', + 'To exclude your own visits, open the "Ignore Rules" tab and enable the option for logged-in admins. You can also add your own IP there.', + 'Want automated events, like downloads, outbound link clicks, and email clicks, collected for you? Check "Collect automated events" in the "Events" tab.', + 'No account yet? Sign up at simpleanalytics.com. The trial includes almost all features, then you can choose a free or paid plan.', + ]); + $tab->cta( + 'Visit your analytics dashboard', + 'https://dashboard.simpleanalytics.com?utm_source=wordpress&utm_medium=plugin&utm_content=go_to_dashboard_button' + ); }) ->tab('Ignore Rules', function (Tab $tab) { $tab->icon(get_icon('eye-slash')); @@ -105,6 +113,11 @@ ->tab('Advanced', function (Tab $tab) { $tab->icon(get_icon('cog')); + $tab->input(SettingName::CUSTOM_DOMAIN, 'Custom Domain') + ->placeholder('Enter your custom domain or leave it empty.') + ->description('E.g. api.example.com. Leave empty to use the default domain (most users).') + ->docs('https://docs.simpleanalytics.com/bypass-ad-blockers'); + $tab->checkbox(SettingName::COLLECT_DNT, 'Collect Do Not Track') ->description('If you want to collect visitors with Do Not Track enabled, turn this on.') ->docs('https://docs.simpleanalytics.com/dnt'); diff --git a/src/Settings/Blocks/IntroBlock.php b/src/Settings/Blocks/IntroBlock.php new file mode 100644 index 0000000..118c6e1 --- /dev/null +++ b/src/Settings/Blocks/IntroBlock.php @@ -0,0 +1,29 @@ +paragraphs = $paragraphs; + } + + public function render(): void + { + $allowed = ['strong' => [], 'em' => [], 'a' => ['href' => [], 'target' => [], 'rel' => []]]; + ?> +
+ paragraphs as $paragraph): ?> +

+ +
+ addBlock($block); + return $block; + } + public function callout(string $text): CalloutBlock { $block = new CalloutBlock($text); diff --git a/src/Settings/Tab.php b/src/Settings/Tab.php index 04a1d15..1f0b05f 100644 --- a/src/Settings/Tab.php +++ b/src/Settings/Tab.php @@ -2,6 +2,7 @@ namespace SimpleAnalytics\Settings; +use SimpleAnalytics\Settings\Blocks\Fields\Field; use SimpleAnalytics\Support\SvgIcon; class Tab @@ -31,6 +32,16 @@ class Tab */ protected $title; + /** + * @var string|null + */ + protected $ctaLabel; + + /** + * @var string|null + */ + protected $ctaUrl; + /** @var Block[] */ protected $blocks = []; @@ -69,6 +80,24 @@ public function title(string $title): self return $this; } + public function cta(string $label, string $url): self + { + $this->ctaLabel = $label; + $this->ctaUrl = $url; + + return $this; + } + + public function getCtaLabel(): ?string + { + return $this->ctaLabel; + } + + public function getCtaUrl(): ?string + { + return $this->ctaUrl; + } + protected function addBlock(Block $block): self { $this->blocks[] = $block; @@ -80,6 +109,16 @@ public function getBlocks(): array return $this->blocks; } + public function hasFields(): bool + { + foreach ($this->blocks as $block) { + if ($block instanceof Field) { + return true; + } + } + return false; + } + public function render(): void { ?> @@ -87,7 +126,7 @@ public function render(): void title) || isset($this->description)): ?>
title)): ?> -

+

title); ?> docs)): ?> - + hasFields()): ?> + + getCtaLabel() && $currentTab->getCtaUrl()): ?> + + getCtaLabel()); ?> + +

diff --git a/tests/Browser/pluginSettings.spec.ts b/tests/Browser/pluginSettings.spec.ts index 0d296d3..4715ebd 100644 --- a/tests/Browser/pluginSettings.spec.ts +++ b/tests/Browser/pluginSettings.spec.ts @@ -36,7 +36,7 @@ async function visitAsGuest(browser: Browser, path = '/'): Promise { test('adds a script by default', async ({ page, browser }) => { await asAdmin(page); - await page.goto('/wp-admin/options-general.php?page=simpleanalytics&tab=general'); + await page.goto('/wp-admin/options-general.php?page=simpleanalytics&tab=advanced'); await page.fill('[name="simpleanalytics_custom_domain"]', ''); await saveSettings(page); @@ -244,7 +244,7 @@ test('adds automated events script with override global', async ({ page, browser test('adds a script with a custom domain name', async ({ page, browser }) => { await asAdmin(page); - await page.goto('/wp-admin/options-general.php?page=simpleanalytics&tab=general'); + await page.goto('/wp-admin/options-general.php?page=simpleanalytics&tab=advanced'); await page.fill('[name="simpleanalytics_custom_domain"]', 'mydomain.com'); await saveSettings(page); await expect(page.locator('[name="simpleanalytics_custom_domain"]')).toHaveValue('mydomain.com'); @@ -253,7 +253,7 @@ test('adds a script with a custom domain name', async ({ page, browser }) => { await expect(guest.locator('script[src="https://mydomain.com/latest.js"]')).toBeAttached(); await guest.context().close(); - await page.goto('/wp-admin/options-general.php?page=simpleanalytics&tab=general'); + await page.goto('/wp-admin/options-general.php?page=simpleanalytics&tab=advanced'); await page.fill('[name="simpleanalytics_custom_domain"]', ''); await saveSettings(page); });