Sebenzisa i-jQuery ukuze ulalele futhi udlule ukulandelela umcimbi we-Google Analytics nganoma yikuphi ukuchofoza

I-jQuery Lalela Ukuchofoza Ukuze Udlule Ukulandelela Imicimbi Ye-Google Analytics

Kuyangimangaza ukuthi ukuhlanganiswa okwengeziwe namasistimu akubandakanyi ngokuzenzakalelayo I-Google Analytics Event Tracking ezinkundleni zabo. Isikhathi sami esiningi ngisebenza kumasayithi amaklayenti ngithuthukisa ukulandelela kwezehlakalo ukuze kunikeze iklayenti ulwazi eliludingayo mayelana nokuthi iziphi ukuziphatha kwabasebenzisi ezisebenzayo noma ezingasebenzi kusayithi.

Muva nje, ngibhale mayelana nendlela yokulandelela ukuchofoza kwe-mailto, tel ukuchofoza, Futhi Ukuhanjiswa kwefomu le-Elementor. Ngizoqhubeka nokwabelana ngezixazululo engizibhalayo ngethemba lokuthi zizokusiza ukuthi uhlaziye kangcono isayithi lakho noma ukusebenza kwesicelo sewebhu.

Lesi sibonelo sinikeza izindlela ezilula zokufaka Ukulandelelwa Komcimbi we-Google Analytics kunoma iyiphi ithegi yokunamathisela ngokungeza ingxenye yedatha ehlanganisa Isigaba Somcimbi Wezibalo Ze-Google, Isenzo Somcimbi We-Google Analytics, kanye Nelebula Lomcimbi we-Google Analytics. Nasi isibonelo sesixhumanisi esihlanganisa ingxenye yedatha, ebizwa Gaevent:

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

Imfuneko yesayithi lakho ihlanganisa i-jQuery kuyo... lesi script esinikwe amandla ngayo. Uma ikhasi lakho selilayishiwe, lesi sikripthi sengeza umlaleli ekhasini lakho kunoma ubani ochofoza into ngaye Gaevent idatha... bese ithwebula futhi ihlukanise isigaba, isenzo, bese ilebula oyicacisayo ngaphakathi kwenkundla.

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

Isaziso: Ngifake isexwayiso (ubeke amazwana) ukuze uhlole ukuthi yini ephumelele ngempela.

Uma usebenzisa i-jQuery ku-WordPress, uzofuna ukulungisa ikhodi kancane njengoba i-WordPress ingasijabuleli isinqamuleli se-$:

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

Akusona iskripthi esiqine kakhulu futhi ungase udinge ukwenza ukuhlanza okwengeziwe, kodwa kufanele kukwenze uqalise!