snowplow / snowplow-javascript-tracker

Snowplow event tracker for client-side and server-side JavaScript. Add analytics to your websites, web apps and servers.
http://snowplowanalytics.com
BSD 3-Clause "New" or "Revised" License
555 stars 222 forks source link

Add an emitter and event store interface in the tracker core to be used both by the browser and node trackers and use fetch API for making requests (close #1076) #1337

Closed matus-tomlein closed 3 months ago

matus-tomlein commented 3 months ago

This PR replaces the XMLHttpRequest API in the browser tracker and the got library in the Node tracker with the fetch API in order to make requests to the collector using a common code base.

The changes are:

  1. Add an Emitter in the tracker-core for making requests to the collector. This is used both by the Web and Node trackers.
  2. Add an EventStore interface including an in-memory implementation in the tracker-core. On top of this, the Web trackers implement a local storage based event store. The Node tracker uses the tracker-core implementation.

The new Emitter and EventStore interfaces are Promise-based so can be used to await when the events are stored or sent to the collector. I didn't change any outward facing Web tracker APIs to expose the promises, we can consider that though.

There are various breaking changes, I'll need to make a full list and publish in docs.

As part of the work, I also had to update the Node.JS version used for the build – I set the supported versions to >=18.0.0 <25.0.0.

bundlemon[bot] commented 3 months ago

BundleMon

Files added (6) Status | Path | Size | Limits :------------: | ------------ | :------------: | :------------: :white_check_mark: | trackers/javascript-tracker/dist/sp.js
| +27.69KB | 30KB / +10% :white_check_mark: | libraries/browser-tracker-core/dist/index.mod
ule.js
| +22.25KB | 25KB / +10% :white_check_mark: | libraries/tracker-core/dist/index.module.js
| +19.12KB | 20KB / +10% :white_check_mark: | trackers/browser-tracker/dist/index.umd.min.j
s
| +16.83KB | 20KB / +10% :white_check_mark: | trackers/javascript-tracker/dist/sp.lite.js
| +16.81KB | 20KB / +10% :white_check_mark: | trackers/browser-tracker/dist/index.module.js
| +3.49KB | 5KB / +10%

Total files change +106.18KB 0%

Final result: :white_check_mark:

View report in BundleMon website ➡️


Current branch size history

matus-tomlein commented 3 months ago

Thanks a lot for the in depth review @jethron, that was super helpful!