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

Handle optimizely.get not yet existing #1343

Closed jethron closed 2 months ago

jethron commented 2 months ago

Fixes a regression from 24928acd08164d42f95e3c1de88f63d6cdef1b67 that undoes the fix from #798.

If window.optimizely exists, but window.optimizely.get does not yet exist, we never populate state. The fix for #798 added checks for dereferencing methods directly on the result, but provided no default for getActiveExperimentIds() meaning experiment_ids would also be undefined if state was.

Originally the code used lodash/map to then iterate over experiment_ids, that was then updated to directly be experiment_ids.map; with no default this tries to dereference undefined to call the method, whereas lodash/map accepts undefined as a value and returns an empty array.

This changes the plugin to:

bundlemon[bot] commented 2 months 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% :white_check_mark: | trackers/javascript-tracker/dist/sp.js
| +25.48KB | 25.5KB / +10% :white_check_mark: | trackers/javascript-tracker/dist/sp.lite.js
| +15.77KB | 16KB / +10% :white_check_mark: | trackers/browser-tracker/dist/index.umd.min.j
s
| +15.72KB | 16KB / +10% :white_check_mark: | libraries/tracker-core/dist/index.module.js
| +13.4KB | 15KB / +10% :white_check_mark: | trackers/browser-tracker/dist/index.module.js
| +3.51KB | 5KB / +10%

Total files change +101.4KB 0%

Final result: :white_check_mark:

View report in BundleMon website ➡️


Current branch size history