Tracking the generational/viral effects of the Like button
Note: I'm sure a ton of people do this, and I'm sure it's been documented before..but a quick search for "generational effects like button" yielded nothing interesting on the top half of the first page of the search results so imma write this.
Sometimes when your shit goes viral it would be nice to measure HOW viral..how is the fanout. Someone "likes" your page. Then it posts a Like story to Facebook. Their friends see it and click the link. Then they hit "like" too. And so on and so on. Your site starts getting a ton of hits, life is awesome. But how awesome was it really? Did a ton of poeple find it organically on thier own and then liked it? Or was it more of a viral thing where people saw the Like story and clicked. And how many "generations" did it go through before it started dying out?
Turns out there's a sweet way to Make This Happen. Check out this code snippet for a Like button:
I removed all the javascript part of it, but you get the gist (HAR!). When a user clicks this like button, it will create a story on their newsfeed. If their friends see it and click on it, they'll be taken to http://themostawesomewebsiteevar.com and life is good. But now check out this version:
Looks identical, right? But there is a ref="1" tacked on there. What does it mean? Well this time, when a friend clicks the story, they are taken to http://themostawesomewebsiteeavar.com?fb_ref=1&fb_source=home. BOOM. Now you can track if the visitor came in organically, or if they came in because someone clicked on a post in their newsfeed. fb_source can also tell you if they clicked on it from a person's profile, or other places, but that's not important now. What if fb_ref could increment on every generation? Then you would be able to tell if someone visited the page because someone clicked "Like," then their friend saw it and clicked "Like," then THEIR friend saw it and clicked "Like" etc etc etc.
You now have a way of measuring your Like viral fanout. You could compile stats saying "x thousand pageviews came from a 1st generation like story, y thousand pageviews came from a 2nd generation like story, z bazillion pageviews came from a 3rd generation like story." Neato.
So how do you do this autoincrementing magic? Check out this snippet written using Javascript using nodejs, the expressjs framework, and the mustache templating language:
The server reads the querystring param if it exists, and increments the generation count. Then my like button code in my mustache template file would like this:
Neat huh? That ref parameter can be expanded to do more than just track a generation. It could hold a hash value to some table in your database which tracks much more. The sky is the limit. The possibilities are endless. The world is your oyster. Take a look, it's in a book, reading rainbow.
Docs for the Like Button are here.
