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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/README.md export-ignore

# SRI hashes depend on exact bytes, including line endings.
/resources/js/pinned/** text eol=lf
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.

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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ You need a Simple Analytics account. Start with the [free plan](https://www.simp

- [WordPress plugin page](https://wordpress.org/plugins/simpleanalytics/)
- [Create a Simple Analytics account](https://www.simpleanalytics.com/signup)

## Script pinning

Enable **Pin analytics scripts** under **Settings → Simple Analytics → Advanced** to run the v12 analytics and automated-events scripts bundled with the plugin, instead of the latest scripts from the CDN. Every script tag carries a Subresource Integrity (SRI) hash, so a browser refuses changed bytes. Pinning is off by default. Script updates arrive with plugin releases. Clear page caches after changing this setting or updating the plugin, so visitors receive the new script tags, and exclude pinned files from JavaScript rewriting or minification.

With a custom domain, the plugin fills the domain into the bundled custom-domain build, as the custom-domain server does for `https://YOUR.DOMAIN/sri/v12.js`, and saves it as `wp-content/uploads/simpleanalytics/v12-YOUR.DOMAIN.js`. That script sends data to the custom domain. If the uploads folder is not writable, visitors get the bundled script for the default domain and administrators see a warning.

### Updating pinned scripts

- Pinned scripts follow the releases of [simpleanalytics/scripts](https://github.com/simpleanalytics/scripts). `VERSION` in `src/Support/ScriptPinning.php` is the release tag (`v12`), and `resources/js/pinned/v12/` holds `dist/v12/app.js`, `dist/v12/custom/app.js` and `dist/v12/auto-events.js` from that release's `scripts-v12.tar.gz`, unmodified. `app.js` equals `https://scripts.simpleanalyticscdn.com/sri/v12.js` except for its source map comment. The MIT license is retained in `resources/js/pinned/LICENSE`.
- For a new release such as `v13`: review the upstream changes, put the same three files from `scripts-v13.tar.gz` in `resources/js/pinned/v13/`, remove `v12/`, and change `VERSION`, `INTEGRITY`, `CUSTOM_DOMAIN_INTEGRITY` and `EVENTS_INTEGRITY` together. Calculate each hash with `echo "sha384-$(openssl dgst -sha384 -binary FILE | openssl base64 -A)"`. Never calculate the expected hashes at runtime.
- Run the PHP regressions and browser checks, including altered script responses, a custom domain, and event collection.
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ Installing "Simple Analytics" can be done in multiple ways.

== Frequently Asked Questions ==

= Can I pin the analytics scripts? =

Yes. Enable "Pin analytics scripts" under Settings > Simple Analytics > Advanced. The plugin then runs the v12 analytics and automated-events scripts bundled with it, with Subresource Integrity, instead of the latest scripts from our CDN. Pinning is off by default. Script updates arrive with plugin releases. Clear page caches after enabling pinning or updating the plugin, and exclude pinned files from JavaScript rewriting or minification. With a custom domain, the plugin saves a copy of the script for that domain in the uploads folder. The readable source of the bundled scripts is at https://github.com/simpleanalytics/scripts/tree/v12/src.

= Is Simple Analytics free? =

Yes. You can use Simple Analytics for free forever. You only need to create an account at [Simple Analytics](https://simpleanalytics.com/?ref=wordpress).
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;
21 changes: 21 additions & 0 deletions resources/js/pinned/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018-2026 Simple Analytics

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading