Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions simple-analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@
$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('Ignore Rules', function (Tab $tab) {
$tab->icon(get_icon('eye-slash'));
Expand All @@ -105,6 +101,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');
Expand Down
72 changes: 62 additions & 10 deletions src/UI/PageLayoutComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

class PageLayoutComponent
{
private const DASHBOARD_URL = 'https://dashboard.simpleanalytics.com/?utm_source=wordpress&utm_medium=plugin&utm_content=go_to_dashboard_button';
private const SIGNUP_URL = 'https://www.simpleanalytics.com/signup?utm_source=wordpress&utm_medium=plugin&utm_content=signup_link';

/**
* @readonly
* @var \SimpleAnalytics\Settings\AdminPage
Expand Down Expand Up @@ -44,7 +47,7 @@ public function __invoke(): void
<div class="flex items-center">
<!-- Logo -->
<a
href="https://dashboard.simpleanalytics.com/websites"
href="<?php echo esc_url(self::DASHBOARD_URL); ?>"
target="_blank"
class="text-base font-semibold leading-6 text-gray-900"
>
Expand All @@ -56,7 +59,7 @@ class="mr-2 inline-block h-10 w-auto text-primary"
</a>
<!-- "Open Dashboard" link -->
<a
href="https://dashboard.simpleanalytics.com/websites"
href="<?php echo esc_url(self::DASHBOARD_URL); ?>"
target="_blank"
class="inline-flex items-center rounded bg-white px-2 py-1 text-xs font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
>
Expand All @@ -75,17 +78,22 @@ class="inline-flex items-center rounded bg-white px-2 py-1 text-xs font-semibold
<!-- Fields / Layout -->
<div class="mx-auto max-w-3xl bg-white px-4 py-6 sm:px-4 lg:px-0">
<div class="border-b border-gray-900/10 pb-7">
<?php if ($currentTab->getSlug() === 'general'): ?>
<?php $this->renderGeneralTabIntro(); ?>
<?php endif; ?>
<?php $currentTab->render(); ?>
</div>

<div class="mt-6 flex items-center justify-start gap-x-6">
<button
type="submit"
class="rounded-md px-3 py-2 text-sm font-semibold text-white shadow-sm bg-primary hover:bg-red-500 focus-visible:outline-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2"
>
Save Changes
</button>
</div>
<?php if ($currentTab->getSlug() !== 'general'): ?>
<div class="mt-6 flex items-center justify-start gap-x-6">
<button
type="submit"
class="rounded-md px-3 py-2 text-sm font-semibold text-white shadow-sm bg-primary hover:bg-red-500 focus-visible:outline-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2"
>
Save Changes
</button>
</div>
<?php endif; ?>
</div>
</form>
<script>
Expand Down Expand Up @@ -140,4 +148,48 @@ protected function findTabBySlug(array $tabs, string $slug): ?Tab

return null;
}

protected function renderGeneralTabIntro(): void
{
?>
<div class="mb-7" style="max-width: 64ch;">
<p class="text-sm text-gray-700">
Simple Analytics is now added to your WordPress site.
</p>
<p class="mt-4 text-sm text-gray-700">
The plugin collects pageviews in a privacy-first way, without cookies or personal data.
</p>
<p class="mt-4 text-sm text-gray-700">
Your stats will appear in
<a class="text-primary hover:underline" target="_blank" href="<?php echo esc_url(self::DASHBOARD_URL); ?>">
the Simple Analytics dashboard
</a>
within a few minutes.
</p>
<p class="mt-4 text-sm text-gray-700">
To avoid tracking your own visits, go to the "Ignore Rules" tab and ignore visits from logged-in admins.
You can also add your own IP address there.
</p>
<p class="mt-4 text-sm text-gray-700">
To automatically track downloads, outbound links, and email clicks, go to the "Events" tab and enable "Collect automated events".
</p>
<p class="mt-4 text-sm text-gray-700">
No account yet? Create one at
<a class="text-primary hover:underline" target="_blank" href="<?php echo esc_url(self::SIGNUP_URL); ?>">
simpleanalytics.com.
</a>
You can start with a free trial and choose a free or paid plan later.
</p>
<p class="mt-6">
<a
href="<?php echo esc_url(self::DASHBOARD_URL); ?>"
target="_blank"
class="inline-flex items-center rounded bg-primary px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-500"
>
Open dashboard
</a>
</p>
</div>
<?php
}
}
27 changes: 24 additions & 3 deletions tests/Browser/pluginSettings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { test, expect, type Page, type Browser } from '@playwright/test';

const DEFAULT_SCRIPT_SELECTOR = 'script[src="https://scripts.simpleanalyticscdn.com/latest.js"]';
const INACTIVE_ADMIN_SCRIPT_SELECTOR = 'script[src*="resources/js/inactive.js"]';
const DASHBOARD_URL =
'https://dashboard.simpleanalytics.com/?utm_source=wordpress&utm_medium=plugin&utm_content=go_to_dashboard_button';
const SIGNUP_URL =
'https://www.simpleanalytics.com/signup?utm_source=wordpress&utm_medium=plugin&utm_content=signup_link';
const SCRIPT_PREFIX_COMMENT = '<!-- Simple Analytics - 100% privacy-first analytics (official WordPress plugin) -->';
const INACTIVE_COMMENT_PREFIX = '<!-- Simple Analytics: Script not included because this visitor is excluded by tracking rule:';
const INACTIVE_USER_ROLE_COMMENT = '<!-- Simple Analytics: Script not included because this visitor is excluded by tracking rule: Exclude User Role -->';
Expand Down Expand Up @@ -39,7 +43,7 @@ async function visitAsGuest(browser: Browser, path = '/'): Promise<Page> {

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);

Expand All @@ -49,6 +53,23 @@ test('adds a script by default', async ({ page, browser }) => {
await guest.context().close();
});

test('shows guidance on general tab and keeps custom domain in advanced tab', async ({ page }) => {
await asAdmin(page);
await page.goto('/wp-admin/options-general.php?page=simpleanalytics&tab=general');

await expect(page.getByText('Simple Analytics is now added to your WordPress site.')).toBeVisible();
await expect(page.getByText('without cookies or personal data')).toBeVisible();
await expect(page.getByRole('link', { name: 'the Simple Analytics dashboard' })).toHaveAttribute('href', DASHBOARD_URL);
await expect(page.getByRole('link', { name: 'simpleanalytics.com.' })).toHaveAttribute('href', SIGNUP_URL);
await expect(page.getByRole('link', { name: 'Open dashboard', exact: true })).toHaveAttribute('href', DASHBOARD_URL);
await expect(page.getByRole('link', { name: 'Open Dashboard', exact: true })).toHaveAttribute('href', DASHBOARD_URL);
await expect(page.getByRole('button', { name: 'Save Changes' })).toHaveCount(0);
await expect(page.locator('[name="simpleanalytics_custom_domain"]')).toHaveCount(0);

await page.goto('/wp-admin/options-general.php?page=simpleanalytics&tab=advanced');
await expect(page.locator('[name="simpleanalytics_custom_domain"]')).toBeVisible();
});

test('adds inactive script for authenticated users by default', async ({ page }) => {
await asAdmin(page);
await page.goto('/wp-admin/options-general.php?page=simpleanalytics&tab=ignore-rules');
Expand Down Expand Up @@ -270,7 +291,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');
Expand All @@ -279,7 +300,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);
});