Google Analytics Outbound Link Event Tracking

前端 未结 3 1417
我在风中等你
我在风中等你 2021-01-25 14:34

I\'m trying to set up event tracking so that I can track when someone goes to my \'about\' page and clicks on a link to my LinkedIn profile. Below is the link that I want tracke

3条回答
  •  温柔的废话
    2021-01-25 15:13

    First you need to add The JavaScript tracking snippet.

    
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
    
        ga('create', 'UA-XXXXX-Y', 'auto'); //you should definitely change your tracking ID
        ga('send', 'pageview');
    
    

    then we write our event function

    function handleOutboundLinkClicks(category, action, label) {
       ga('send', 'event', {
       eventCategory: category,
       eventAction: action,
       eventLabel: label
     });
    }
    

    Finally we call our function at the place we want

    CLICK ME
    

提交回复
热议问题