Tracking Facebook Virality

Imagine a common scenario within Facebook:

  1. Alex clicks on a Facebook ad and visits your site
  2. Alex is convinced to click a “Like” or “Share” button related to your products/services
  3. Betty clicks the link from within Alex’s feed which takes Betty to your site
  4. Betty then makes a purchase
  5. Betty shares this purchase on Facebook
  6. Charles then clicks this link, and so on…

As you can see only a single user clicked the actual ad (Alex), but Betty visited because of Alex, and Charles visited because of Betty. So if you are looking at a simple model you will only attribute Alex’s activity to your ad, but in reality without that ad you may not have gotten Betty or Charles.

There are several things that you may want to do in this situation:

KISSmetrics provides the tools to be able to track and answer these questions provided you are willing to do a little extra. What follows is a practical how-to guide.

Properties to Track

There are several custom properties we will need to track, which are below. If you are new to KISSmetrics, please see People, Events and Properties first.

For information on how set custom properties please see our various APIs.

Walk-Thru

Below is a walkway through of our same scenario, but showing what properties we would set and why.

1. Alex clicks on a Facebook ad and visits your site

You might tag your ad with a URL param to identify that the visit came from Facebook. This might look like:

http://yoursite.com/promo?kme=Visited+Promo&km_source=fb_ad1 //-
  &km_generation=0&km_orig_source=fb_ad1

This will record an event called Visited Promo and will then set the following properties for Alex:

We will then use the set method to set:

2. Alex is convinced to click a “Like” or “Share” button related to your products/services

Create a custom link with URL parameters that contains the following information:

So the link for the URL that Alex shares that links back to your site might look like:

 http://yoursite.com/promo?kme=Visited+Promo&source=share1 //-
    &km_orig_source=fb_ad1&km_km_prev_source=fb_ad1 //-
    &km_orig_person=Alex&km_prev_person=Alex&km_generation=1

3. Betty clicks the link from within Alex’s feed which takes Betty to your site

We will read the params from the URL. We will then set the following properties for Betty:

4. Betty then makes a purchase

Record your purchase event with KISSmetrics record method.

5. Betty shares this purchase on Facebook

We need to create a new URL for Betty to share. This might look like:

So the link for the URL that Betty shares that links back to your site might look like:

 http://yoursite.com/promo?kme=Visited+Promo&source=share1 //-
    &km_orig_source=fb_ad1&km_km_prev_source=share1 //-
    &km_orig_person=Alex&km_prev_person=Betty&km_generation=2

6. Charles then clicks this link, and so on…

We will read the information from the URL to set the properties for Charles and then create a new link for Charles to share.

Example Code

There are two distinct parts you will need to add code to your site for:

  1. Recording of events/properties as traffic comes in
  2. Creation of custom Like/Share links

Recording Events/Properties

If you tag your URLs use the URL API then all the setting and recording of events will be taken care of for you automatically. However, for people who click your initial ad then the orig_person property will not be set (see step 1 in the example above) so you will need to detect that and set it. The following Javascript will do that:

_kmq.push(function(){
  // Get the parts of the current URL
  var currentURL = KM.uprts(KM.u());
  if  ( !currentURL.params.km_orig_person )
  {
    // So the orig_person is not available in the URL so we need to set it
    // to the identity of the current person
    KM.set({'orig_person': KM.i()})
  }
});

Link Creation

When generating the links that you will use for your Share/Like URLs you will need to use the following logic:

Below is some example Javascript code, which will need to be modified for your specific needs:

// Define a global shareURL variable to hold the URL of our share URL 
// if the current person decides to Share on Facebook
var shareURL = "http://yoursite.com/promo";

_kmq.push(function(){
  // Get the parts of the current URL
  var currentURL = KM.uprts(KM.u());
  // Create a hash to store the new params for our new URL
  var params = {};
  // Set the source to something that makes sense for you
  params.source = "share1";
  // Pass through the original source
  params.km_orig_source = currentURL.params.km_orig_source;
  // Set the previous source to the "source" in the current URL
  params.km_prev_source = currentURL.params.km_source;
  // Pass through the original person or set to the current identity if 
  // not in the URL
  params.km_orig_person = currentURL.params.km_orig_person || KM.i();
  // Set the previous person to the identity of the current person
  params.km_prev_person = KM.i();
  // Set generation to the value of `km_generation` in the current URL
  // incremented by one
  params.km_generation = parseInt(currentURL.params.km_generation, 10)+1
  // Create the URL, using the KM.p function which turns a hash into
  // a set of URL params
  shareURL += "?"+KM.p(params);
  
  // Now use the shareURL in your Facebook sharing code...
});

Filed under Advanced

Search


Learn more about KISSmetrics

Get started now