Skip to content

v12 #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 62 commits into
base: main
Choose a base branch
from
Open

v12 #40

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
4e33371
Fix problem with solana extension
ironbrands16 May 11, 2023
38373b8
Move from _phantom to phantom
adriaandotcom May 12, 2023
ea0cd3d
Merge pull request #39 from ironbrands16/patch-1
adriaandotcom May 12, 2023
f79ba5d
Run prettier via GitHub Action
May 12, 2023
3d7ccb5
Fix bug in checking phantom.solana
adriaandotcom Jun 19, 2023
65a6c3a
Always expose sa_pageview
adriaandotcom Jun 29, 2023
a914c9a
Check for Cloudflare under attack mode param
adriaandotcom Jul 14, 2023
de31383
Run prettier via GitHub Action
Jul 14, 2023
4924174
Test for all Cloudflare params
adriaandotcom Jul 14, 2023
23e043d
Clean subdomain hostname, fix auto events for links with child elemen…
adriaandotcom Mar 7, 2024
dc1a3ef
Add acron and remove trailing comma
adriaandotcom Feb 13, 2025
6e7ce19
Run prettier via GitHub Action
adriaandotcom Feb 13, 2025
e717409
Save local changes [no ci]
adriaandotcom May 27, 2025
8845936
Add jsdom unit tests
adriaandotcom May 27, 2025
46992f6
Fix default test without Browserstack
adriaandotcom May 29, 2025
5dad1ea
Add unit test to job
adriaandotcom May 29, 2025
770470a
Make sure all node js version are the same
adriaandotcom May 29, 2025
cda1d7d
Merge pull request #63 from simpleanalytics/codex/set-up-unit-tests-w…
adriaandotcom May 29, 2025
3fb3495
Merge branch 'v12' into v12-b
adriaandotcom May 29, 2025
065dbb1
Allow overwriting referrer
adriaandotcom May 29, 2025
ae84e8d
Merge pull request #62 from simpleanalytics/v12-b
adriaandotcom May 29, 2025
e1702cf
Rename testing file
adriaandotcom May 29, 2025
779661a
Run prettier in dry mode [no ci]
adriaandotcom May 29, 2025
dc35828
Add AGENTS guidance
adriaandotcom May 29, 2025
f99b45f
Improve AGENTS.md
adriaandotcom May 29, 2025
fbdd6ee
Add .cursorrules [no ci]
adriaandotcom May 29, 2025
fb045ce
Merge pull request #64 from simpleanalytics/codex/create-agents.md-fi…
adriaandotcom May 29, 2025
6bbf49a
Add modular unit tests and helpers
adriaandotcom May 29, 2025
d16c953
Merge pull request #65 from simpleanalytics/codex/plan-unit-testing-s…
adriaandotcom May 29, 2025
6f06801
Run browserstack not every time, and add linting
adriaandotcom May 29, 2025
b721ad0
Run browserstack not every time, for real
adriaandotcom May 29, 2025
495be42
Require prettier for brwoserstack too
adriaandotcom May 29, 2025
6bb5c0d
Rename prettier to linting
adriaandotcom May 29, 2025
8bfb9ec
Merge pull request #67 from simpleanalytics/codex/create-agents.md-file
adriaandotcom May 29, 2025
0a8a5ff
chore: fix eslint errors
adriaandotcom May 30, 2025
47bda2f
Merge pull request #68 from simpleanalytics/codex/fix-eslint-errors
adriaandotcom May 30, 2025
bfd91a4
feat(auto-events): skip automation when data-simple-event present
adriaandotcom May 30, 2025
912f482
Add manual build step
adriaandotcom May 30, 2025
5ee72b9
Merge branch 'v12' into codex/skip-automated-events-for-data-simple-e…
adriaandotcom May 30, 2025
0f12612
Merge pull request #69 from simpleanalytics/codex/skip-automated-even…
adriaandotcom May 30, 2025
82fcbb4
Rename to Testing Suite
adriaandotcom May 30, 2025
e38d8f6
Merge branch 'main' into v12
adriaandotcom May 30, 2025
21ae5b7
fix metadata reload in appendMetadata
adriaandotcom May 30, 2025
c256994
Merge pull request #70 from simpleanalytics/codex/fix-sa_metadata-loa…
adriaandotcom May 30, 2025
1835428
Bind sendBeacon calls
adriaandotcom May 30, 2025
f37e4ee
Merge branch 'v12' into codex/implement-fix-for-sendbeacon-error
adriaandotcom May 30, 2025
cfdd6f6
Merge pull request #71 from simpleanalytics/codex/implement-fix-for-s…
adriaandotcom May 30, 2025
7dc389f
Add callback support to sa_pageview
adriaandotcom May 30, 2025
3ac0008
Merge branch 'v12' into codex/add-callback-to-sa_pageview
adriaandotcom May 30, 2025
76b0426
Merge pull request #72 from simpleanalytics/codex/add-callback-to-sa_…
adriaandotcom Jun 13, 2025
cba0b20
Checkout dist after test:unit
adriaandotcom Jun 13, 2025
2d165c9
Reuse query param filter for manual pageviews
adriaandotcom Jun 13, 2025
984f634
Merge branch 'v12' into codex/fix-query-param-handling-in-sa_pageview
adriaandotcom Jun 13, 2025
2bfd05c
Merge pull request #74 from simpleanalytics/codex/fix-query-param-han…
adriaandotcom Jun 13, 2025
8ed3786
test: add metadata collector attr test
adriaandotcom Jun 13, 2025
28bf151
Merge branch 'v12' into codex/add-test-for-data-metadata-collector
adriaandotcom Jun 13, 2025
e1b021e
Merge pull request #75 from simpleanalytics/codex/add-test-for-data-m…
adriaandotcom Jun 13, 2025
571b372
Run npm run build
adriaandotcom Jun 13, 2025
67edab1
Add unit tests for auto-events
adriaandotcom Jun 13, 2025
defc6a0
Warn when metadata collector function is not found
adriaandotcom Jun 24, 2025
a216bda
Run npm run build
adriaandotcom Jun 24, 2025
aa513da
Merge pull request #77 from simpleanalytics/codex/add-unit-tests-for-…
adriaandotcom Jun 24, 2025
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
2 changes: 2 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Check AGENTS.md for instructions specifically for AI
- Check README.md for instructions
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es6: true,
node: true,
},
extends: "eslint:recommended",
ignorePatterns: ["dist/"],
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",
},
parserOptions: {
ecmaVersion: 2020,
},
overrides: [
{
files: ["test/**/*.js"],
env: { mocha: true },
},
],
rules: {},
};
68 changes: 0 additions & 68 deletions .github/workflows/browserstack.yml

This file was deleted.

133 changes: 133 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Testing Suite

on:
pull_request:
types: [opened, synchronize]
push:
branches:
- main
workflow_dispatch:

env:
NODE_VERSION: 22.16

jobs:
linting:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Run npm ci
run: npm ci

- name: Run npm prettier
continue-on-error: true
run: |
./node_modules/.bin/prettier --check . || echo "::warning::Prettier found formatting issues. Fix it locally by running './node_modules/.bin/prettier --write .'"

- name: Run ESLint
run: ./node_modules/.bin/eslint --ext .js .

unit-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Run npm ci
run: npm ci

- name: Build project
run: npm run build

- name: Run unit tests
run: npm run test:unit
env:
CI: true
NODE_ENV: test

build:
runs-on: ubuntu-latest
needs: unit-tests
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Run npm ci
run: npm ci

- name: Build project
run: npm run build

- name: Commit build changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add dist/
git diff --staged --quiet || git commit -m "Update build artifacts [skip ci]"
git push

browserstack:
runs-on: ubuntu-latest
needs: [unit-tests, linting, build]
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'

steps:
- name: "BrowserStack Env Setup"
uses: "browserstack/github-actions/setup-env@master"
with:
username: ${{ secrets.BROWSERSTACK_USERNAME }}
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}

- name: "Start BrowserStackLocal Tunnel"
uses: "browserstack/github-actions/setup-local@master"
with:
local-testing: "start"
local-logging-level: "all-logs"
local-identifier: "random"

- uses: actions/checkout@v4

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Run npm ci
run: npm ci

- name: Build project
run: npm run build

- name: Run BrowserStack tests
run: node ./test/index.js
env:
CI: true
NODE_ENV: test
DEBUG: false
LOCATION: ${{ secrets.LOCATION }}
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}

- name: "Stop BrowserStackLocal"
uses: "browserstack/github-actions/setup-local@master"
with:
local-testing: "stop"
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.16
22.16
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "es5"
}
21 changes: 21 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Agent Instructions

This repository contains the public scripts for Simple Analytics. When making changes keep the following points in mind.

## Development

- Use **Node.js 22.16** (see `.nvmrc`).
- Run `npm run build` to compile the scripts. This generates the files in `dist/` which should be committed.
- Format code with Prettier before committing. You can run `npx prettier -w .` or validate with `npm run prettier`.

## Testing

- Execute `npm run test:unit` to run the unit tests
- When adding a new feature or fixing a bug, please add a test.
- For every change, run `npm run build` to ensure the test uses the latest compiled version.
- Ignore most files in the `dist/` directory when checking for diffs, just check `dist/latest/latest.dev.js` and `dist/latest/auto-events.js` (whichever is relevant).
- Only tests in `test/unit/` are relevant for the AI and agents (it can run without internet access).

## References

Most work happens in `src/` with `compile.js` creating the distributable versions. Read `README.md` for more details about contributing and running scripts locally.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Just run `npm run watch` and every file will be validated and compiled on save.

The most important file of the repository is [`/src/default.js`](src/default.js)

## Unit tests

Run `npm run test:unit` to execute a small set of tests without BrowserStack.

## Device testing is sponsored by BrowserStack

We run our public script with more than [50 browsers on many different (real) devices](https://github.com/simpleanalytics/scripts/blob/main/test/helpers/get-browsers.js). We support Internet Explorer 9 (not sure who is still using that) and up. Including many mobile browsers and less common devices. We get amazing sponsorship from [BrowserStack](https://www.browserstack.com/). Thanks, BrowserStack!
Expand Down
30 changes: 28 additions & 2 deletions compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ const UglifyJS = require("uglify-js");
const fs = require("fs");
const esprima = require("esprima");
const path = require("path");
const acorn = require("acorn");

const GREEN = "\x1b[32m%s\x1b[0m";
const YELLOW = "\x1b[33m%s\x1b[0m";
const RED = "\x1b[31m%s\x1b[0m";

const VERSION = 11;
const VERSION = 12;

Handlebars.registerHelper("or", function (param1, param2) {
return param1 || param2;
Expand Down Expand Up @@ -320,7 +321,7 @@ for (const file of files) {
.digest("hex")
.slice(0, 4);

const prepend = `/* Simple Analytics - Privacy friendly analytics (docs.simpleanalytics.com/script; ${date}; ${hash}${
const prepend = `/* Simple Analytics - Privacy-first analytics (docs.simpleanalytics.com/script; ${date}; ${hash}${
variables.sri ? `; SRI-version` : ""
}${variables.version ? `; v${variables.version}` : ""}) */\n`;

Expand Down Expand Up @@ -358,6 +359,31 @@ for (const file of files) {
for (const warning of warnings || [])
console.warn(YELLOW, `[${name}] ${warning}`);

try {
acorn.parse(rawCode, { ecmaVersion: 5 });
} catch (error) {
// console.log("acorn", error);

// error object:
// pos: 147,
// loc: Position { line: 12, column: 0 },
// raisedAt: 148

// Find part of the code that is causing the error
const lines = rawCode.split("\n");
const line = error.loc.line;
const column = error.loc.column;
const start = Math.max(0, line - 3);
const end = Math.min(lines.length, line + 3);
const codeSnippet = lines.slice(start, end).join("\n");
const sentence = lines[error.loc.line - 1];

// console.log({ codeSnippet, line: lines[error.loc.line - 1] });

throw new Error(
`${error.message} at line ${sentence} position ${column}: ${codeSnippet}`
);
}
const code = fillTemplate(codeTemplate, variables);

const validate = template({
Expand Down
4 changes: 2 additions & 2 deletions dist/latest/auto-events.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading