* 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>
* 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
* 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
* 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
* 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>
* move util function to util module
* move playwright config file to tracker dir root
* update Playwright + add gitignores
* Playwright: enable reuseExistingServer (non-CI env)
* store tracker src copies to avoid re-compilation in dev env
* test pageleave on simple navigation
* fix test util fn
* rename local_test npm script
* make test util able to expect multiple requests
* test pageleaves in SPAs
* test pageleave with manual URL
* test pageleave not sent in manual when pageview not triggered
* extend util fn to refute event requests
* test pageleaves not sent in excluded hash pages
* store hashes instead of file copies to detect /tracker/src changes
* drop async
* speed up test suite
* add experimental pageleave script variant
* also send pageleave events on SPA navigation
* disallow goals with 'pageleave' event name
* do not count pageleaves towards the event metric
* remove duplication in test file
* do not update sessions on pageleave events
* ignore pageleaves in the current time_on_page implementation
* make pageleave events not billable
* rename function
* Prevent multiple pageleaves being sent at the same time
Adds a new script extension that allows tracking interactions with specific HTML elements on a website. For example - to track link clicks on one specific `<a>` element, you can tag it like this:
```html
<a href=... class="plausible-event-name=<your_event_name>">
```
And you can also tag the link with custom property names and values:
```html
<a href=... class="plausible-event-name=<your_event_name> plausible-event-<your_custom_prop>=<your_value>">
```
Tagging a link as above will send a custom event with the given name and props, if a `click` or `auxclick` browser event happens, and targets the link element.
The tracking behavior is somewhat different based on the HTML element type:
- `<a>`
- triggers on `click` and `auxclick` events
- intercepts navigation based on the same rules as `outbound-links` and `file-downloads`
- `<form>`
- triggers on `submit` event
- always intercepts navigation (calls `form.submit()` after preventing default and sending the Plausible event)
- other (`<img>`, `<button>`, `<span>`, `<div>`, `<h2>`, etc ...)
- triggers on `click` and `auxclick` events
- does not prevent default to intercept possible navigation. Simply calls Plausible with the event name and props read from the element class list.
* moved custom event code to the bottom + fix indentation
* add handlebars helper fn + extract getLinkEl fn
* extract isOutboundLink function
* extract shouldFollowLink function
* remove middle and click variables
* use only one click handler for outbounds and downloads
* extract sendLinkClickEvent function
* add error handling when script compilation fails
* use callback instead of fixed timeout
* do not prevent default if externally prevented + test
* add more tests
* generate tracker files in priv/tracker/js
* update changelog
* requested changes after review
* regenerate tracker files
* use return instead of else if
* move middleMouseButton outside the function
* Adds data-exclude support and plausible_ignore support
* Splits exclusion into separate script option
* localStorage parsing upgrades
* Additional script type additions
I'm unsure about the formatting decision in tracker.ex - lmk.
* Adds new compiled files
This will certainly have conflicts with my other PRs related to the tracking scripts right now, I'll make one extra PR after both are done to ensure they're consolidated into the compiled scripts.
* Moves localStorage blocker out of special script
* Changelog
* Second thoughts on localStorage exclusion
* Updates `*` to not match `/` or whitespace
* Fix formatting
* Removes zero-length asterisks
* Adds support for double glob, zero-length replacements
* Update to reduce size+allow localStorage exclude
Co-authored-by: Uku Taht <Uku.taht@gmail.com>