I'm finishing another HTML5 game, and this time I'd like to do some spying business on the players... Mostly just basic stuff: when they are playing, for how long, what upgrades they are buying the most and so on. Now, my first idea was just to collect this information during the gameplay, and then have a Javascript function fire when they close the tab/browser, and said function would send it to my server via Socket.io. This, of course, wouldn't work, because anyone who takes a look at the code would realize it and could start sending a tonne of false info which would mess up my statistics.


  • Is there a way to effectively do this?
  • If yes, what kind of info should I be looking for, aside from stuff I already mentioned?
  • 3
    \$\begingroup\$ You should also ask them if they have your permission to collect this info, and indicate what kinds of stuff you're sending. \$\endgroup\$ – ashes999 Apr 8 '12 at 15:34
  • \$\begingroup\$ Why? Do I have to, legally? \$\endgroup\$ – jcora Apr 8 '12 at 15:40
  • 3
    \$\begingroup\$ I'm not qualified to answer legal questions. But read questions on GameDev. The backlash from not asking permission and sending data without telling users is usually enough to get people to avoid your game entirely. It's inevitable that they discover this. \$\endgroup\$ – ashes999 Apr 8 '12 at 15:41
  • 2
    \$\begingroup\$ There is right now a vote going on area 51 about opening a Laws & Legal Questions site. Think about committing to use it. \$\endgroup\$ – user14741 Apr 9 '12 at 0:02
  • \$\begingroup\$ Yes! A few months ago, we were chatting here and we all agreed that it's a great idea! \$\endgroup\$ – jcora Apr 9 '12 at 9:44

You can simply gather all the info you need into some convenient form, such as JSON or something, then send it at some stage in a XmlHttpRequest, whenever you feel is appropriate.

Yes, people COULD forge requests and send loads of crap, but they probably won't. And you can record the IP address of each recipient, and if an unlikely amount of responses come from one address, you can just disregard them all.

It is highly unlikely that you will have any problems. Those eleet haxxors have better things to do than skew your stats. Really.

  • \$\begingroup\$ Awesome, thanks! I'll just do some IP checks as you suggested, and some reality checks. \$\endgroup\$ – jcora Apr 8 '12 at 22:08
  • 2
    \$\begingroup\$ Just to reiterate, since this is the winning answer: make sure you ask them before you do this. \$\endgroup\$ – ashes999 Apr 9 '12 at 2:33
  • \$\begingroup\$ Google Analytics is a particularly easy to use API for this purpose, and works surprisingly well. Several Very Big Games are doing this, in fact. The API is not precisely the best suited to the task, but it's easy to just use that than build your own. \$\endgroup\$ – Sean Middleditch Apr 9 '12 at 9:30
  • 1
    \$\begingroup\$ No need to check the IP address, just store the IP addresses with your other data, if there are anomalies they can easily be removed. \$\endgroup\$ – MarkR Apr 9 '12 at 10:18

Well this is much easier in a multiplayer game where things are validated but you could probably do the same thing.basically, male a log of all actions and periodically send it to the server. (or when he/she logs in or out. You could also encrypt the data or obfuscate your code. But, since you're using html it's not fool proof.

  • \$\begingroup\$ And then, boom, suddenly they start sending false logs. In multiplayer games, I usually choose only to send actual keypresses, only that. I can't do this here, though, it's a singleplayer game (I mean, yes, I can, but I don't really want to go that far). \$\endgroup\$ – jcora Apr 8 '12 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.