
Open Source Visitor.js - codejoust
https://github.com/codejoust/visitor.js
======
memnips
It is now apparently Session.js <https://github.com/codejoust/session.js>

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

Fyi: I am not storing the information.

~~~
codejoust
Official demo: <http://codejoust.github.com/session.js/>

------
dsl
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.

------
gojomo
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?

~~~
ryanmahoski
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).

[https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-
Brow...](https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-
Polyfills)

~~~
nl
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>

~~~
ryanmahoski
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.

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

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

------
tonywebster
I love when disruption disrupts disruption.

------
grantjgordon
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.

------
slavin
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.

------
DannyPage
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.

~~~
driverdan
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.

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

~~~
codejoust
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.

~~~
Flimm
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.

~~~
pbhjpbhj
>" _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.

~~~
Flimm
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.

~~~
pbhjpbhj
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.

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

------
josscrowcroft
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.

------
mise
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.

------
sbarre
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.

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

<http://codejoust.github.com/session.js/ipinfodb_demo.html>

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

------
dchuk
well...that didn't take long

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

> session.locale.country

"US"

> session.locale.location

undefined

~~~
arnoooooo
Are you not confusing

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

and

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

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

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

~~~
wavephorm
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.

------
tomhallett
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?

~~~
cag_ii
He answers that in the earlier visitor.js thread:

<http://news.ycombinator.com/item?id=3434154>

------
dlitz
Visitor.js should be the new FizzBuzz

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

~~~
codejoust
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.

~~~
desireco42
I get it. Thanks for writing it.

------
alpb
Gives 404?

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

------
buremba
404?

~~~
esoltys
"Moved to session.js"

<https://github.com/codejoust/session.js>

------
necenzurat
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?

~~~
Terretta
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.

