Jiri jQuery gee ntị wee nyefee ihe omume Google Analytics maka Pịa ọ bụla

jQuery Gee ntị maka ọpịpị ka ịgafe ihe omume nyocha Google

Ọ tụrụ m n'anya na njikọta na sistemụ anaghị agụnye akpaghị aka Nyocha mmemme Google Analytics n'ime ikpo okwu ha. Ọtụtụ n'ime oge m na-arụ ọrụ na saịtị ndị ahịa na-emepụta nsochi maka Ihe omume iji nye onye ahịa ozi ha chọrọ gbasara àgwà ndị ọrụ na-arụ ọrụ ma ọ bụ na-adịghị arụ ọrụ na saịtị ahụ.

Kachasị nso nso, M dere banyere otú soro mailto clicks, tel pịa, na Mpempe akwụkwọ elementor. M ga-aga n'ihu na-ekerịta azịza ndị m na-ede na-atụ anya na ọ ga-enyere gị aka nyochaa saịtị gị ma ọ bụ ngwa weebụ nke ọma.

Ihe atụ a na-enye ụzọ dị mfe isi tinye Google Analytics Event Tracking n'ime mkpado arịlịka ọ bụla site n'ịgbakwụnye ihe data nke gụnyere ngalaba Omume Google Analytics, Omume Omume Google Analytics, na Google Analytics Event Label. Nke a bụ ọmụmaatụ nke njikọ nke na-agụnye mmewere data, nke a na-akpọ omume:

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

Ihe dị mkpa maka saịtị gị gụnyere jQuery n'ime ya… nke ejiri ya kwado edemede a. Ozugbo ebudatara ibe gị, edemede a na-agbakwunye onye na-ege ntị na ibe gị maka onye ọ bụla na-pịa ihe nwere omume data… wee weghara ma tụsaa udi, mmemme na labelụ ị depụtara n'ime ubi ahụ.

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

Rịba ama: Etinyela m njikere (kwupụtara) ka ị nwee ike nwalee ihe agafere n'ezie.

Ọ bụrụ na ị na-agba jQuery na WordPress, ị ga-achọ ịgbanwe koodu ahụ ntakịrị ntakịrị ebe WordPress enweghị ekele maka ụzọ mkpirisi $:

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

Ọ bụghị script kacha sie ike na ị nwere ike ịme nchacha ọzọ, mana ọ kwesịrị ịmalite!