Gwiritsani ntchito jQuery kuti Mumvetsere ndi Kudutsa Kutsata Zochitika za Google Analytics Pakudina Kulikonse

jQuery Mverani Kuti Mudutse Kutsata Zochitika za Google Analytics

Ndine wodabwitsidwa kuti zophatikizika zambiri ndi machitidwe sizimangophatikiza Kutsata Zochitika za Google Analytics m'mapulatifomu awo. Nthawi yanga yambiri ndikugwira ntchito pamasamba amakasitomala ndikupanga zolondolera za Zochitika kuti apatse kasitomala zidziwitso zomwe amafunikira pazomwe machitidwe akugwiritsa ntchito kapena osagwira ntchito patsamba.

Posachedwapa, ndinalemba za momwe mungalondolere kudina kwa mailto, tel kudinandipo Ma fomu a Elementor. Ndipitiliza kugawana nawo mayankho omwe ndikulemba ndikuyembekeza kuti zimakuthandizani kusanthula bwino tsamba lanu kapena momwe mungagwiritsire ntchito tsamba lanu.

Chitsanzochi chimapereka njira zosavuta zophatikizira Google Analytics Event Tracking mu tag iliyonse ya nangula powonjezera deta yomwe ili ndi Google Analytics Event Category, Google Analytics Event Action, ndi Google Analytics Event Label. Nachi chitsanzo cha ulalo womwe umaphatikizapo data element, yotchedwa gaevent:

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

Chofunikira pa tsamba lanu ndikuphatikiza jQuery momwemo… yomwe script iyi imayendetsedwa nayo. Tsamba lanu litatsitsidwa, script iyi imawonjezera womvera patsamba lanu kwa aliyense amene akudina chinthucho gaevent data… ndiye imagwira ndikugawa gulu, zochita, ndikulemba zomwe mwafotokoza m'mundamo.

<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>

Zindikirani: Ndaphatikiza chenjezo (ndapereka ndemanga) kuti mutha kuyesa zomwe zadutsa.

Ngati mukugwiritsa ntchito jQuery pa WordPress, mudzafuna kusintha kachidindo pang'ono popeza WordPress sayamikira njira yachidule ya $:

<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>

Silemba lolimba kwambiri ndipo mungafunike kuyeretsa, koma liyenera kukuyambitsani!