Siv jQuery los mloog thiab hla Google Analytics Event Tracking Rau Txhua Nyem

jQuery Mloog rau Nyem kom dhau Google Analytics Event Tracking

Kuv xav tsis thoob tias kev sib koom ua ke ntau dua thiab cov tshuab tsis tuaj yeem suav nrog Google Analytics Event Tracking hauv lawv lub platform. Ntau ntawm kuv lub sijhawm ua haujlwm ntawm cov neeg siv cov vev xaib tab tom txhim kho kev taug qab rau Cov Txheej Txheem los muab cov ntaub ntawv rau cov neeg siv khoom uas lawv xav tau ntawm tus neeg siv tus cwj pwm ua haujlwm lossis tsis ua haujlwm ntawm lub xaib.

Tsis ntev los no, kuv tau sau txog yuav ua li cas taug qab mailto clicks, xov clicks, Thiab Elementor daim ntawv xa tuaj. Kuv yuav mus txuas ntxiv qhia cov kev daws teeb meem uas kuv tau sau nrog kev cia siab tias nws yuav pab koj txheeb xyuas koj qhov chaw lossis lub vev xaib ua haujlwm tau zoo.

Qhov piv txwv no muab ib txoj hauv kev yooj yim heev ntawm kev koom nrog Google Analytics Event Tracking rau hauv ib qho chaw thauj tog rau nkoj los ntawm kev ntxiv cov ntaub ntawv uas suav nrog Google Analytics Event Category, Google Analytics Event Action, thiab Google Analytics Event Label. Ntawm no yog ib qho piv txwv ntawm qhov txuas uas suav nrog cov ntaub ntawv, hu ua gaev:

<a href="#" data-gaevent="Category,Action,Label">Click Here</a>

Ib qho yuav tsum tau ua ua ntej rau koj lub xaib yog suav nrog jQuery hauv nws… uas tsab ntawv no tau siv nrog. Thaum koj nplooj ntawv yog loaded, tsab ntawv no ntxiv ib tug mloog rau koj nplooj ntawv rau leej twg nyem rau ntawm ib lub caij nrog gaev cov ntaub ntawv… ces nws captures thiab parses cov qeb, ua, thiab daim ntawv lo uas koj teev nyob rau hauv lub teb.

<script>
  $(document).ready(function() {      
    $(document).on('click', '[data-gaevent]', function(e) {
      var $link = $(this);
      var csvEventData = $link.data('gaevent');
      var eventParams = csvEventData.split(',');
      if (!eventParams) { return; }
        eventCategory = eventParams[0]
        eventAction = eventParams[1]
        eventLabel = eventParams[2]
        gtag('event',eventAction,{'event_category': eventCategory,'event_label': eventLabel})
        //alert("The Google Analytics Event passed is Action: " + eventAction + ", Category: " + eventCategory + ", Label: " + eventLabel);
    });
  });
</script>

Daim Ntawv Ceeb Toom: Kuv tau suav nrog kev ceeb toom (hais tawm) kom koj tuaj yeem kuaj qhov tau dhau los.

Yog tias koj tab tom khiav jQuery ntawm WordPress, koj yuav xav hloov cov cai me ntsis vim WordPress tsis txaus siab rau $ shortcut:

<script>
  jQuery(document).ready(function() {      
    jQuery(document).on('click', '[data-gaevent]', function(e) {
      var $link = jQuery(this);
      var csvEventData = $link.data('gaevent');
      var eventParams = csvEventData.split(',');
      if (!eventParams) { return; }
        eventCategory = eventParams[0]
        eventAction = eventParams[1]
        eventLabel = eventParams[2]
        gtag('event',eventAction,{'event_category': eventCategory,'event_label': eventLabel})
        //alert("The Google Analytics Event passed is Action: " + eventAction + ", Category: " + eventCategory + ", Label: " + eventLabel);
    });
  });
</script>

Nws tsis yog tsab ntawv uas muaj zog tshaj plaws thiab tej zaum koj yuav tau ua qee qhov kev ntxuav ntxiv, tab sis nws yuav tsum tau pib koj!