
Show HN: Analytics.js – The analytics API you've always wanted - ianstormtaylor
http://segmentio.github.com/analytics.js/
======
alexdean
This is a cool idea for a project! The closest equivalent I'm aware of is
Qubit OpenTag (<https://github.com/QubitProducts/OpenTag>).

I'm interested in adding SnowPlow support to this
(<https://github.com/snowplow/snowplow>) - our tracking API is very similar to
Google Analytics's.

We've just gone through the quite involved exercise of mapping SnowPlow to
Google Tag Manager ([http://snowplowanalytics.com/blog/2012/11/16/integrating-
sno...](http://snowplowanalytics.com/blog/2012/11/16/integrating-snowplow-
with-google-tag-manager/)) so I was a bit surprised in the code to see this
mapping for GA events:

    
    
        track : function (event, properties) {
                    window._gaq.push(['_trackEvent', 'All', event]);
                }
    

I'm a bit confused by this - how would I use analytics.js to pass through all
the valid data that I can log in a GA event or indeed SnowPlow event -
[https://github.com/snowplow/snowplow/wiki/javascript-
tracker...](https://github.com/snowplow/snowplow/wiki/javascript-tracker#wiki-
events)

I think you might be making the assumption that events consist of an event
name plus arbitrary JSON envelope. This is a very MixPanelish view of the
world - it doesn't really translate to Google Analytics, Piwik, SnowPlow,
Omniture...

~~~
ianstormtaylor
Really good points. I think there is definitely a way for the Mixpanel-esque
API to map cleanly via a decided on spec to the GA-style API with 'category'
and 'label'. We are thinking about how to solve this in the nicest way
possible for the developer right now!

~~~
alexatkeplar
It's going to be really hard to make a generic, non-lossy mapping in a static,
stateless JS script. Have you looked at Google's dataLayer as an alternative
yet? The setup guide for SnowPlow + dataLayer is here in case it's
interesting: [https://github.com/snowplow/snowplow/wiki/Integrating-
javasc...](https://github.com/snowplow/snowplow/wiki/Integrating-javascript-
tags-with-Google-Tag-Manager)

The dataLayer approach seems really sound to us - here's hoping other tag
management solutions move to something similar (or standardise on Google's
dataLayer API).

------
hayksaakian
It's ironic that HN can simultaneously abhor[1] and applaud[this] progressive
invasions of privacy on the internet.

[1] <http://news.ycombinator.com/item?id=4907609>

~~~
lazerwalker
I'd disagree that it's a natural progression to move from collecting anonymous
(or at least pseudo-anonymous) use data from what your users actively do on
your web site (which is very useful for measuring usage and making design
improvements) to cross-referencing that with data your users did _not_ give
you for the explicit purpose of identifying them.

~~~
dchuk
There was a post on here a few weeks ago where people were specifically
blasting KISSMetrics for using an Evercookie style tracking system, so I'd
argue that HN hasn't come up with a coherent opinion of the moral implications
of analytics and conversion tracking yet.

------
bluesmoon
How does this script impact the performance of a site?

Specifically...

1\. It includes code to load up various analytics tools even if you never use
them. For example, if I only use GA and Mixpanel, do I really want to serve
the bytes for all the other plugins to my users? Maybe it would be useful to
only package the JavaScript that a certain site needs.

2\. The script still blocks the onload event. See this post for a way around
that: [http://calendar.perfplanet.com/2012/the-non-blocking-
script-...](http://calendar.perfplanet.com/2012/the-non-blocking-script-
loader-pattern/)

3\. How does having multiple analytics solutions on a page affect the load
time of that page?

Lastly, I couldn't tell from the docs how to call methods before the script
has finished loading. Is it similar to GA's method queue pattern?

~~~
Hovertruck
> It includes code to load up various analytics tools even if you never use
> them. For example, if I only use GA and Mixpanel, do I really want to serve
> the bytes for all the other plugins to my users? Maybe it would be useful to
> only package the JavaScript that a certain site needs.

It only has code that knows how to load each script, which isn't that much. So
for example if you don't tell it to load chartbeat.js, it will never load
chartbeat.js.

Regarding load time of pages, it's one thing we (Chartbeat) take really
seriously, e.g. our default implementation waits until after onload before
downloading anything and we keep our JS as light as possible. This script
does, unfortunately, throw some of that out the window with it's
implementation though. I'm working on my pull request already. :)

~~~
ianstormtaylor
Looking forward to it! Sorry to mess with your onload

------
mediascreen
Just remember that using email addresses as UserId string, like in the
example, is against the Google Analytics terms of service.

~~~
ianstormtaylor
Don't worry, that identify call never gets sent to GA

------
stdbrouw
Hm, I seem to recall Google used to ban third-party wrappers in their Terms of
Service, but I can't seem to find it in the ToS anymore – so either they've
softened up or I have a faulty memory.

------
karolisd
For event tracking, how does

analytics.track('Purchased an Item', { price : 39.95, shippingMethod : '2-day'
});

translate to Google Analytics?

_gaq.push(['...?

How many properties can you have?

~~~
ianstormtaylor
The Google Analytics provider doesn't send properties for events. The only
thing the GA API providers that's even close is a "Label" which is just a
string. The idea is to get as much from each provider as possible, so we just
don't send properties when a provider can't use them.

Hope that helps!

~~~
troels
There's the ecommerce api though, which would apply to this specific case.

[https://developers.google.com/analytics/devguides/collection...](https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce)

~~~
ianstormtaylor
Ah yep that's a good point. Trouble is it doesn't apply to all cases, and has
really strict requirements, but if it's a big enough need I could totally see
a .price() method that hits GA's ecommerce API and then delegates to other
providers's normal event API with properties. Wouldn't be a bad way to handle
it.

------
tarr11
I was hoping that this would be an open source version of Google Analytics.

~~~
smacktoward
You're looking for Piwik (<http://piwik.org/>), which is awesome.

~~~
arcatek
But ugly as hell. I mean, I would be willing to pay for getting them to work
on the design.

~~~
neumann_alfred
You can customize every last bit of it, it being open source. Feel free pay
them or someone else to do just that. Nobody would claim it's the prettiest,
but it's open source and self-hosted, surely that counts for something? The
devil will always have the shinier bling, but it's also the devil.

------
bluetidepro
This looks awesome! One thing would be nice on the demo/landing site is to
maybe add screenshots of how your examples translate in Google Analytics or
the others. Like _karolisd_ mentioned in his comment, I would like to see how
that stuff translates or what it looks like in the respective apps. Again,
great work! :)

------
sudonim
Happy to be supporting this project at <http://customer.io> . A lot of folks
who use other tools want it to be easier to send the same information to
everyone. Thanks guys for helping us all play nicer together.

------
dudus
Google Analytics has a new api currently in beta that is also called
analytics.js. This will be confusing.

[https://developers.google.com/analytics/devguides/collection...](https://developers.google.com/analytics/devguides/collection/analyticsjs/)

~~~
ry0ohki
Agreed. Please stick to the trend of a creative, whimsical, yet non-
descriptive name, I recommend "SealFur.js".

~~~
pud
How about shortening it to Anal.js

(seriously, that would be a great name. and, ya know, in reference to being
anal retentive. get your mind outta the gutter people.)

~~~
sgerrand
There's a typo on the README site that might indicate that they had similar
ideas: `Google Analtyics`

------
vtuulos
Great library! I know that a number of companies have created a wrapper of
their own exactly for this purpose.

We could contribute integration to <https://bitdeli.com> for those who want to
build their own analytics. Is it enough to add a new provider to
availableProviders?

~~~
pkrein
Yep, feel free to just pull request to the analytics.js repo.

------
rossta
Thanks for sharing. A useful improvement could be a build step that supplies
only the metrics snippets that I want so I don't need to deliver to clients
provider code I'll never use.

------
mguterl
I've been using analytical with our Rails backend which seems to achieve
something similar:

<https://github.com/jkrall/analytical>

------
madoublet
Really cool. But, I was kind of hoping the library would pull data from Google
analytics to use for charting and stats within an app.

------
donohoe
If this covered Omniture I'd be over the moon...

------
spaetzel
Awesome, I was thinking of writing something like this, but you took the idea
and made it much more powerful than i was planning.

------
Hovertruck
This is awesome! There's a few bugs in the Chartbeat implementation. Expect a
pull request soon! :)

------
novaleaf
Three words: Google Tag Manager.

------
davidradcliffe
I was just creating something like this for my project. This is great!!

------
karthik_ram
You didn't include gaug.es

------
benhamner
Web analytics just got meta

