mixpanel / mixpanel-js

Official Mixpanel JavaScript Client Library
https://mixpanel.com/help/reference/javascript
Other
881 stars 312 forks source link

LocalStorage `_mpq_` flush queue accumulate events #384

Open JonLev opened 1 year ago

JonLev commented 1 year ago

Hi guys, I noticed a strange behaviour with Mixpanel events localStorage usage: I have some of my user that have in their local storage a key that just accumulate elements of tracking: mixpanel-flush-queue-blurred

From my investigation this element is a kind of batch accumulation to flush to mixpanel with some debounce. But for some reason I don't know yet, they accumulate within the storage instead. My deeper problem is that other services that are based on storage are failing because there's so much elements that the storage limit is reached 😅.

My config is:

Let me know if you need more information

tdumitrescu commented 1 year ago

Hi @JonLev, yes, it would be very useful to get more info on your specific setup and the monitoring you have on users who hit this condition (it's likely specific to some combo of browser version, extensions, os etc). Can you email me at ted@mixpanel.com? Thanks

JonLev commented 1 year ago

Just did ! 🙏🏽

hrvbernardic commented 1 year ago

I've got the same problem. Would love to know if you find out why this is happening.

tomlagier commented 7 months ago

Same problem here. Will write some code to flush those localstorage keys during app start, but would be nice to not have to do that.

Current guess is that ublock is blocking the request that would flush the queue, which causes events to accumulate.

EDIT: Upgrading from mixpanel-browser 2.41 to 2.49 seems to have fixed the issue.

hussain-nz commented 6 months ago

Happening to us as well. My guess is that adblockers are preventing mixpanel events so they never get sent (or flushed). We will update to 2.49 and hope that fixes it

Colombo97 commented 4 months ago

@hussain-s6 did you solve it? I couldn't

goamn commented 4 months ago

@hussain-s6 did you solve it? I couldn't

No idea. It happened to my colleague and I was hoping it would fix the issue. I will try and check with him to see if it's still there. I didn't find any difficulty in upgrading to the newer version, did you try it? It's quite easy to diagnose, you can look for "mpq" items and see if they are getting big or not (100-500kb or greater), just run this script below, it is sorting in ascending order:

var _lsTotal=0,_xLen,_x,_lsData=[];for(_x in localStorage){if(localStorage.hasOwnProperty(_x)){_xLen=((localStorage[_x].length+_x.length)*2);_lsTotal+=_xLen;_lsData.push({key:_x,size:_xLen});}}_lsData.sort((a,b)=>a.size-b.size).forEach(item=>console.log(item.key.substr(0,50)+" = "+(item.size/1024).toFixed(2)+" KB"));console.log("Total = "+(_lsTotal/1024).toFixed(2)+" KB");

Colombo97 commented 4 months ago

Yes I tried to update but it didn't solve. About the script, yes, I've added one to check the storage size, almost the same that you've shared.

Colombo97 commented 4 months ago

I'm thinking about making a workaround to solve this deleting the mpq from the localstorage

goamn commented 4 months ago

I'm thinking about making a workaround to solve this deleting the mpq from the localstorage

I think it's valid to use a workaround, otherwise users will have a crashed app with no way to recover. Thanks for letting me know, we will probably implement the workaroudn as well :)