Guest User

Untitled

a guest
Jul 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1.  
  2. var addTrackToLink = function() {
  3. var anchor = new RegExp(location.href + "#.*?");
  4. var js = /^javascript\:/;
  5. return function(link) {
  6. var handler = link.readAttribute('onclick');
  7. var href = link.href;
  8. if (handler === null && !anchor.test(href) && !js.test(href)) {
  9. var action = href.match(/http?:\/\/([^\/]+)\//)[1];
  10. link.writeAttribute('onclick', "javascript:_gaq.push(['_trackEvent', 'outbound-article', '" + action + "'])");
  11. }
  12. };
  13. }();
  14.  
  15. document.observe('dom:loaded', function(event) {
  16. $$('a').each(addTrackToLink);
  17. }, false);
  18.  
  19. document.observe('DOMNodeInserted', function(event) {
  20. $(event.target).select('a').each(addTrackToLink);
  21. }, false);
Add Comment
Please, Sign In to add comment