
Re: How are outbound referals tracked?
Microsoft initiates the following code onLoad:
Code:
MicrosoftAnalytics.prototype.AttachLinkEvent=function(){
var mouseEvent="onclick";
for(var i=0;i<document.links.length;i++){
document.links[i].LoggingObject=this;
if(typeof(document.links[i][mouseEvent])!="function"&&document.links[i].href.indexOf("javascript:")<0){document.links[i][mouseEvent]=this.OnTrackLink;
} else{
}
}
};
The OnTrackLink function is called whenever a user clicks a link calling the follwing:
Code:
MicrosoftAnalytics.prototype.OnTrackLink=function(evt){
var srcElement=typeof(event)!="undefined"&&$assertValue(event)?event.srcElement:this;
if(srcElement.tagName!="A"){
do{
srcElement=$assertValue(srcElement.parentElement)?srcElement.parentElement:srcElement.parentNode;
}
while($assertValue(srcElement)&&srcElement.tagName!="A");
}
var loggingObject=srcElement.LoggingObject;
if(loggingObject==null){return true;
} var urlPath=srcElement.pathname;
var dotIndex=urlPath.lastIndexOf(".");
var foundMatch=false;
if(dotIndex>=0){
var fileExt=urlPath.substring(dotIndex+1);
if(srcElement.LoggingObject.Extensions){
foundMatch=loggingObject.Extensions.Find(fileExt)!=null;
}
}
if(!foundMatch&&srcElement.host.indexOf(location.host)>=0){
return true;
} if(!$assertValue(loggingObject.Links)){loggingObject.Links=new List();
loggingObject.Taxonomy.Add("Links","lnk",ListNodeType.Variable);
} loggingObject.Links.Add(srcElement.href,new SimpleLink(srcElement.href,foundMatch?LinkType.Download:LinkType.Outbound));
var eventPayload=loggingObject.SubmitPayload(PayloadType.Link);
if($assertValue(eventPayload)){
loggingObject.ImageRequest(eventPayload);
} if(loggingObject.EnableLinkTimeout==true){loggingObject.PauseLink(loggingObject.LinkTimeout);
} return true;
};
This basically asings all urlPaths clicked to the srcElement object, which is then tracked and sent to the MS analytics database to later show in your data.
This is a very brief explanation of the code found in the javascript (that is loaded in each page to be tracked) but it explains the basics.
Any better explanations are welcome!