Skip to content
Open
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
18 changes: 18 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,21 @@ composer.lock
package.json
pnpm-lock.yaml
release.sh

/tests
/scripts
/bin
/test-results
/playwright-report
/blob-report
Caddyfile
rector.php
.wp-env*.json
playwright.config.*
tailwind.config.*
pnpm-workspace.yaml
.editorconfig
.prettierrc.json
README.md
AGENTS.md
CLAUDE.md
58 changes: 37 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
name: Release

on:
schedule:
- cron: "0 8 * * 1" # At 08:00 on Monday.
workflow_dispatch: # Allows manual triggering
workflow_dispatch: # Releases require an explicit manual trigger on main.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the weekly run: every Monday it tests new WordPress versions and releases when anything changed. This restores only the trigger and keeps this PR's pinned actions, permissions and concurrency.

Suggested change
workflow_dispatch: # Releases require an explicit manual trigger on main.
schedule:
- cron: "0 8 * * 1" # At 08:00 on Monday: test new WordPress versions and release when anything changed.
workflow_dispatch: # Allows manual triggering


concurrency:
group: wordpress-release
cancel-in-progress: false

permissions:
contents: read

jobs:
e2e:
uses: ./.github/workflows/tests.yml

update:
name: Update version
if: github.ref == 'refs/heads/main'
needs: e2e
runs-on: ubuntu-latest
timeout-minutes: 10
Expand All @@ -20,7 +26,7 @@ jobs:
steps:
- name: Create release app token
id: release-app
uses: actions/create-github-app-token@v3
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3
with:
client-id: ${{ vars.RELEASE_APP_CLIENT_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
Expand All @@ -30,40 +36,42 @@ jobs:
id: release-app-user
env:
GH_TOKEN: ${{ steps.release-app.outputs.token }}
run: echo "user-id=$(gh api "/users/${{ steps.release-app.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
APP_SLUG: ${{ steps.release-app.outputs.app-slug }}
run: echo "user-id=$(gh api "/users/${APP_SLUG}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"

- name: Check out repository
uses: actions/checkout@v6
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
token: ${{ steps.release-app.outputs.token }}
persist-credentials: true # Required to push the release commit as the app
fetch-depth: 0 # Fetch all history so we can access tags and commits
fetch-tags: true # Ensure tags are fetched

- name: Install pnpm
uses: pnpm/action-setup@v5
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5
with:
version: 10

- name: Install Node.js LTS
uses: actions/setup-node@v6
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: lts/*
cache: "pnpm"

- name: Install dependencies
run: pnpm install
run: pnpm install --frozen-lockfile

- name: Build assets
run: pnpm build

- name: Install PHP
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
with:
php-version: "latest"
tools: composer:v2

- name: Install Composer
uses: ramsey/composer-install@v4
- name: Install Composer dependencies
run: composer install --no-interaction --prefer-dist --no-progress

- name: Downgrade PHP code to the minimum version WordPress requires
run: vendor/bin/rector --ansi
Expand All @@ -83,18 +91,23 @@ jobs:

- name: Commit and push changes
if: steps.script.outputs.has-changed == 'true'
env:
RELEASE_NAME: ${{ steps.script.outputs.release-name }}
RELEASE_REF: ${{ github.ref_name }}
APP_SLUG: ${{ steps.release-app.outputs.app-slug }}
APP_USER_ID: ${{ steps.release-app-user.outputs.user-id }}
run: |
git config user.name "${{ steps.release-app.outputs.app-slug }}[bot]"
git config user.email "${{ steps.release-app-user.outputs.user-id }}+${{ steps.release-app.outputs.app-slug }}[bot]@users.noreply.github.com"
git config user.name "${APP_SLUG}[bot]"
git config user.email "${APP_USER_ID}+${APP_SLUG}[bot]@users.noreply.github.com"
git add .
git commit -m "${{ steps.script.outputs.release-name }}"
# Push changes, handling potential conflicts
git push || git pull --rebase origin ${{ github.ref_name }} && git push
git commit -m "$RELEASE_NAME"
# Stop if main changed instead of deploying an untested rebase.
git push origin "HEAD:$RELEASE_REF"

- name: WordPress Plugin Deploy
if: steps.script.outputs.has-changed == 'true'
id: deploy
uses: 10up/action-wordpress-plugin-deploy@2.3.0
uses: 10up/action-wordpress-plugin-deploy@54bd289b8525fd23a5c365ec369185f2966529c2 # 2.3.0
with:
generate-zip: true
env:
Expand All @@ -107,13 +120,16 @@ jobs:
- name: Name release zip like repository
if: steps.script.outputs.has-changed == 'true'
id: release_zip
env:
ZIP_PATH: ${{ steps.deploy.outputs.zip-path }}
REPOSITORY_NAME: ${{ github.event.repository.name }}
run: |
cp "${{ steps.deploy.outputs.zip-path }}" "${{ github.workspace }}/${{ github.event.repository.name }}.zip"
echo "path=${{ github.workspace }}/${{ github.event.repository.name }}.zip" >> "$GITHUB_OUTPUT"
cp -- "$ZIP_PATH" "$GITHUB_WORKSPACE/$REPOSITORY_NAME.zip"
echo "path=$GITHUB_WORKSPACE/$REPOSITORY_NAME.zip" >> "$GITHUB_OUTPUT"

- name: Create GitHub release
if: steps.script.outputs.has-changed == 'true'
uses: softprops/action-gh-release@v3
uses: softprops/action-gh-release@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3
with:
tag_name: ${{ steps.script.outputs.stable-tag }}
name: ${{ steps.script.outputs.release-name }}
Expand Down
19 changes: 11 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
prepare-matrix:
name: Prepare test matrix
Expand All @@ -19,7 +22,7 @@ jobs:
matrix: ${{ steps.build-matrix.outputs.matrix }}
steps:
- name: Checkout plugin
uses: actions/checkout@v6
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false

Expand All @@ -43,27 +46,27 @@ jobs:

steps:
- name: Checkout plugin
uses: actions/checkout@v6
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false

- name: Install pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6
with:
version: 10

- name: Setup Node
uses: actions/setup-node@v6
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: lts/*
cache: "pnpm"

- name: Install pnpm dependencies
run: pnpm install
run: pnpm install --frozen-lockfile

- name: Restore Playwright browsers cache
id: playwright-cache
uses: actions/cache/restore@v5
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('pnpm-lock.yaml') }}
Expand Down Expand Up @@ -108,7 +111,7 @@ jobs:

- name: Save Playwright browsers cache
if: steps.playwright-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5
continue-on-error: true
with:
path: ~/.cache/ms-playwright
Expand All @@ -119,7 +122,7 @@ jobs:

- name: Upload test results
if: always()
uses: actions/upload-artifact@v7
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: test-results-php${{ matrix.php }}-wp${{ matrix.wp }}
path: test-results
Expand Down
2 changes: 0 additions & 2 deletions resources/css/settings.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import url(https://fonts.bunny.net/css?family=space-grotesk:500,600);

@tailwind base;
@tailwind components;
@tailwind utilities;
11 changes: 9 additions & 2 deletions simple-analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
require __DIR__ . '/src/Actions/AddPluginSettingsLink.php';
require __DIR__ . '/src/Support/Str.php';
require __DIR__ . '/src/Support/OnloadCallback.php';
require __DIR__ . '/src/Support/CustomDomain.php';
require __DIR__ . '/src/Settings/Block.php';
require __DIR__ . '/src/Settings/Blocks/CalloutBlock.php';
require __DIR__ . '/src/Settings/Concerns/HasDocs.php';
Expand Down Expand Up @@ -92,7 +93,13 @@
$tab->multiCheckbox(SettingName::EXCLUDED_ROLES, 'Specific User Roles to Exclude')
->description('When none selected, all authenticated users will be excluded from tracking.')
->options(function () {
return wp_roles()->get_names();
$roles = wp_roles()->get_names();

if (is_multisite()) {
$roles[SimpleAnalytics\TrackingRules::SUPER_ADMIN] = 'Network administrator (Super Admin)';
}

return $roles;
});

$tab->ipList(SettingName::EXCLUDED_IP_ADDRESSES, 'Exclude IP Addresses')
Expand All @@ -104,7 +111,7 @@

$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).')
->description('E.g. api.example.com. Requires permission to save unfiltered HTML. Leave empty to use the default domain.')
->docs('https://docs.simpleanalytics.com/bypass-ad-blockers');

$tab->checkbox(SettingName::COLLECT_DNT, 'Collect Do Not Track')
Expand Down
2 changes: 2 additions & 0 deletions src/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SimpleAnalytics\Actions;

defined('ABSPATH') || exit;

trait Action
{
protected function hook(): string
Expand Down
2 changes: 2 additions & 0 deletions src/Actions/AddInactiveComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SimpleAnalytics\Actions;

defined('ABSPATH') || exit;

class AddInactiveComment
{
use Action;
Expand Down
7 changes: 4 additions & 3 deletions src/Actions/AddNoScriptTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace SimpleAnalytics\Actions;

use SimpleAnalytics\Setting;
use SimpleAnalytics\SettingName;
defined('ABSPATH') || exit;

use SimpleAnalytics\Support\CustomDomain;

class AddNoScriptTag
{
Expand All @@ -21,6 +22,6 @@ public function handle(): void

public function getCustomDomain(): string
{
return esc_url('https://' . Setting::get(SettingName::CUSTOM_DOMAIN, 'queue.simpleanalyticscdn.com') . '/noscript.gif');
return esc_url('https://' . CustomDomain::get('queue.simpleanalyticscdn.com') . '/noscript.gif');
}
}
2 changes: 2 additions & 0 deletions src/Actions/AddPluginSettingsLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SimpleAnalytics\Actions;

defined('ABSPATH') || exit;

use const SimpleAnalytics\PLUGIN_BASENAME;

/**
Expand Down
12 changes: 9 additions & 3 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SimpleAnalytics;

defined('ABSPATH') || exit;

use SimpleAnalytics\Actions\AddInactiveComment;
use SimpleAnalytics\Actions\AddNoScriptTag;
use SimpleAnalytics\Actions\AddPluginSettingsLink;
Expand Down Expand Up @@ -34,7 +36,7 @@ public function __construct(

public function boot(): void
{
$this->hooks->addAction('init', \Closure::fromCallable([$this, 'onInit']));
$this->hooks->addAction('wp_enqueue_scripts', \Closure::fromCallable([$this, 'enqueueScripts']));
$this->hooks->onActivation(\Closure::fromCallable([$this, 'onActivation']));

if ($this->hooks->isAdmin()) {
Expand All @@ -43,8 +45,12 @@ public function boot(): void
}
}

public function onInit(): void
public function enqueueScripts(): void
{
if ($this->hooks->isAdmin() || ($GLOBALS['pagenow'] ?? '') === 'wp-login.php') {
return;
}

$hasExcludedIp = $this->trackingRules->hasExcludedIp();
$hasExcludedUserRole = $this->trackingRules->hasExcludedUserRole();
$tracking = ! $hasExcludedIp && ! $hasExcludedUserRole;
Expand All @@ -61,7 +67,7 @@ public function onInit(): void
AddNoScriptTag::register();
}

if ($this->settings->boolean(SettingName::AUTOMATED_EVENTS)) {
if ($tracking && $this->settings->boolean(SettingName::AUTOMATED_EVENTS)) {
$this->scripts->push(new AutomatedEventsScript);
}

Expand Down
2 changes: 2 additions & 0 deletions src/ScriptRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SimpleAnalytics;

defined('ABSPATH') || exit;

use SimpleAnalytics\Scripts\Contracts\HasAttributes;
use SimpleAnalytics\Scripts\Contracts\HideScriptId;
use SimpleAnalytics\Scripts\Contracts\Script;
Expand Down
5 changes: 4 additions & 1 deletion src/Scripts/AnalyticsScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

namespace SimpleAnalytics\Scripts;

defined('ABSPATH') || exit;

use SimpleAnalytics\Scripts\Contracts\HasAttributes;
use SimpleAnalytics\Scripts\Contracts\HideScriptId;
use SimpleAnalytics\Scripts\Contracts\Script;
use SimpleAnalytics\Setting;
use SimpleAnalytics\SettingName;
use SimpleAnalytics\Support\CustomDomain;
use SimpleAnalytics\Support\OnloadCallback;

class AnalyticsScript implements Script, HasAttributes, HideScriptId
{
public function path(): string
{
return sprintf("https://%s/latest.js", Setting::get(SettingName::CUSTOM_DOMAIN, 'scripts.simpleanalyticscdn.com'));
return sprintf("https://%s/latest.js", CustomDomain::get('scripts.simpleanalyticscdn.com'));
}

public function handle(): string
Expand Down
Loading