Lo jQuery lati Gbọ Ati Kọja Ṣiṣayẹwo Iṣẹlẹ Google Analytics Fun Eyikeyi Tẹ

jQuery Tẹtisi fun Awọn titẹ lati Kọja Ṣiṣayẹwo Iṣẹlẹ Google Analytics

O yà mi pe diẹ sii awọn iṣọpọ ati awọn ọna ṣiṣe ko pẹlu laifọwọyi Titele Iṣẹlẹ Google Analytics ninu wọn awọn iru ẹrọ. Pupọ ti akoko mi ti n ṣiṣẹ lori awọn aaye awọn alabara n ṣe idagbasoke titele fun Awọn iṣẹlẹ lati pese alabara pẹlu alaye ti wọn nilo lori kini awọn ihuwasi olumulo n ṣiṣẹ tabi ko ṣiṣẹ lori aaye naa.

Laipẹ julọ, Mo kowe nipa bi o ṣe le ṣe atẹle mailto jinna, tẹli tẹ, Ati Awọn ifisilẹ fọọmu Elementor. Emi yoo tẹsiwaju lati pin awọn ojutu ti MO nkọ pẹlu awọn ireti pe o ṣe iranlọwọ fun ọ lati ṣe itupalẹ aaye rẹ dara julọ tabi iṣẹ ohun elo wẹẹbu.

Apeere yii n pese ọna ti o rọrun pupọ ti iṣakojọpọ Titele Iṣẹlẹ Awọn atupale Google sinu aami oran eyikeyi nipa fifi nkan data kan kun ti o pẹlu Ẹka Iṣẹlẹ Google Analytics, Iṣẹ iṣẹlẹ Awọn atupale Google, ati Aami Iṣẹlẹ Awọn atupale Google. Eyi ni apẹẹrẹ ọna asopọ kan ti o ṣafikun eroja data, ti a pe iṣẹlẹ:

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

Ohun pataki ṣaaju fun aaye rẹ ni pẹlu jQuery ninu rẹ… eyiti iwe afọwọkọ yii ni agbara pẹlu. Ni kete ti oju-iwe rẹ ba ti kojọpọ, iwe afọwọkọ yii ṣafikun olutẹtisi si oju-iwe rẹ fun ẹnikẹni ti o tẹ lori nkan kan pẹlu iṣẹlẹ data… lẹhinna o ya ati ṣe itupalẹ ẹka, iṣe, ati aami ti o pato laarin aaye naa.

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

Akiyesi: Mo ti ṣafikun itaniji (ṣalaye jade) ki o le ṣe idanwo ohun ti o kọja.

Ti o ba n ṣiṣẹ jQuery lori Wodupiresi, iwọ yoo fẹ lati yi koodu naa pada diẹ diẹ nitori Wodupiresi ko ni riri ọna abuja $:

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

Kii ṣe iwe afọwọkọ ti o lagbara julọ ati pe o le nilo lati ṣe diẹ ninu mimọ-mimọ, ṣugbọn o yẹ ki o bẹrẹ!