Commit Graph

64 Commits

Author SHA1 Message Date
RobertJoonas a83b4f3583
Clean up legacy verification code and script v2 flag (#5824)
* add module name to service_error when check times out

Otherwise, it can sometimes remain unclear in the diagnostics, whether
it was InstallationV2 or InstallationV2CacheBust that timed out.

* Remove duplicate timeout logic

The current production logs show two types of verification timeouts:

* service_error: "Unhandled Browserless response status: 408" (vast
  majority of cases)
* service_error: :timeout (only a few cases)

The latter happens when we hit the Req receive_timeout
(endpoint_timeout + 2s). I've seen Browserless not respect the timeout
param from time to time, so it's better to keep the timeout logic
"in-house" only.

* make service_error into a map with code and extra

* interpret temporary service errors

...but still consider them "unhandled" for telemetry, also notifying Sentry
and logging the warning.

* separate sentry messages (verification)

* make Verification.ChecksTest more DRY

* organize tests into describe blocks

* test verification telemetry and logging

* fix codespell

* get rid of legacy verification

* rename Checks.InstallationV2 -> Checks.VerifyInstallation

* delete Live.Installation and rename Live.InstallationV2 -> Live.Installation

* rename installationv2 (live) files as well

* delete old change-domain routes

Also rename current liveview modules and routes, removing the v2 suffix

* rename domain_change_v2 files, removing v2 suffix

* remove legacy JS verifier code

Also fix dockerignore and elixir.yml referencing a wrong priv path

* rename verification_v2_test -> verification_test

* remove v2 prefix from logs and sentry messages

* clean up duplicate external_sites_controller_test.exs tests

* remove flag

* fix typespec

* pass timeout as query param to Browserless too

* Fixup external sites controller test module (#5826)

* fix test description

---------

Co-authored-by: Artur Pata <artur.pata@gmail.com>
2025-10-27 09:39:41 +00:00
Artur Pata 6b1821362f
Start passing official installs that are using legacy .compat script (#5812)
* Start passing official installs that are using legacy .compat installation

* Pass the first domain for verifying legacy compat installs

* Fix variable access issue

* Fix non-existent function call

* Comment why split domainString
2025-10-16 15:53:18 +00:00
Artur Pata 3eeab00273
Make sure undefined callbackResult (ignored event) is visible in logs (#5802) 2025-10-14 08:54:20 +00:00
Artur Pata b03569d762
Update tests transformRequest tests (#5687) 2025-09-16 05:39:17 +00:00
Artur Pata cc5ca4b752
Script v2: Apply prettier (#5718)
* Apply prettier

* Fix issue with quotes in test setup

* Fix other issues with customSubmitHandlerStub

* Fix format with cookies fixtures
2025-09-15 11:21:27 +00:00
Artur Pata f7acb068d4
Script v2: Change priority of CSP related error for verifying manual installations (#5707)
* Add logic to find Plausible script tag

* Clarify where cookies fixtures come from

* Add case for snippet not found

* Fix issue with installation type not propagating to diagnostics

* Better struct definition

* Refactor verification tests to be more comprehensive

* Fix compile error related to Test.Support.DNS

* Fix DNS imports for CE

* Refactor when tracker is in HTML is detected
2025-09-11 06:59:03 +00:00
Artur Pata 88fccb6972
Script v2: Show "Plausible not detected" errors with installation type specific recommendations (#5693)
* Show Plausible not detected errors with installation type specific recommendations

* Update diagnostics and diagnostics tests for verification

* Format

* Stop calling statuses between 200..299 as errors

* Remove function that populates diagnostics randomly
2025-09-04 06:24:37 +00:00
Artur Pata 757cf95070
Script v2: Adds linter and prettier, satisfies linter (#5691)
* Install deps and create config

* Satisfy linter in tests

* Silence redeclare warnings

* Remove shadowed/redeclared variables

* Update changelog
2025-09-04 04:56:42 +00:00
Artur Pata af06df806b
Script v2: Verifier accepts cookies (#5669)
* Accept cookies (WIP)

* Make resolving Plausible function call a priority

* Update tracker script version

* Remove cookieBannerLikely, replace with debug-only cookiesConsentResult

* Use compact rules

* Make verifier tests less flaky

* Add fixtures for accepting cookies

* Limit CMPs

* Fix dep position
2025-09-01 05:54:19 +00:00
Karl-Aksel Puulmann 619a9ed57b
ScriptV2: Use async instead of defer, new snippet (#5655)
* async -> defer

* Run legacy tests using async instead of defer
2025-08-25 07:12:11 +00:00
Karl-Aksel Puulmann b36a92fb45
ScriptV2: snippet structure change (#5662)
* Remove dead code

* Use a new snippet style

* Allow plausible to be on window
2025-08-25 05:35:06 +00:00
Karl-Aksel Puulmann bcf8b422e1
ScriptV2: Domain change refinement (#5657)
* Improve "back to settings" button

* Dark mode support for change domain

* Purge CDN cache on domain change

* Allow npm installation_type

* Detect npm installation type in detector

* Support npm installation type in onboarding

* Show warning in change domain flow for npm

* Make CE tests happy

* Cleanup

* npm_likely -> npm

* Cleanup
2025-08-21 09:25:39 +00:00
Artur Pata 276f95cda2
Script v2: Make detection take less time (#5635)
* Add fast failing dns check to verification

* Convert Detection to a checks pipeline

* Convert detection to checks pipeline

* Unify browserless checks, set retry policy, timeouts

* Fix spelling

* Update change domain v2

* Fix issue with handling errors with detection

* Include timeoutMs in detector function args

* Allow saving npm installation type (#5639)

* small code style/comment improvements

---------

Co-authored-by: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com>
Co-authored-by: Robert Joonas <robertjoonas16@gmail.com>
2025-08-19 10:16:27 +00:00
Artur Pata a2df9a986c
Script v2: Add more diagnostics cases to verifier v2, more tests for verifier v2 (#5620)
* Add more diagnostics cases to verifier v2, more tests for verifier v2

* Remove extraneous text from CSP in tests
2025-08-11 10:43:59 +00:00
Artur Pata 5807878a18
Script v2: Handle verifying sites where there's an immediate JS redirect (#5619)
* Handle canceled execution context when verifying v2 installs

* Show diagnostics even on verification success for superadmins

* Add check for scriptv2 user to support branching off to v2 site verification better
2025-08-07 07:51:22 +00:00
Artur Pata a533116444
Fix unexpected config switch from calling init twice with plausible web (#5601) 2025-08-04 10:26:40 +00:00
Artur Pata 9c35a0f47c
Script v2: Handle exceptions on clicks on links within svgs (#5538)
* Access href attribute more defensively to avoid uncaught errors

WIP

chore: Bump tracker_script_version to 22

Try accept limitation

Clarify issue with tagged link clicks within svgs

Fix potential error chain accessing object

Revert fixes about tagged events props

* Refactor script tests
2025-08-04 10:10:08 +00:00
Artur Pata bb17a17e5a
Script v2: Allow verifying that tracker installed correctly (1st iteration) (#5572)
* Sketch out verification for v2 installs

* WIP

* Fix naming

* Implement CSP check, refactor what test event output looks like

* Update error matcher

* Better typedefs

* Unify error format

* WIP diagnostics

* Delete superfluos doc

* Remove prettierrc

* Fix type

* Remove superfluous error file

* Remove foobar.md

* Fix format and variable names, ensure compliance for errors

* Add cache bust check, fix success diagnostics

* Fix v2 verifier spec and add moduledocs

* Make test not dependent on tracker script version

* Make verifier less CPU intensive

* Change the signature of checkDisallowedByCSP

* Fix unused service_errror matcher

* Refactor data_domain to expected_domain

* Ignore request URL

* Add case for for succeeding after cache bust

* Fix infinite recursion

* Relax CSP error interpretation

* Fix sentry message, ignore plausible.s
2025-07-31 08:10:44 +00:00
RobertJoonas c5adbc6af0
Detector.js - detect v1 and technologies used on the website (#5591)
* fix comment on localhost dogfood tracking

* improve detector script and integrate into Elixir

* wait for window.plausible.l instead of window.plausible

* do not touch source files during compilation

* stop referencing compiler hint module attr
2025-07-29 06:17:16 +00:00
RobertJoonas 9be0b71233
Add `window.plausible` to NPM + `window.plausible.v2` (#5580)
* setWindowFlag

* bindToWindow

* set window.plausiuble.v2 flag

* chore: Bump tracker_script_version to 24

* fix billing test

* tracker changlog

* Update tracker/test/plausible-npm.spec.js

Co-authored-by: Artur Pata <artur.pata@gmail.com>

* update npm tracker changelog

* flattened window.plausible fields with more info

* remove unused function + readme update

---------

Co-authored-by: Karl-Aksel Puulmann <oxymaccy@gmail.com>
Co-authored-by: RobertJoonas <RobertJoonas@users.noreply.github.com>
Co-authored-by: Artur Pata <artur.pata@gmail.com>
2025-07-22 10:06:46 +00:00
RobertJoonas 97dcc3fe7c
Refactor Verification module structure (#5570)
* detector.js

* refactor: organize modules better

* Renaming (Elixir + JS)

* lib/plausible/verification -> lib/plausible/installation_support
* test/plausible/verification -> test/plausible/installation_support
* priv/tracker/verifier -> priv/tracker/installation_support
* tracker/verifier -> tracker/installation_support
* tracker/test/verifier -> tracker/test/installation-support

* rename remaining test modules

* add documentation

* dialyzer: remove module refs that do not exist yet

* Fix CI

* fix tracker CI

* fix tracker CI for good
2025-07-15 10:50:34 +00:00
RobertJoonas b76996b3a4
Verification v2 (#5549)
* new verifier script with tests + telemetry

* dataDomainMismatch tests

* more tests for callbackStatus and plausibleInstalled

* create priv/verifier subfolder + fix Elixir CI

* bump CI cache version

* organize verifier tests

* Remove accidentally committed verifier

* Rework compilation: Make it a variant, always return new verifier code in tests

* Make priv/tracker/verifier/ exist

* Handle static checks with grace

* Fix paths

* Fix paths

* Add some tests

* Add one more test

* split up the JS

* proxyLikely + code structure refactor + unit tests

* fix telemetry fields

* move most telemetry to logs

* run verifier tests only on chromium

* detect wordpressPlugin and wordpressLikely

* detect GTM

* rename JS checks

* detect cookiebot

* include new fields in logs

* different logs for browserless request vs js failures

* detect manual extension

* detect unknown attrs + fix logging

* stick to Elixir checks for snippet detection

* fix codespell

* fix IO.inspect

* remove unnecessary fields from test mock

* cookiebot doc

* move test into verifier subfolder

* do not duplicate ts types

* comma -> semicolon in log

* test dynamically loaded snippet

* improve logging on Browserless error

---------

Co-authored-by: Karl-Aksel Puulmann <oxymaccy@gmail.com>
2025-07-14 14:32:21 +00:00
Artur Pata 3bdbe83383
Script v2: Sync event.props.path for special path-based events from event.pathname (#5559)
* Sync pathname to event.props.path for special path-based goals

* Stop adding event.props.path for 'Form: Submission' events

* Update tracker script version

* Fix test expectations

* Fix format

* Simplify maybe_put_props_path with 'with'

* Add specs, fix factory

* Update tracker changelog

* Update EE/CE changelog

* Remove business logic from factory

* Refactor event.props.path sync result to be validated with the rest of the custom props

* Clarify doctests and update function name
2025-07-14 08:39:25 +00:00
Artur Pata 04f455cbfc
Script v2: Do not send Form: Submission events for tagged forms (#5546)
* Do not send duplicate tagged form events

* Update changelog

* chore: Bump tracker_script_version to 22

* Share HTML fixture

---------

Co-authored-by: apata <apata@users.noreply.github.com>
2025-07-08 08:01:14 +00:00
Artur Pata 74dddc241c
Script v2: Remove delays except when using .compat extension (#5465)
* Make delays conditional on COMPILE_COMPAT, otherwise rely on keepalive fetch

* Add tests

* Fix webkit related test file-download feature tests issues

* Remove ternaries for scriptConfig in tests

* Make sure .compat scripts don't contain unreachable code blocks

* Test legacy .compat extension in a separate block

* Tests for tagged events

* Remove extraneous tests, add needed tests

* Add tests for v2 features overlap and outbound link clicks

* Add changelog, add current behaviour test for outbound links

* Remove mockRequest, unify API

* Fix coverage of legacy compat navigation, add back interactive event test

* chore: Bump tracker_script_version to 21

* Update specs

* Fix issues with _ variable

* Fix args

* Types and formatting cleanup

---------

Co-authored-by: apata <apata@users.noreply.github.com>
2025-06-27 12:10:02 +00:00
Karl-Aksel Puulmann 1f86ae55ef
ScriptV2: `callback`, file downloads and `logging` changes (#5514)
* Make logging in tracker script configurable

* Improved callbacks

* Improved fileDownloads

* Export DEFAULT_FILE_TYPES

* Cross-browser compatibility

* Rename

* Rename a test

* chore: Bump tracker_script_version to 20
2025-06-19 08:45:20 +00:00
Artur Pata bf39a4c34f
Script v2: Rename form submission system event (#5512)
* Rename form submission

* Update changelog

* chore: Bump tracker_script_version to 19

---------

Co-authored-by: apata <apata@users.noreply.github.com>
2025-06-17 10:10:05 +00:00
Karl-Aksel Puulmann c7779e2f33
ScriptV2: Support `meta` only in legacy scripts (#5492)
* Revert "Log warning when m/meta parameter used in ingestion (#5478)"

This reverts commit d4bec6d9e3.

* Support `meta` argument only on legacy scripts + test

* Changelog

* Bump version
2025-06-16 12:25:00 +03:00
Karl-Aksel Puulmann c3dd21431c
ScriptV2: `transformRequest` (#5488)
* Commit as Plausible Bot

This way commits by it can be excluded from protections

* ScriptV2: Add support for `config.transformRequest`

transformRequest allows users to either manipulate or ignore requests to plausible
with a minimal footprint.

Some use-cases we're aware of and are planning for:
1. Ignoring requests similar to previous exclusion rules in WordPress
2. Normalizing urls for requests

* Allow passing `options.url` for overriding url when calling track

Previous naming `u` was unintuitive, but is kept around (untyped) for backwards
compatibility reasons

* chore: Bump tracker_script_version to 17

* Changelog

* Update types

* Docs

* Add test showing interaction with engagement events

* README.md
2025-06-12 11:50:27 +00:00
Karl-Aksel Puulmann 595e71a399
ScriptV2: NPM library codebase (#5459)
* Compile NPM modules into commonjs and esm modules

Note that since the module uses only vanilla es5 outside the export,
it's safe to just append to the minified output

* package.json, Typescript definition, generation for commonjs

* Scrap commonjs for the moment

Running into too big rabbit holes trying to get it off the ground

* Shared tests for npm and web

* Better way to identify npm module in fixture

* Simplify code

* Add NPM library specific tests

* Fix a flaky test

* Standardize a callsite

* npm_package standardize on

* Make legacy variant code more explicit

* Wrap code pre and post

* analyze-sizes.js should work with npm_package

* Port test changes from PR #5432

* Update outbound link feature test

* Await callInit

* Smaller npm module - mangle variables

* Clean up wrapping code

* chore: Bump tracker_script_version to 15

* Add debug messaging to expect

* Remove dead code

* Refactor, account for initialization delays in tests

* Remove needless features from compiler

As the compiler currently manages to compile everything in ~3 seconds,
the `features`/`compileIds` feature serves no more point. Scrapping it

* Re-inline readOutput

* Update tracker/test/plausible-npm.spec.js

Co-authored-by: Artur Pata <artur.pata@gmail.com>

* Remove redundant comment

---------

Co-authored-by: Artur Pata <artur.pata@gmail.com>
2025-06-04 10:47:44 +00:00
Karl-Aksel Puulmann 426ae49ed1
Proposal: ScriptV2 bundler (#5449)
* Experiment with rollup bundler

* WIP: Unbundle

* Always allow overriding url with options.u

* fix conditional

* Update manual conditional #2

* Unbundle custom events code

* Unbundle autocapturing of pageviews

* Comment Object.assign

* Rename functions in compiler

* Rename trigger -> track, unbundle

* Dont rely on window.plausible in custom-events.js

* chore: Bump tracker_script_version to 14

* Cherry-pick PR #5462
2025-06-04 07:36:02 +00:00
Artur Pata a01f8e1c05
Update playwright (#5432)
* Refactor mock-many-requests

* Add commented fallback route

* Fix outbound link tracking expectation, fix file downloads import

* Remove console logs

* Add test skips and remove unnecessary skip

* Revert test name change

* Remove webkit related conditional in test expectations

* chore: Bump tracker_script_version to 13

---------

Co-authored-by: apata <apata@users.noreply.github.com>
2025-06-03 09:03:55 +00:00
Karl-Aksel Puulmann 98cdeb23dd
ScriptV2: Configuration renames, iteration (#5427)
* plausible-main -> plausible-web

* Change elixir workflow

* Update tracker option names in tracker.ex

* config.hash -> config.hashBasedRouting

* Enable revenue by default for plausible-web

* Enable taggedEvents by default

* config.local -> config.captureOnLocalhost

* manual -> autoCapturePageviews

* Update playwright tests

* Support adding/editing file types for download in plausible-web

Original docs: https://plausible.io/docs/file-downloads-tracking#what-if-i-want-to-track-a-different-file-type

* rebase: initialize-page-dynamically update

* chore: Bump tracker_script_version to 12

* Ignore pageviews in file-downloads.spec

* Phrasing in tests

* Remove unneeded conditional
2025-05-27 11:28:17 +00:00
Artur Pata 9be012362c
Track form submission events (#5381)
* Track form submissions

* chore: Bump tracker_script_version to 11

* Check that script loadedin tests

* Track form submissions

* Fix format

* Fix missing form submit handler

* Make id casing consistent

* Automatically sync compiled script snippet in dynamic test pages

* Enforce format manually

* Skip one test on Firefox, explain reason for stub

* Revert "Automatically sync compiled script snippet in dynamic test pages"

This reverts commit 7622b23f31.

---------

Co-authored-by: apata <apata@users.noreply.github.com>
2025-05-26 06:30:21 +00:00
Karl-Aksel Puulmann 844c118135
ScriptV2: `plausible.init`, `customProperties`, snippet compilation, double initialization protection, `swc` (#5391)
* WIP: init() for plausible.js

* Reformat whitespace

* Handle double-initialization gracefully

* Script customProperties option

* Remove pageview-props from tracker script interpolation - its now an advanced config

* Add compile option for compiling the web snippet. This can then be copied to e.g. onboarding

* Switch minification from uglify-js to swc

* Use 4 passes for optimal output

* Remove use strict to remove it from output. Uglifyjs already removed this

* Minor optimization: Remove nulls from output via runningEngagementStart

* Minor optimization: Reduce onIgnoredEvent

* config_json -> config_js

* Dead attribute

* Remove guard for engagements

* More protective customProperties

* Object.assign

* chore: Bump tracker_script_version to 10

* No need for default in Object.assign

* Remove dead guard
2025-05-20 06:57:35 +00:00
Karl-Aksel Puulmann 96abac2d4e
ScriptV2: plausible-main, script size measurements (#5375)
* analyze-sizes.js script

* Start work on plausible-main

Size changes:
```
Main variants:
|                                 | Brotli | Gzip  | Uncompressed |
| ------------------------------- | ------ | ----- | ------------ |
| plausible-main.js (new variant) | 2344B  | 2675B | 6062B        |

Important legacy variants:
|                                                                                                   | Brotli               | Gzip                 | Uncompressed          |
| ------------------------------------------------------------------------------------------------- | -------------------- | -------------------- | --------------------- |
| plausible.js                                                                                      | 1086B (-6B / -0.5%)  | 1283B (+5B / +0.4%)  | 2684B (+4B / +0.1%)   |
| plausible.hash.js                                                                                 | 1078B (+24B / +2.3%) | 1268B (+29B / +2.3%) | 2642B (+76B / +3%)    |
| plausible.pageview-props.tagged-events.js                                                         | 1846B (+57B / +3.2%) | 2158B (+63B / +3%)   | 4739B (+185B / +4.1%) |
| plausible.file-downloads.hash.pageview-props.revenue.js                                           | 1669B (+62B / +3.9%) | 1958B (+54B / +2.8%) | 4097B (+175B / +4.5%) |
| plausible.compat.exclusions.file-downloads.outbound-links.pageview-props.revenue.tagged-events.js | 2286B (+81B / +3.7%) | 2692B (+84B / +3.2%) | 5978B (+280B / +4.9%) |

Summary:
|                                                                                                                     | Brotli               | Gzip                 | Uncompressed            |
| ------------------------------------------------------------------------------------------------------------------- | -------------------- | -------------------- | ----------------------- |
| Largest variant (plausible.compat.exclusions.file-downloads.outbound-links.pageview-props.revenue.tagged-events.js) | 2286B (+81B / +3.7%) | 2692B (+84B / +3.2%) | 5978B (+280B / +4.9%)   |
| Max change (plausible.exclusions.hash.local.manual.outbound-links.pageview-props.js)                                | 1460B (+80B / +5.8%) | 1755B (+83B / +5%)   | 3557B (+241B / +7.3%)   |
| Min change (plausible.js)                                                                                           | 1086B (-6B / -0.5%)  | 1283B (+5B / +0.4%)  | 2684B (+4B / +0.1%)     |
| Median change                                                                                                       | 1723B (+65B / +3.9%) | 2037B (+70B / +3.6%) | 4335B (+220.5B / +5.3%) |
```

* Janky conditionals for COMPILE_CONFIG

Results in no size increase for historical scripts:

Main variants:
|                                 | Brotli | Gzip  | Uncompressed |
| ------------------------------- | ------ | ----- | ------------ |
| plausible-main.js (new variant) | 2339B  | 2672B | 6058B        |

Important legacy variants:
|                                                                                                   | Brotli          | Gzip                | Uncompressed    |
| ------------------------------------------------------------------------------------------------- | --------------- | ------------------- | --------------- |
| plausible.js                                                                                      | 1092B (0B / 0%) | 1280B (+2B / +0.2%) | 2680B (0B / 0%) |
| plausible.hash.js                                                                                 | 1054B (0B / 0%) | 1241B (+2B / +0.2%) | 2566B (0B / 0%) |
| plausible.pageview-props.tagged-events.js                                                         | 1789B (0B / 0%) | 2097B (+2B / +0.1%) | 4554B (0B / 0%) |
| plausible.file-downloads.hash.pageview-props.revenue.js                                           | 1607B (0B / 0%) | 1906B (+2B / +0.1%) | 3922B (0B / 0%) |
| plausible.compat.exclusions.file-downloads.outbound-links.pageview-props.revenue.tagged-events.js | 2205B (0B / 0%) | 2610B (+2B / +0.1%) | 5698B (0B / 0%) |

Summary:
|                                                                                                                     | Brotli                   | Gzip                     | Uncompressed             |
| ------------------------------------------------------------------------------------------------------------------- | ------------------------ | ------------------------ | ------------------------ |
| Largest variant (plausible.compat.exclusions.file-downloads.outbound-links.pageview-props.revenue.tagged-events.js) | 2205B (0B / 0%)          | 2610B (+2B / +0.1%)      | 5698B (0B / 0%)          |
| Max change (plausible.js)                                                                                           | 1092B (0B / 0%)          | 1280B (+2B / +0.2%)      | 2680B (0B / 0%)          |
| Median change                                                                                                       | 1655B (0B / 0%)          | 1969B (+2B / +0.1%)      | 4116B (0B / 0%)          |

* plausible-main: no COMPILE_EXCLUSIONS

Size change from this:
|                   | Brotli              | Gzip                  | Uncompressed          |
| ----------------- | ------------------- | --------------------- | --------------------- |
| plausible-main.js | 2223B (-116B / -5%) | 2533B (-139B / -5.2%) | 5710B (-348B / -5.7%) |

* Rework server.js to be less compiler-aware

* Add first test for plausible-main.js

* Tests for plausible-main variant

* Remove report-sizes.js

* Tracker - report size changes in a comment

* Update summary notes

* Handle outbound links not being captured by network tab in webkit

See: https://3.basecamp.com/5308029/buckets/39034214/card_tables/cards/8429433464

* Solve a TODO

* Sign in comment

* Update pin

* Mock file downloads

* Update base branch

* Pin add-and-commit as per cenk request

* Use bot for checkout

* Attempt to reduce permissions

* Smaller fetch depth

* Fix rebase
2025-05-12 06:55:54 +00:00
Karl-Aksel Puulmann 7265d04a8c
ScriptV2: Improved tracker compile.js (#5363)
* Add CLI arguments to compile.js and logging

* Rename folder

* Extract compile code, es modules

* Add a progress bar

* Remove handlebars

* Update report-sizes

* Remove debug code

* inline

* More generous split

* Allow positional arguments for compiling

* Add watch option to compile

* Add compileFile logic

* Most tests run under playwright

* All tests runnable

* Update playwright, remove hack

Note that upgrading to latest failed due to a new test failure. This
might be due to a chrome update.

* Compile script on the fly for tests

* Minor refactor for compileAll

* es module for generate-variants.js

* Allow passing suffix to compilation script - this can be used to generate separate files for comparison

* Fix positionals

* Switch from 2 passes to 1 pass

Did some data analysis on this data:
- Compared to master, 1 pass increased brotli size by 0.7%, 2 passes 0.4%.

Given the change is insignificant enough, we can ignore it for now

The increase is likely due to order of operations in compilation and
some inlined functions getting lost.

* Move customEvents.js to plausible.js

* Clean up API

* Suffix default

* Rework variants.json, globals stored there

* Add more variants under test

* Distribute work across multiple worker threads

Compile time went on my machine from 60s -> 30s

* Fixup server

* Update canSkipCompile

* chore: Bump tracker_script_version to 7

* Update scripts

* Update node-version

* Experiment with adding a small delay to page

* Casing

* rename variable

* Update help text

* features -> compileIds, backport functionality from other branch
2025-05-08 07:05:09 +00:00
Karl-Aksel Puulmann a3db3af806
Avoid compiling pageleave variant and p.js (#5351)
* Avoid compiling pageleave variant

Instead, it's treated as a no-op. Tracker still serves it.

Compile wall time went down from 86s -> 46s.

* Vendor, no longer compile p.js

This was a legacy script variant which we keep for backwards
compatibility but little else.

* chore: Bump tracker_script_version to 6
2025-04-29 06:42:48 +00:00
Karl-Aksel Puulmann 2114c6232d
Allow marking custom events as non-interactive (#5295)
* Tracker: Allow sending non-interactive custom events

These will not affect is_bounce

* Allow marking events as `non-interactive` in events API, change bounce definition

Ref: https://3.basecamp.com/5308029/buckets/26383192/card_tables/cards/8450017341
Feedback: https://feedback.plausible.io/220

* CHANGELOG.md

* credo

* Update tracker script version

* Explicitly ignore event.interactive in schema

* Replace an old test util
2025-04-21 08:11:58 +00:00
RobertJoonas 86e485e210
Tracker bug: engagements not fired on manual trigger SPAs (#5313)
* add a test

* fix bug

* chore: Bump tracker_script_version to 3

---------

Co-authored-by: RobertJoonas <RobertJoonas@users.noreply.github.com>
2025-04-10 10:57:20 +00:00
Karl-Aksel Puulmann 539f4a3f98
Tracker script version reported to /api/event (#5198)
* WIP

* tracker_script_version over reportedVersion

Will make it easier to grep for this thing

* CHANGELOG.md

* Only add tracker/package.json in workflow commit

* chore: Bump tracker_script_version to 1

* Show tracker_script_version is reported in tracker tests

* Track `engagement_time` while accounting for time page is blurred (#5206)

Consider this scenario:
1. User opens page /blog
2. 3 seconds later, alt-tabs to another window
3. minute later, alt-tabs to the page and closes it

Previously, this would be reported as 1m03s engagement_time. Now this
would be reported as 3s engagement_time.

* remove redundant engagement cooldown (#5199)

---------

Co-authored-by: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com>
2025-03-18 07:30:17 +00:00
Uku Taht c85862e9ed
Access document more defensively (#5148)
* Access document more defensively

* Add test
2025-03-05 16:06:06 +00:00
Uku Taht 294f6da293
Scroll Depth Release: make pageleave script the new default (#5105) (#5137)
* pageleave to default

* update report-sizes.js

Co-authored-by: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com>
2025-03-04 12:35:24 +00:00
RobertJoonas 7dd5664992
Revert "Scroll Depth Release: make pageleave script the new default (#5105)" (#5112)
This reverts commit 079b40068c.
2025-02-25 10:52:41 +00:00
RobertJoonas 079b40068c
Scroll Depth Release: make pageleave script the new default (#5105)
* pageleave to default

* update report-sizes.js
2025-02-25 09:30:22 +00:00
Karl-Aksel Puulmann 75a8b19571
time-on-page: track engagement time in plausible.js (#5087)
* Track engagement time in plausible.js

* Test page going between background and foreground without sending

* Rename some variables

* Add comment on when we send information or not

* Extract a function

* Test SPA navigation

* Raise threshold

* Update tracker/src/plausible.js

Co-authored-by: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com>

---------

Co-authored-by: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com>
2025-02-20 10:31:24 +00:00
Karl-Aksel Puulmann 63b732eb36
Tracker: Track only engagements (pageleave extension) (#5039)
* Tracker: Remove tracking pageleaves

* chore(tracker): rename html files

* Update comment
2025-02-06 11:35:10 +00:00
Karl-Aksel Puulmann 8e7520c944
Tracker: Run tests on safari (#5038) 2025-02-04 10:48:27 +00:00
Karl-Aksel Puulmann de62f80564
Use `fetch` over `XMLHttpRequest` in plausible.js (#5025)
`fetch` allows us to use the keepalive flag, which more reliably
delivers data to us. It's also required for reliable scroll depth
capturing down the line.

The only major browser not to support fetch is Internet Explorer.
Clients who care about IE traffic can use the `.compat` variant of our
script (documented in
https://plausible.io/docs/script-extensions#scriptcompatjs). As of this
commit, IE makes up less than ~0.003% of incoming traffic to plausible.
2025-02-03 08:48:37 +00:00
Karl-Aksel Puulmann 334f8bbdfc
Tracker: Send `engagement` events on visibilitychange (if pageleave extension) (#5023)
* Separate `engagement` event triggered on visibilitychange

* Set up shared tests for engagement requests and pageleaves

* Store scroll_depth on engagement events

* Move test to be shared

* Update cache_store
2025-01-29 06:30:41 +00:00