Implementing multiple link tracking

145 views Asked by At

In adobe analytics for a liniking tracking I am using this

<a href="http://www.google.com/" onClick="s.tl(this,'e','google', null,'navigate');return false"> test </a>

If I have many links in my code and I want to make the same for all of them how is it possible to use one fuction for the onClick event for all links I have in code?

2

There are 2 answers

2
michelem On

This should work with native javascript, without any external library needed

var links = document.links;

for(var i = 0; i < links.length; i++) {
  links[i].addEventListener('click', function(e) {
    e.preventDefault();
    s.tl(this,'e','google', null,'navigate');return false
  });
}
0
Mark Stringham On

You can control your exit links a few different ways but a simple one would be to set s.linkInternalFilters.

s.linkInternalFilters = "javascript:" 
// will send all link clicks (except a "javascript" match) as exits 
s.linkInternalFilters = "javascript:,my-site.com" 
// will send all link clicks (except a "javascript" match or "my-site.com") as exits.