Track all outbound links in Google Analytics

前端 未结 7 1817
小蘑菇
小蘑菇 2021-01-31 20:06

I\'ve been using a script to track outbound links for a couple of months now. The script WORKS, but in the report generated by Google Analytics many UR

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-31 20:52

    This small piece of code worked for me :

        var hostname = window.location.hostname; 
    
        jQuery("body a").click(function(){
    
              if(jQuery(this).attr("href").indexOf(hostname)== -1){
    
                   ga('send', 'event', {'eventCategory': "Outbound Links", 'eventAction': "OnClick", 'eventLabel': jQuery(this).attr("href")});
    
              }
        });
    

提交回复
热议问题