Tracking 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:

  • Calculate how much revenue a specific channel generates both directly and indirectly
  • Attribute Betty and Charles’ activity to the original ad that Alex saw
  • Determine the total activity a single Like/Share/Facebook ad can generate
  • Discover the Viral Factor or average number of re-Likes/re-Shares at each level in the viral tree

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.

  • source - How the current person got here, which is an identifier you designate for each Ad, Like, Share link.
  • orig_source - This is the original source (the initial Ad/Like/Share). Once set it will never be changed no matter how man levels of people we track.
  • prev_source - This is the source that the current person got here from. For the first person this will be blank. For the second person it will be the source of the first person. For the third person it will be the source of the second person and so on.
  • orig_person - This is the id of the original person. Like the orig_source once set it will never change.
  • prev_person - This is the id of the person that created the link that the current person clicked on. For the first person this will be blank, for the second person it will be the id of the first person, for the third person it will be the id of the second person and so on.
  • generation - this is a numeric value that represents the “generation” or level in the virality tree. For the first person this value will be 0. Anyone who clicks the link generated by a generation 0 person will have a generation of 1. Anyone who clicks a link from a generation 1 person will have a generation of 2 and so on.

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:

  • source = the ad that Alex clicked on (fb_ad1)
  • orig_source = also set to fb_ad1 since Alex is first person in this viral tree
  • generation = 0 - Alex is the original origin

We will then use the set method to set:

  • orig_person = the id of Alex, since Alex is the first person

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

  • km_source = the special identifier you want to use for this Share or Like link. We are going to use share1 for this example
  • km_orig_source = fb_ad1 - The original ad
  • km_prev_source = fb_ad1 - The original ad is also the previous source
  • km_orig_person = Alex - Alex is the original person
  • km_prev_person = Alex - Alex is also the previous person for anyone who clicks this link
  • km_generation = 1 - whoever clicks on this link will be generation 1

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

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

  • source = share1
  • orig_source = fb_ad1
  • prev_source = fb_ad1
  • orig_person = Alex
  • prev_person = Alex
  • generation = 1

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:

  • km_source = the special identifier you want to use for this Share or Like link. We’ll assume that Betty is using the same Share as Alex so we will leave this as share1
  • km_orig_source = fb_ad1 - The original ad - this never changes
  • km_prev_source = share1 - Betty got here from Alex’s share link
  • km_orig_person = Alex - Alex is the original person - this never changes
  • km_prev_person = Betty - Anyone who click’s Betty’s link will need to be attributed to Betty
  • km_generation = 2 - whoever clicks on this link will be generation 2 because they are two steps from the origin

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

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()})
  }
});

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

  • Set km_source to an identifier that makes sense for the type of link you are generating (e.g. share1)
  • Set km_orig_source to the value of km_orig_source in the current URL
  • Set km_prev_source to the value of km_source in the current URL
  • Set km_orig_person to the value of km_orig_person in the current URL or the current identity of the current person if this is not set in the URL
  • Set km_prev_person to the value of the current identity of the current person
  • Set km_generation to the value of km_generation in the current URL incremented by one

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.km_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...
});

Creating Reports

With this setup, you’ll now have a number of properties at your disposal to help you segment your users’ activity. You can use these properties in any of our reportings tools. (We don’t have one specific report for examining only viral activity, but we may consider building one in the future.)

Let’s revisit the examples from earlier:

  • Calculate how much revenue a specific channel generates both directly and indirectly.

    Segment your Revenue Report by source and orig_source.

  • Attribute Betty and Charles’ activity to the original ad that Alex saw.

    Within your funnel or metric that examines activity (ie. the event “Logged In”), segment activity by orig_person.

  • Determine the total activity a single Like/Share/Facebook ad can generate.

    When reporting on activity (ie. the event “Logged In”), segment the funnel or metric by orig_source.

  • Discover the Viral Factor or average number of re-Likes/re-Shares at each level in the viral tree.

    Create a metric to display the Average Number of Likes or Average Number of Shares per Person. Segment that metric by generation.

You’re not limited to only these combinations! Try some others out - you may find the results very interesting.

Is anything on this page unclear? Suggest edits on Github!