E hoʻohana i ka jQuery e hoʻolohe a hāʻawi i ka huli ʻana i nā hanana hanana Google Analytics no kēlā me kēia kaomi

jQuery E hoʻolohe i nā kaomi e hala i ka nānā ʻana i nā hanana hanana Google Analytics

Pīhoihoi au no ka hoʻohui ʻana a me nā ʻōnaehana ʻaʻole hoʻokomo aunoa Ka Hoʻokolo ʻana o Google Analytics ma ko lakou mau paepae. ʻO ka hapa nui o koʻu manawa e hana ana ma nā pūnaewele o nā mea kūʻai aku e hoʻomohala ana i ka nānā ʻana i nā hanana e hāʻawi i ka mea kūʻai aku i ka ʻike e pono ai lākou e pili ana i nā ʻano mea hoʻohana e hana nei a ʻaʻole hana paha ma ka pūnaewele.

ʻO ka mea hou loa, ua kākau wau e pili ana i ka hahai ʻana mailto kaomi, kī kelepona, a Nā hoʻouna palapala Elementor. E hoʻomau wau i ka hāʻawi ʻana i nā haʻina aʻu e kākau nei me ka manaʻolana e kōkua ia iā ʻoe e hoʻomaʻamaʻa maikaʻi i kāu pūnaewele a i ʻole ka hana noi pūnaewele.

Hāʻawi kēia hiʻohiʻona i kahi ala maʻalahi loa o ka hoʻokomo ʻana i ka Google Analytics Event Tracking i loko o kahi hōʻailona heleuma ma ka hoʻohui ʻana i kahi mea ʻikepili e komo pū ana me ka Google Analytics Event Category, Google Analytics Event Action, a me Google Analytics Event Label. Eia kekahi laʻana o kahi loulou e hoʻokomo i ka ʻikepili ʻikepili, i kapa ʻia huikau:

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

ʻO kahi koi mua no kāu pūnaewele e hoʻokomo i ka jQuery i loko… kahi i hoʻohana ʻia ai kēia palapala. Ke hoʻouka ʻia kāu ʻaoʻao, hoʻohui kēia palapala i kahi mea hoʻolohe i kāu ʻaoʻao no ka mea e kaomi ana i kahi mea me huikau ʻikepili… a laila hopu a paʻi i ka waeʻano, hana, a me ka lepili āu i kuhikuhi ai i loko o ke kahua.

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

'Ōlelo Aʻo: Ua hoʻokomo au i kahi makaʻala (manaʻo mai) i hiki iā ʻoe ke hoʻāʻo i ka mea i hala maoli.

Inā ʻoe e holo ana i ka jQuery ma WordPress, makemake ʻoe e hoʻololi iki i ke code no ka mea ʻaʻole mahalo ʻo WordPress i ka pōkole $:

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

ʻAʻole ia ka palapala ʻoi loa a pono paha ʻoe e hana i kahi hoʻomaʻemaʻe hou aku, akā pono e hoʻomaka ʻoe!