louisbarclay / nudge

Nudge makes the internet less addictive.
https://nudgeware.io
MIT License
144 stars 9 forks source link

Create proper all-time history for each user & send to server #15

Closed louisbarclay closed 4 years ago

louisbarclay commented 7 years ago

Currently localStorage keeps a bunch of info about domains and nudges but it's not enough to do proper analysis and tell people e.g. you used FB for 3 hours this week (data clears itself every day). Additionally if we stored this all in localStorage or Chrome.storage we would quickly run out of space so this 'proper all-time history' needs to be sent to our server, which is set up already.

History should include the following:

Visits to nudge domains

Nudges (most of this already exists in nudges in localStorage)

postNudgeAction

Figure out sensible schedule for sending this data to server, and way to ensure information is never duplicated on server side (and that no information is skipped).

I will send an email now detailing the server API info for sending data over. You can see there is a function in background.js which enables sending stuff to server - you can find a user ID hash there. Server API was made by Kristo.

louisbarclay commented 7 years ago

Some clearer instructions:

  1. use chrome identity API in place of getRandomToken (background.js line 114) - https://developer.chrome.com/apps/identity. this is so that each user always has the same ID, even if Nudge is deleted and reinstalled. currently every time i reinstall Nudge, it's creating a new user in the DB
  2. log Visits, Nudges (as defined above - ignore postNudgeActions for now) in localStorage. requires creating a new localStorage object localStorage.visits where visits get put in once that particular visit has ended - which occurs line 432 background.js when 'domainTimeUpdater' runs
  3. send all 3 over to DB using post function at background.js line 147 every [week] and clear localStorage once data successfully transferred
  4. some safeguard to prevent duplication of data onto database

@biggest-dave could you add @danieljvdm to the nudge-api repo in case that's helpful?

louisbarclay commented 4 years ago

Dropped