smower
asked on
How do I Update Javascript Event Tracking Code to Not Track Internal Javascript Links as Outgoing Links in Google Analytics
Hello, I have been using the following javascript to track outgoing links on our asp.net website www.competitiveedgeproducts.com and it is working pretty good except that it is also tracking javascript links on the website that don't take people to another site as Outgoing links. For example it is tracking a lot of javascript links like this:
javascript:{if (typeof(Page_ClientValidat e) != 'function' || Page_ClientValidate()) __doPostBack('SearchTempla te13$DataG rid1$_ctl1 9$_ctl1',' ')}
and classifying them as an Outgoing Link which I don't want. Could anyone tell me what to change in this code to track internal javascript links as Internal links instead of outgoing links or not even track them with this code?
Thanks in advance!
Shawn
javascript:{if (typeof(Page_ClientValidat
and classifying them as an Outgoing Link which I don't want. Could anyone tell me what to change in this code to track internal javascript links as Internal links instead of outgoing links or not even track them with this code?
<script type="text/javascript">
/* Attach tracking to all download & external links */
var _gaq = _gaq || [];
function _gaLt(event){
var el = event.srcElement || event.target;
/* Loop up the tree through parent elements if clicked element is not a link (eg: an image in a link) */
while(el && (typeof el.tagName == 'undefined' || el.tagName.toLowerCase() != 'a' || !el.href))
el = el.parentNode;
if(el && el.href){
if(el.href.indexOf(location.host) == -1){ /* external link */
_gaq.push(["_trackEvent", "Outgoing Links", el.href, document.location.pathname + document.location.search]);
/* if target not set delay opening of window by 0.5s to allow tracking */
if(!el.target || el.target.match(/^_(self|parent|top)$/i)){
setTimeout(function(){
document.location.href = el.href;
}.bind(el),500);
/* Prevent standard click */
event.preventDefault ? event.preventDefault() : event.returnValue = !1;
}
}
}
}
/* Attach the event to all clicks in the document */
var d = document;
d.addEventListener ? d.addEventListener("click",_gaLt,!1) : d.attachEvent && d.attachEvent("onclick",_gaLt);
</script>
Thanks in advance!
Shawn
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok. It seems to be working in my limited tests so far. Thank you so much for your help on this!
ASKER
Thank you mplungjan,
Your suggestion sounds great also, but I am using an old asp.net 1.1 site and it seems to be generating those javascript links automatically and I am sure how to change those or comfortable trying to tweak that programmatic part of the code. The javascript change seems to be working so I am going to monitor those results for a while to see if it will keep performing properly.
Your suggestion sounds great also, but I am using an old asp.net 1.1 site and it seems to be generating those javascript links automatically and I am sure how to change those or comfortable trying to tweak that programmatic part of the code. The javascript change seems to be working so I am going to monitor those results for a while to see if it will keep performing properly.
change
<a href="javascript:{if (typeof(Page_ClientValidat
to
<a href="#" onclick="if (typeof(Page_ClientValidat