Skip to content
Open

v12 #40

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 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
c938f2f
Add tel link tracking to auto events
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
78bc66d
Fix delayed phone link events
adriaandotcom Jun 24, 2025
dc116ae
Merge pull request #76 from simpleanalytics/codex/add-tel--clicks-to-…
adriaandotcom Jul 29, 2025
9294410
fix allowParams regex to be case insensitive
adriaandotcom Jul 29, 2025
c869bb0
Merge pull request #81 from simpleanalytics/codex/make-allow-params-r…
adriaandotcom Jul 29, 2025
443ee6b
Merge main into v12
Aug 11, 2026
52d297e
Fix merged BrowserStack test setup
Aug 11, 2026
3e8bc7e
Collect compact query parameter names via ignore metrics
Aug 12, 2026
c70cae6
Run BrowserStack tests on Node.js 22.16
Aug 12, 2026
84ef41b
Use numeric BrowserStack test exit codes
Aug 12, 2026
6a74a12
Sync v12 conflict files with current main
Sep 16, 2026
d979bee
Merge current main into v12
simple-analytics-ai[bot] Sep 16, 2026
62d0cda
Use querykeys for query parameter name collection
Sep 16, 2026
3a6d633
Fix v12 CI after main sync
Sep 16, 2026
a2a876c
Document tracker compatibility and size priorities for agents (#115)
simple-analytics-ai[bot] Oct 15, 2026
38248a0
Support inline events in the main v12 script (#106)
simple-analytics-ai[bot] Oct 15, 2026
ee45d52
Preserve distinct manual pageviews in v12 (#108)
simple-analytics-ai[bot] Oct 15, 2026
b568ca3
Leave phone click navigation to the website and browser (#111)
simple-analytics-ai[bot] Oct 15, 2026
3395422
Respect the configured namespace for manual pageviews (#110)
simple-analytics-ai[bot] Oct 15, 2026
58f6679
Fix cmd-click for auto events (#78)
adriaandotcom Oct 15, 2026
6af229d
Count Cloudflare challenge arrivals as unique (#112)
simple-analytics-ai[bot] Oct 15, 2026
a3f1a4a
Accept current and legacy script deployment headers (#117)
simple-analytics-ai[bot] Oct 15, 2026
6b84d42
Remove retired Cloudflare app build from v12 (#121)
simple-analytics-ai[bot] Oct 15, 2026
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: {},
};
3 changes: 3 additions & 0 deletions .github/workflows/browserstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ jobs:
- name: Test BrowserStack matrix selection
run: pnpm run test:matrix

- name: Run unit tests
run: pnpm run build && pnpm run test:unit && pnpm run test:deploy

- name: Prettier check (report only, no writes or commits)
if: always()
run: |
Expand Down
23 changes: 23 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Agent instructions

Before working here, read the shared [Simple Analytics instructions](https://github.com/simpleanalytics/ide-config/blob/main/AGENTS.md) through the approved GitHub access method. Apply them alongside applicable parent and nested instructions; more specific instructions take precedence.

## Tracker changes

1. **Minimize shipped bytes.** Keep changes small and reuse existing helpers and variables. Measure minified and gzip byte differences for affected scripts against the target branch using the same build and compression settings. Test proposed optimizations: extracting repeated strings can increase gzip size.

2. **Preserve existing installations.** Unless the user explicitly accepts a behavior change, preserve existing settings and integrations. Check affected combinations against the [customer documentation](https://docs.simpleanalytics.com/), including manual pageviews, query handling, attribution, namespaces, ignored metrics, metadata, and automatic events. Report concrete before/after effects on customer data, event names, and counts, separately from additions that leave existing installations unchanged.

3. **Prefer simple implementations.** Add fallbacks, polling, abstractions, or compatibility layers only for a demonstrated requirement. Respect explicitly accepted tradeoffs, especially for unused beta helpers, rather than adding speculative compatibility machinery.

4. **Preserve website behavior.** Tracking must respect cancelled actions, existing handlers, form validation, submitter settings, modified clicks, new tabs, and downloads. Let the browser or website own navigation and submission; send tracking without forcing either action.

5. **Keep collection deliberate.** Honor collection settings and opt-outs. Distinguish query-parameter names from values when checking what is sent. Keep form field values out of automatic form tracking, sanitize automatically reported URLs, and keep extra diagnostic requests such as 404 confirmation opt-in. Make changes to collection defaults explicit for review.

6. **Preserve browser and build compatibility.** Keep visitor-facing output ES5-compatible and respect feature boundaries such as event-free `light.js`. Build affected scripts from source and commit their generated distributions. Review source and build inputs first, using relevant generated output to verify those changes. Keep previously published pinned versions and their SRI bytes unchanged unless explicitly requested.

## Validation and review

7. **Verify affected behavior locally.** Use the Node and pnpm versions declared by the repository configuration and the commands available in `package.json`; see `README.md` for setup. For script changes, rebuild before focused before/after payload and browser-interaction checks. Prefer the offline suites in `test/unit/` for local runs. Follow the shared testing policy and ensure committed tests run with declared dependencies. Leave the full BrowserStack matrix to CI unless explicitly requested, and report local verification separately from remote CI.

8. **Keep PRs easy to review.** Prefer one logical change per PR. Group related fixes under one issue, state dependencies and merge order, and branch from and target the integration branch requested by the user. Keep unrelated test-infrastructure repairs separate from tracker behavior changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ As our public scripts are very important in our mission to privacy we decided to

## Contribute

If you want to contribute, you probabaly want to contribute to our [`/src/default.js`](src/default.js) or [`/src/auto-events.js`](src/auto-events.js) files. These files compile into a few versions of our script by [`compile.js`](compile.js). They end up on [our CDN](https://scripts.simpleanalyticscdn.com/latest.js), custom domains, and [the Cloudflare app](https://www.cloudflare.com/apps/simpleanalytics).
If you want to contribute, you probabaly want to contribute to our [`/src/default.js`](src/default.js) or [`/src/auto-events.js`](src/auto-events.js) files. These files compile into a few versions of our script by [`compile.js`](compile.js). They end up on [our CDN](https://scripts.simpleanalyticscdn.com/latest.js) and custom domains.

In `default.js` you see some weird syntax in the comments. For example, `/** if ignorepages **/` _\[some code\]_ `/** endif **/`. These comments are converted to handlebars like this: `{{#if ignorepages }}` _\[some code\]_ `{{/if}}`. In this case, [`ignorepages` is a variable](https://github.com/simpleanalytics/scripts/blob/3874b44ce5f1b0b8a7d50fb512fdcf5285a0138f/minify.js#L66) used in `minify.js` that takes care of what functionality to show in what script. Our main script is the `latest.js` script which includes all features. We also have a `light.js` script that obviously doesn't.

Expand Down
82 changes: 32 additions & 50 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 All @@ -24,7 +25,7 @@ const MINIFY_OPTIONS = {
nameCache: null,
};

const fillTemplate = (template, { overwriteOptions = null } = {}) => {
const fillTemplate = (template) => {
if (!template)
throw new Error("Parsing of the JavaScript failed, please use ES5 only.");
return template
Expand All @@ -35,16 +36,6 @@ const fillTemplate = (template, { overwriteOptions = null } = {}) => {
.replace(
/\{\{\s?nginxProxyHost\s?\}\}/gi,
'<!--# echo var="proxy_hostname" default="" --><!--# echo var="proxy_path" default="/simple" -->'
)
.replace(
/\\?"\{\{\s?overwriteOptions\s?\}\}\\?"/gi,
overwriteOptions
? JSON.stringify(overwriteOptions).replace(/:"([^"]+)"/gi, ":$1")
: "{}"
)
.replace(
/"\{\{\s?cloudFlareCustomDomain\s?\}\}"/gi,
'INSTALL_OPTIONS.custom_domain || "queue.simpleanalyticscdn.com"'
);
};

Expand Down Expand Up @@ -77,7 +68,6 @@ const DEFAULTS = {
nonuniquehostnames: true,
ignoremetrics: true,
dev: false,
skipnonwindow: false,
};

const LIGHT = {
Expand Down Expand Up @@ -156,36 +146,6 @@ const templates = [
apiUrlPrefix: "queue.",
},
},
{
type: "js",
input: `${__dirname}/src/default.js`,
output: `cloudflare.js`,
variables: {
...DEFAULTS,
skipnonwindow: true,
minify: false,
version: VERSION,
scriptName: `cloudflare_${VERSION}`,
sri: false,
baseUrl: "{{cloudFlareCustomDomain}}",
overwriteOptions: {
hostname: "INSTALL_OPTIONS.hostname",
collectDnt:
"typeof INSTALL_OPTIONS.collect_dnt === 'boolean' ? INSTALL_OPTIONS.collect_dnt : null",
mode: "INSTALL_OPTIONS.hash_mode ? 'hash' : 'normal'",
strictUtm:
"INSTALL_OPTIONS.advanced_settings_toggle && INSTALL_OPTIONS.strict_utm",
allowParams:
"INSTALL_OPTIONS.advanced_settings_toggle && INSTALL_OPTIONS.allow_url_parameters",
nonUniqueHostnames:
"INSTALL_OPTIONS.advanced_settings_toggle && INSTALL_OPTIONS.non_unique_hostnames",
ignorePages:
"INSTALL_OPTIONS.advanced_settings_toggle && INSTALL_OPTIONS.ignore_pages",
namespace:
"INSTALL_OPTIONS.overwrite_namespace && INSTALL_OPTIONS.namespace",
},
},
},
{
type: "js",
input: `${__dirname}/src/default.js`,
Expand Down Expand Up @@ -308,10 +268,7 @@ for (const file of files) {
const finalFileName = output.split("/").pop();

const template = Handlebars.compile(contents);
const rawCode = template({
...variables,
overwriteOptions: "{{overwriteOptions}}",
});
const rawCode = template(variables);

const date = new Date().toISOString().slice(0, 10);
const hash = require("crypto")
Expand All @@ -320,7 +277,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,7 +315,32 @@ for (const file of files) {
for (const warning of warnings || [])
console.warn(YELLOW, `[${name}] ${warning}`);

const code = fillTemplate(codeTemplate, variables);
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);

const validate = template({
...variables,
Expand All @@ -385,7 +367,7 @@ for (const file of files) {
fs.mkdirSync(path.dirname(latestFile), { recursive: true });
}

const compiledMap = map ? fillTemplate(map, variables) : null;
const compiledMap = map ? fillTemplate(map) : null;
const isCustom = /^custom\//.test(output);

if (variables.version && variables.sri) {
Expand Down
4 changes: 2 additions & 2 deletions deploy.mts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ const CDN_PUBLIC_ROOT = "https://scripts.simpleanalyticscdn.com";
const CDN_STORAGE_ROOT = "https://storage.bunnycdn.com/sa-cdn";
const CDN_PURGE_URL =
"https://api.bunny.net/purge?url=https://simpleanalyticscdn.b-cdn.net/*";
const HEADER_PATTERN =
/^\/\* Simple Analytics - Privacy friendly analytics \(docs\.simpleanalytics\.com\/[^;]+; \d{4}-\d{2}-\d{2}; [0-9a-f]{4}(?:; SRI-version)?(?:; v\d+)?\) \*\/$/;
export const HEADER_PATTERN =
/^\/\* Simple Analytics - Privacy(?: friendly|-first) analytics \(docs\.simpleanalytics\.com\/[^;]+; \d{4}-\d{2}-\d{2}; [0-9a-f]{4}(?:; SRI-version)?(?:; v\d+)?\) \*\/$/;

const ansi = {
bold: (value: string) => color("1", value),
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
Loading