Whakamahia te jQuery ki te whakarongo me te tuku i a Google Analytics Takahanga Aroturuki mo te paato

jQuery Whakarongo mo nga Pawhiri ki te Paahi i te Aroturuki Takahanga a Google Analytics

Kei te miharo ahau he maha nga whakaurunga me nga punaha kaore i te whakauru aunoa Aroturuki Takahanga a Google Analytics i roto i o ratou turanga. Ko te nuinga o taku wa e mahi ana i runga i nga pae a nga kiritaki kei te whakawhanake i te whainga mo nga Takahanga hei whakarato ki te kiritaki nga korero e hiahiatia ana e ia mo nga whanonga kaiwhakamahi e mahi ana, kaore ranei e mahi ana i runga i te pae.

Ina tata nei, i tuhi ahau me pehea te whai mailto pao, pawhiri tel, a Elementor puka tukunga. Ka haere tonu ahau ki te tiritiri i nga otinga e tuhia ana e au me te tumanako ka awhina koe ki te tātari pai ake i to mahinga paetukutuku, tono paetukutuku ranei.

Ko tenei tauira e whakarato ana i tetahi huarahi tino ngawari ki te whakauru i te Aroturuki Takahanga a Google Analytics ki tetahi tohu punga ma te taapiri i tetahi huānga raraunga kei roto ko te Kawai Takahanga a Google Analytics, Google Analytics Event Action, me te Tapanga Takahanga a Google Analytics. Anei he tauira o te hono e whakauru ana i te huānga raraunga, e kiia nei takahanga:

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

Ko te tikanga mo to papaanga ko te whakauru i te jQuery ki roto… kei roto i tenei tuhinga te mana. Kia utaina to wharangi, ka taapirihia e tenei tuhinga he kaiwhakarongo ki to wharangi mo te tangata e pa ana ki tetahi huānga takahanga raraunga… ka hopuhia, ka poroporoaki i te waahanga, mahi, me te tapanga ka tohua e koe i roto i te mara.

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

Panui: Kua whakauruhia e ahau he matohi (i korero mai) kia taea ai e koe te whakamatautau i nga mea kua paahitia.

Mena kei te whakahaere koe i te jQuery i runga i te WordPress, ka hiahia koe ki te whakarereke i te waehere i te mea kaore a WordPress e aro ki te $ pokatata:

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

Ehara i te mea te tuhinga tino pakari, a tera pea me mahi etahi atu horoi, engari me timata koe!