News for hackers. Stuff that matters.
Re:0 second visits according to Google Analytics by shurcooL on Sunday May 12, 2013 @01:53PM (#5695120)
Can I get some feedback on the following idea please:

- Maintain an open (but idle) websocket connection on your page to have an accurate real-time visitor information. The websocket should remain open as long as the user doesn't close the tab or navigate away.

What are some cons that prevent everyone from doing so?

Re:0 second visits according to Google Analytics by dhimes on Sunday May 12, 2013 @01:58PM (#5695140)
I have many tabs open that I'm not actually "on." I just took a shower and left HN open, for example. Can it detect that the tab is "active" or "focus?" That may help. But I'm not sure this is a problem worth a ton of work. It's, at best, a proxy for measuring things like interest.
Re:0 second visits according to Google Analytics by bsimpson on Sunday May 12, 2013 @02:06PM (#5695188)

    document.addEventListener('visibilitychange', onVisibilityChange);
Re:0 second visits according to Google Analytics by shurcooL on Sunday May 12, 2013 @02:02PM (#5695167)
Yeah, as you say, even if it just tells if a tab is open (active or inactive), that's already a good measure of interest.

But I think it may be possible to determine if the current tab is open with some javascript, and send that information through the websocket. Edit: what bsimpson said.

Re:0 second visits according to Google Analytics by thezilch on Sunday May 12, 2013 @01:59PM (#5695149)
~50% of visitors don't have websocket support, and there is not, afaik, a free service offering such, and otherwise, it is probably not straightforward enough for the 99% to setup.
Re:0 second visits according to Google Analytics by shurcooL on Sunday May 12, 2013 @01:59PM (#5695150)
You can see a sample in action here [1]. The page should list every single person in the world (whose browser supports websockets) who is currently on that page. You can open multiple tabs and see that whenever you close/navigate away, your corresponding entry will disappear.

[1] https://dl.dropboxusercontent.com/u/8554242/live-status.html

Re:0 second visits according to Google Analytics by daemon13 on Sunday May 12, 2013 @02:19PM (#5695237)
Error: TypeError: sock is undefined

Ubuntu, Firefox 20.0

Re:0 second visits according to Google Analytics by shurcooL on Monday May 13, 2013 @01:30PM (#5700040)
I just debugged this. The issue is that Firefox doesn't allow insecure websocket connections from https.

So either change the url to http://dl.dropboxusercontent.com/u/8554242/live-status.html or override the network.websocket.allowInsecureFromHTTPS setting in about:config to true.

Re:0 second visits according to Google Analytics by dangrossman on Sunday May 12, 2013 @02:03PM (#5695173)
Everyone does do so already (though not necessarily with websockets; occasional pings are sufficient and more widely supported). Google Analytics has a real-time dashboard. So do most web analytics platforms these days.
Re:0 second visits according to Google Analytics by shurcooL on Sunday May 12, 2013 @02:06PM (#5695182)
How do you ping a browser? Where can I find more info about this.

I figured the real-time dashboard of Google Analytics must be doing something similar, but I don't know what exactly they use.

Re:0 second visits according to Google Analytics by dangrossman on Sunday May 12, 2013 @02:08PM (#5695191)
The browser pings the server.

    setInterval(function() {
        $.ajax('http://analytics-site.com/ping?page=' + window.location.href);
    }, 5000);
Re:0 second visits according to Google Analytics by shurcooL on Sunday May 12, 2013 @02:09PM (#5695203)
Ah, makes sense, thanks.
Re:0 second visits according to Google Analytics by brokentone on Sunday May 12, 2013 @02:27PM (#5695266)
GA realtime does not differ in tracking methodology, it uses the same onload beacon, just like the long-tail reporting.