diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b87fe31..9de793f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -61,6 +61,15 @@ jobs: - name: Install pnpm dependencies run: pnpm install + - name: Restore Playwright browsers cache + id: playwright-cache + uses: actions/cache/restore@v5 + with: + path: ~/.cache/ms-playwright + key: ${{ runner.os }}-playwright-${{ hashFiles('pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-playwright- + - name: Set WordPress and PHP version override run: | echo '{ @@ -71,8 +80,39 @@ jobs: - name: Start wp-env run: pnpm exec wp-env start - - name: Install Playwright browsers - run: pnpm run tests:install + - name: Verify WordPress login page + run: | + for attempt in {1..10}; do + if curl -fsS http://localhost:8888/wp-login.php | grep -q 'id="user_login"'; then + exit 0 + fi + sleep 3 + done + + curl -fsS http://localhost:8888/wp-login.php || true + exit 1 + + - name: Use Ubuntu archive mirror + run: | + if [ -f /etc/apt/apt-mirrors.txt ]; then + sudo sed -i 's|http://azure.archive.ubuntu.com/ubuntu|http://archive.ubuntu.com/ubuntu|g' /etc/apt/apt-mirrors.txt + fi + if [ -f /etc/apt/sources.list.d/ubuntu.sources ]; then + sudo sed -i 's|http://azure.archive.ubuntu.com/ubuntu|http://archive.ubuntu.com/ubuntu|g' /etc/apt/sources.list.d/ubuntu.sources + fi + sudo apt-get update + + - name: Install Playwright + timeout-minutes: 5 + run: pnpm exec playwright install --with-deps chromium + + - name: Save Playwright browsers cache + if: steps.playwright-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v5 + continue-on-error: true + with: + path: ~/.cache/ms-playwright + key: ${{ runner.os }}-playwright-${{ hashFiles('pnpm-lock.yaml') }} - name: Run Playwright tests run: pnpm exec playwright test diff --git a/simple-analytics.php b/simple-analytics.php index 2e2660b..5a22b62 100644 --- a/simple-analytics.php +++ b/simple-analytics.php @@ -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')); @@ -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'); diff --git a/src/Actions/AddInactiveComment.php b/src/Actions/AddInactiveComment.php index 54135cb..4d91ca2 100644 --- a/src/Actions/AddInactiveComment.php +++ b/src/Actions/AddInactiveComment.php @@ -11,8 +11,24 @@ class AddInactiveComment */ protected $hook = 'wp_footer'; + /** @var string */ + protected $triggeredRule; + + /** + * @param string $triggeredRule + */ + public function __construct(string $triggeredRule = '') + { + $this->triggeredRule = trim($triggeredRule); + } + public function handle(): void { - echo "\n"; + $reason = $this->triggeredRule !== '' ? $this->triggeredRule : 'Unknown Rule'; + + echo sprintf( + "\n", + \esc_html($reason) + ); } } diff --git a/src/Plugin.php b/src/Plugin.php index c195c44..e8ce1ab 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -46,13 +46,16 @@ public function boot(): void public function onInit(): void { - $tracking = ! $this->trackingRules->hasExcludedIp() && ! $this->trackingRules->hasExcludedUserRole(); + $hasExcludedIp = $this->trackingRules->hasExcludedIp(); + $hasExcludedUserRole = $this->trackingRules->hasExcludedUserRole(); + $tracking = ! $hasExcludedIp && ! $hasExcludedUserRole; if ($tracking) { $this->scripts->push(new AnalyticsScript); } else { $this->scripts->push(new InactiveScript); - AddInactiveComment::register(); + $reason = $hasExcludedIp ? 'Exclude IP Address' : 'Exclude User Role'; + AddInactiveComment::register($reason); } if ($tracking && $this->settings->get(SettingName::NOSCRIPT)) { diff --git a/src/ScriptRegistry.php b/src/ScriptRegistry.php index e79099f..7dfe61d 100644 --- a/src/ScriptRegistry.php +++ b/src/ScriptRegistry.php @@ -71,9 +71,19 @@ protected function removeIds(): void protected function removeIdsFilter($tag, $handle): string { foreach ($this->scripts as $script) { - if ($script instanceof HideScriptId && $script->handle() === $handle) { - // Remove the id attribute from the script tag - return preg_replace('/ id=([\'"])[^\'"]*\\1/', '', $tag); + if ($script->handle() === $handle) { + $updatedTag = $tag; + + if ($script instanceof HideScriptId) { + // Remove the id attribute from the script tag + $updatedTag = preg_replace('/ id=([\'"])[^\'"]*\\1/', '', $updatedTag); + } + + if ($handle === 'simpleanalytics') { + return "\n" . $updatedTag; + } + + return $updatedTag; } } diff --git a/src/TrackingRules.php b/src/TrackingRules.php index 02d0505..9e09f84 100644 --- a/src/TrackingRules.php +++ b/src/TrackingRules.php @@ -13,7 +13,7 @@ public function __construct(WordPressSettings $settings) public function hasExcludedIp(): bool { - $ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR']; + $ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? ($_SERVER['REMOTE_ADDR'] ?? null); if (empty($ip)) return false; diff --git a/src/UI/PageLayoutComponent.php b/src/UI/PageLayoutComponent.php index 0a8d81c..586d108 100644 --- a/src/UI/PageLayoutComponent.php +++ b/src/UI/PageLayoutComponent.php @@ -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 @@ -44,7 +47,7 @@ public function __invoke(): void
@@ -56,7 +59,7 @@ class="mr-2 inline-block h-10 w-auto text-primary" @@ -75,17 +78,22 @@ class="inline-flex items-center rounded bg-white px-2 py-1 text-xs font-semibold
+ getSlug() === 'general'): ?> + renderGeneralTabIntro(); ?> + render(); ?>
-
- -
+ getSlug() !== 'general'): ?> +
+ +
+