Ionic Analytics data takes up most of localStorage space


#1

I’m developing a mobile App using Ionic Framework. I tried to get the Ionic Analytics running by doing everything from scratch.

According to this :

To cut down on battery drain when sending events, Ionic Analytics does not send an HTTP request for every event tracked. Instead, it queues events in memory and sends a batch of events every 30 seconds. This 30 seconds is the dispatch interval.

So i assume every 30 seconds my analytics data should sync. For development i’m using Ionic serve --lab to debug my app and i’m tracking my localStorage usage with HTML5 Storage Manager All In One extension.

As i’m working with my app and tapping around and going to different states, Ionic is capturing my movements and in the log i see Ionic Analytics: enqueuing event to send later: Tap Object{...} and as i’m tracking my localStorage, the available space gets smaller and smaller. As this go on for quite some time, eventually i’ll hit the size quota limit and i’ll receive error until i manually delete my localStorage.

My question would be why the 30 second interval doesn’t free up the space used by Ionic Analytics queued events? Is this behavior normal when i’m testing on browser and will it be okay on actual mobile devices?


#2

I found out what the problem was and I’m afraid it was my own error. I’m posting what i did wrong so maybe someone doesn’t make the same mistake.

Normally for Ionic Analytics you have something like this in your app.js file :

app.run(function($ionicPlatform, $ionicAnalytics) {
  $ionicPlatform.ready(function() {

  // Some code here that throw errors when you are on browser rather than real device    

  $ionicAnalytics.register();   

  });
})

So basically i had some code before the $ionicAnalytics.register(); that only worked when i was testing with the real device and threw errors when i was in browser, so those uncaught errors were not allowing the $ionicAnalytics.register(); to run which is essential for sending the queued events. So my event queue would only increase because it never sent the data to the server. I learned my lesson here, either comment out the stuff you write for real devices or pay attention to those errors thrown in console and resolve them.