Hacker News new | past | comments | ask | show | jobs | submit login
Open Source Visitor.js (github.com)
198 points by codejoust on Jan 6, 2012 | hide | past | web | favorite | 52 comments

It is now apparently Session.js https://github.com/codejoust/session.js

Here is a live demo showing your own information. http://visitorjs.herokuapp.com/

Fyi: I am not storing the information.

Damn, you beat me to it. After I saw the original visitor.js was a paid service (which blew my mind), I started hacking together the JS implementations of most of the functionality I had laying around already.

The original visitor.js identified my city correctly; this only put me in the USA.

Is there a free reliable precise geolocation service that can take as many hits as a script like this could throw at it?

Your best bet is html5 geolocation + modernizr.js + a shim. Browsers that support html5 geolocation will return highly accurate results while those that don't support it will fall back to calling the google maps api (ip to geo).


HTML5 Geolocation requires people to opt-in, which is pretty messy.

Better off getting the free version of the MaxMind city database[1] and running it on a server somewhere.

[1] http://www.maxmind.com/app/geolitecity

The opt-in button is messy but results are very precise and reliable. Some use cases warrant it, some do not. Maxmind claims 79% accuracy on a city level: is the google api worse? All other things being equal I would be inclined to pick the one that didn't require me to frequently install binary patches or update a database.

But I agree with you, it's a ux dealbreaker for most situations. Solution: control the hardware. :)

I added in support for http://ipinfodb.com/ (see bottom of README) which might be better than Google's api, although you need to register for an API key. You might want to give that a shot.

Worked fine with me, here in Brazil.

It properly identify my country (Belgium) and my region, but it returned another unrelated city.

I'm glad you've done this, because I'd have wasted a few hours on it I didn't have otherwise :-)

I love when disruption disrupts disruption.

I don't think there are any ethical issues here. The paid service is doing something that was mostly, if not completely, available in other open source projects such as piwik and OWA in the first place. It's very educational to look at the differences in the way codejoust implemented his javascript vs. these other projects, and very convenient that you don't have to dig through a gigantor open source code base to do it.

I don't understand the pricing model behind visitorjs, and we had to implement a similar solution at my company. But the fact is - they created something and shared it here. If you think you can do a better job at it - fine, but why haven't you done it before, or at the very least named it differently. I don't mean to exaggerate, but it just doesn't feel ethical to me.

What are the ethical concerns about using this and storing the data? If I wanted to use this on my site, should I let visitors know, or is this data fair game to store? I rather not use the location data (or any of it) if there could be an issue.

Since websites need a privacy policy if they have users in California anyway, you might as well put your use of the data into it.

You should always tell your users what data you gather and how you use it. If you only let the data stay in the browser and never send it to the server then tell them.

1: You can turn off location data.

2: None of this is being stored, beyond a cookie. Of course, you can call back to the server with that data, but the server has your IP address, which is where the location data came from.

Is this version created or endorsed by the authors of the other Visitor.js implementation?

No. And the recently-posted paid visitor.js site does have a few advantages, most being that this is using pure javascript, while they have the server side doing most of the heavy lifting.

In that case, this implementation really should have a different name. It's confusing to have two competing implementations share the same name, and it may be a trademark violation.

>"and it may be a trademark violation."

"visitor.js" isn't distinct in the field, particularly as it's descriptive and of a common form, I'd warrant it's not novel either.

That doesn't mean that you wouldn't be sued for using it just that any sane TM office shouldn't allow it to be registered and that a sane IP judge should dismiss a case brought against it's use as passing off. The law isn't sane of course ....

I think it's reasonable to use the same name if the scope is largely co-terminous.

It's because the scope is co-terminous that having different names is so important. IANAL, but trademarks don't have to be distinct or novel to be legitimate. They are allowed to be descriptive (like Windows or iPhone).

The fork of OpenOffice.org was named LibreOffice, because it would be unfair to name a competing product with the same name. I'm glad the author of this library has decided to do the same.

First up, "iphone" is definitely not descriptive, it's abstract, a made up word. "touchPhone" would be descriptive. "Windows", well ... it's a generic term now but at the time, despite it being to some extent descriptive of a WIMP system it was arguably a distinctive term for an OS (but I'm surprised it was allowed).

OpenOffice.org is interesting because they previously named the project "Open Office" and suffered trademark problems and had to be very careful to use the full name of the project. But had the former project been called "Computer Office Suite" then trademark issues wouldn't have arisen because that's not a distinctive mark and so couldn't be protected, it's descriptive anyone selling such software could use that description.

It's not unfair to use an identical descriptive name for things that serve the same function - for example Microsoft and Apple both sell something that they use the term "Operating System" to describe. OS is a descriptve term that is expected to be used in the field and so can't be a trademark, it doesn't serve to indicate origin.

I'd argue that visitor.js is an expected name for a piece javascript that logs visitors in some way, it's not distinctive of origin. Moreover it is descriptive of the function of the code. Kinda like having an ad loader that's called ads.js.

FWIW, and I've not been paying too much attention (!), only one of the pieces of code labelled visitor.js appears to be a product.

I believe the earlier comments have merit, thus I've renamed the library.

The best part about this whole thing is the location lookup. Seriously nice job.

I'm super impressed you turned this out so quickly. I think that really sums up the spirit in the HN community...

When you look at something that seems overpriced (or wrongly-priced) and you say "hey, I bet I could do this"

I still see value in potentially paying for a service like this when it's a big enough pain-point. But I really think they'd have had more traction with a open-source-to-paid model, where anyone can use the client-side code for free, but the extra stats and support provided are worth paying for.

Having a "first session" and "current session" exposes very interesting functionality. It suddenly provides a quick way to keep track of what search keywords they used to get to the site, and could be later linked to an account if later created.

location is either "null" or "err/google" for me all the time.

Although I am probably an edge-case, I'm tethering from an iPhone on Rogers in Canada.

Visitor.js (the paid service) correctly positions me in Toronto, Canada though.

Try using another database: I've implemented optional support for ipinfodb.com, however, the code is fairly modular to add another service.


Outstanding! I also was going to have to re-implement this.

well...that didn't take long

Localization doesn't seem to work very well. I'm in Waterloo, Canada. This is what the script outputs for me:

> session.locale.country


> session.locale.location


Are you not confusing

1) session.locale, which is the locale (ie. regional settings) configuration of your browser and might very well be US,


2) session.location, which gives your geographic location ?

I'm in Nairobi, Kenya. The output indicates I'm in the US as well.

where's the server stuff? is google providing everything that the pay service did, but for free?

Google provides it as an extra for the JSAPI, no telling how long it will last, though.

Developers should have learned by now not rely on Google for anything. Once all competing paid services (just like visitor.js) get driven out of business by Google's free service, you can count on Google doing the ol' bait and switch, by taking down the free API, erecting a paywall leaving themselves with a monopoly.

i'm curious about the timing here.

did you see vistor.js hit HN and rewrite it in a few hours? or were you working on this in isolation and when you saw it on HN decided it was the perfect time to ship?

He answers that in the earlier visitor.js thread:


Either way, Monday seems like it wouldve made for a bigger splash than Friday night

Visitor.js should be the new FizzBuzz

The only thing that would make this better is to have it in coffeescript... :) which I might do for you if you don't.

I thought about doing that. I've used a lot of coffeescript in the past, but I just didn't see it being a big advantage here. The biggest issue with using CoffeeScript here is that I wanted control over the syntax as I wanted to have less code. CoffeeScript (generated) really creates more code than what it's worth.

I get it. Thanks for writing it.

Gives 404?

the repository has been renamed. see session.js link in memnips comment.


after reading visitorjs.com thread i asked myself WHY

Question: who would pay 10 bucks a month for using a js file for 30K requests?

People who understand it's not a JS file, it's a generated JS file containing data the server of that file had to look up and process to create the JS.

Registration is open for Startup School 2019. Classes start July 22nd.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact