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

Fix removal of context generator functions #1361

Closed jethron closed 1 month ago

jethron commented 1 month ago

This fixes an issue when using removeGlobalContexts to remove a context generator function when multiple generator functions have been added.

In 3.0.0 the method of identifying the ContextPrimitive to remove was changed from equality/identity to comparing the JSON serialization of the entities. Unfortunately, this doesn't handle the generator function case, because JSON.stringify(function(){}) returns undefined, which means all added context generators appear identical, so removing one generator actually removes all of them.

This changes the comparison to be identity-based for functions, and remain JSON-based for static entities.

It also fixes matching on for ConditionalContextProviders by implementing a deep comparison. A purely identity-based approach is much simpler, but only a partial solution; non-identical providers with the same static entities added with different filter functions would still collide if the identities of the array don't match correctly.

bundlemon[bot] commented 1 month ago

BundleMon

Files added (6) Status | Path | Size | Limits :------------: | ------------ | :------------: | :------------: :white_check_mark: | libraries/browser-tracker-core/dist/index.mod
ule.js
| +27.51KB | 28KB / +10% :x: | trackers/javascript-tracker/dist/sp.js
| **+25.58KB** | 25.5KB / +10% :white_check_mark: | trackers/javascript-tracker/dist/sp.lite.js
| +15.87KB | 16KB / +10% :white_check_mark: | trackers/browser-tracker/dist/index.umd.min.j
s
| +15.84KB | 16KB / +10% :white_check_mark: | libraries/tracker-core/dist/index.module.js
| +13.61KB | 15KB / +10% :white_check_mark: | trackers/browser-tracker/dist/index.module.js
| +3.51KB | 5KB / +10%

Total files change +101.93KB 0%

Final result: :x:

View report in BundleMon website ➡️


Current branch size history