Imagine a common scenario within Facebook:
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.
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.
Below is a walkway through of our same scenario, but showing what properties we would set and why.
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 treegeneration = 0 - Alex is the original originWe will then use the set method to set:
orig_person = the id of Alex, since Alex is the first personCreate 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 examplekm_orig_source = fb_ad1 - The original adkm_prev_source = fb_ad1 - The original ad is also the previous sourcekm_orig_person = Alex - Alex is the original personkm_prev_person = Alex - Alex is also the previous person for anyone who clicks this linkkm_generation = 1 - whoever clicks on this link will be generation 1So 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 = share1orig_source = fb_ad1prev_source = fb_ad1orig_person = Alexprev_person = Alexgeneration = 1Record your purchase event with KISSmetrics record method.
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 share1km_orig_source = fb_ad1 - The original ad - this never changeskm_prev_source = share1 - Betty got here from Alex’s share linkkm_orig_person = Alex - Alex is the original person - this never changeskm_prev_person = Betty - Anyone who click’s Betty’s link will need to be attributed to Bettykm_generation = 2 - whoever clicks on this link will be generation 2 because they are two steps from the originSo 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.
There are two distinct parts you will need to add code to your site for:
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:
km_source to an identifier that makes sense for the type of link you are generating (e.g. share1)km_orig_source to the value of km_orig_source in the current URLkm_prev_source to the value of km_source in the current URLkm_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 URLkm_prev_person to the value of the current identity of the current personkm_generation to the value of km_generation in the current URL incremented by oneBelow 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