Fa'aoga le jQuery e Fa'alogo ma Pasia le Su'esu'ega o Mea e tutupu i Google Analytics mo So'o se Kiliki

jQuery Fa'alogo mo Kiliki e Pasia ai le Su'esu'ega o Mea e tutupu i Google Analytics

Ou te ofo ona o le tele o tu'ufa'atasiga ma faiga e le otometi ona aofia ai Google Analytics Su'esu'ega Mea i o latou tulaga. O le tele o lo'u taimi e galue ai i luga o upegatafa'ilagi a tagata o lo'o atia'e su'esu'ega mo Mea e fai e tu'uina atu ai i le kalani fa'amatalaga latou te mana'omia i amioga a tagata fa'aoga o lo'o galue pe le o galue i luga o le saite.

Talu ai nei lava, na ou tusia ai e uiga i le auala e siaki ai mailto kiliki, tel kiliki, ma Tuuina atu fomu Elementor. O le a ou faʻaauau pea ona faʻasoa fofo o loʻo ou tusia ma le faʻamoemoe e fesoasoani ia te oe e faʻaleleia atili ai au suʻesuʻega o lau 'upega tafaʻilagi poʻo le' upega tafaʻilagi faʻatinoga.

O lenei faʻataʻitaʻiga e maua ai se auala faigofie tele o le faʻaogaina o Google Analytics Event Tracking i soʻo se taula taula e ala i le faʻaopoopoina o se elemene faʻamaumauga e aofia ai le Google Analytics Event Category, Google Analytics Event Action, ma Google Analytics Event Label. O se faʻataʻitaʻiga lea o se soʻotaga e aofia ai le elemene faʻamaumauga, e taʻua gaevent:

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

O se mea e manaʻomia muamua mo lau 'upega tafaʻilagi e aofia ai le jQuery i totonu ... lea e faʻamalosia ai lenei tusitusiga. O le taimi lava e utaina ai lau itulau, o lenei tusitusiga e faʻaopoopoina se tagata faʻalogo i lau itulau mo soʻo se tasi e kiliki i luga o se elemene gaevent data… ona pu'eina lea ma fa'avasega le vaega, gaioiga, ma le fa'ailoga e te fa'ailoaina i totonu o le fanua.

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

Fa'aaliga: Ua ou fa'aofiina se mataala (fa'ailoa mai) ina ia mafai ai ona e su'eina le mea moni na pasi.

Afai o loʻo e faʻaogaina le jQuery i luga o le WordPress, e te manaʻo e sui le code na o sina mea itiiti talu ai e le talisapaia e WordPress le $ shortcut:

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

E le o se tusitusiga sili ona malosi ma atonu e te manaʻomia le faia o se faʻamama faʻaopoopo, ae e tatau ona e amata!