Sebenzisa i-jQuery ukuMamela kwaye uPhume ukuTreyithwa koMsitho we-Google Analytics kuyo nayiphi na into yokucofa

I-jQuery Mamela uKucofa ukuze uPhume ukuJonga ukuJongwa kweMisitho ye-Google Analytics

Ndiyamangalisa ukuba udibaniso oluninzi kunye neenkqubo azibandakanyi ngokuzenzekelayo Ukulandelela uMnyhadala woHlalutyo lukaGoogle kumaqonga abo. Uninzi lwexesha lam elisebenza kwiisayithi zabathengi liphuhlisa ukulandelwa kweMisitho ukubonelela umxhasi ngolwazi abaludingayo malunga nendlela yokuziphatha komsebenzisi esebenzayo okanye engasebenzi kwisayithi.

Kutshanje, ndibhale malunga nendlela yokulandelela mailto ucofa, umnxeba ucofa, yaye Ukungeniswa kwefomu ye-elementor. Ndiza kuqhubeka nokwabelana ngezisombululo endizibhalayo ngethemba lokuba ziyakunceda ukuba uhlalutye ngcono indawo yakho okanye ukusebenza kwesicelo sewebhu.

Lo mzekelo ubonelela ngeendlela ezilula kakhulu zokubandakanya i-Google Analytics Event Tracking kuyo nayiphi na ithegi ye-anchor ngokongeza into yedatha equka iCandelo leSigigaba se-Google Analytics, i-Google Analytics Event Action, kunye ne-Google Analytics Event Label. Nanku umzekelo wekhonkco elibandakanya into yedatha, ebizwa gaevent:

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

Imfuneko yesayithi yakho iquka i-jQuery kuyo... esi script sinikwe amandla ngayo. Nje ukuba iphepha lakho lilayishiwe, esi script songeza umphulaphuli kwiphepha lakho kuye nabani na ocofa into enayo gaevent data... emva koko ibambe kwaye yahlulahlula udidi, intshukumo, kunye neleyibhile oyichazayo ngaphakathi kwendawo.

<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: Ndifake isilumkiso (uhlomle) ukuze uvavanye ukuba yintoni na ephumeleleyo.

Ukuba usebenzisa i-jQuery kwi-WordPress, uya kufuna ukuyiguqula ikhowudi nje kancinci kuba i-WordPress ayiyixabisi i-shortcut ye- $:

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

Ayisosona script sinamandla kwaye unokufuna ukwenza ucoceko olongezelelweyo, kodwa kufuneka uqalise!