Yi amfani da jQuery don Saurara Kuma Wuce Bibiyar Abubuwan Bidiyo na Google Analytics Ga kowane Dannawa

jQuery Saurari Dannawa don Wuce Bibiyar Abubuwan Abubuwan Google Analytics

Na yi mamakin cewa ƙarin haɗin kai da tsarin ba sa haɗawa ta atomatik Binciken Bibiyar Abubuwan Taro na Google Analytics a dandalinsu. Yawancin lokaci na yin aiki akan rukunin yanar gizon abokan ciniki yana haɓaka bin diddigin abubuwan da suka faru don samarwa abokin ciniki bayanan da suke buƙata akan menene halayen mai amfani ke aiki ko rashin aiki akan rukunin.

Kwanan nan, na rubuta game da yadda ake waƙa mailto dannawa, tel dannawa, Da kuma Gabatar da fom na Elementor. Zan ci gaba da raba hanyoyin da nake rubutawa tare da fatan zai taimaka muku don yin nazarin rukunin yanar gizonku ko aikin yanar gizon ku.

Wannan misalin yana ba da hanya mai sauƙi na haɗa Google Analytics Bibiyar Bibiyar Abubuwan da ke faruwa a cikin kowane alamar anga ta ƙara wani ɓangaren bayanai wanda ya haɗa da Rukunin Abubuwan da suka faru na Google Analytics, Ayyukan Abubuwan Abubuwan Google Analytics, da Label na Event na Google Analytics. Ga misalin hanyar haɗin yanar gizo wacce ta ƙunshi ɓangaren bayanai, wanda ake kira aukuwa:

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

Abubuwan da ake buƙata don rukunin yanar gizonku sun haɗa da jQuery a ciki… wanda wannan rubutun ke da ƙarfi da shi. Da zarar an ɗora shafinku, wannan rubutun yana ƙara mai saurare zuwa shafinku ga duk wanda ya danna wani abu da shi aukuwa bayanai… sannan yana kamawa da tantance nau'in, aiki, da lakabin da kuka ƙayyade a cikin filin.

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

Sanarwa: Na haɗa da faɗakarwa (na yi sharhi) don ku iya gwada abin da ya wuce.

Idan kuna gudana jQuery akan WordPress, zaku so ku canza lambar kaɗan kaɗan tunda WordPress ba ta godiya da gajeriyar hanyar $:

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

Ba shine mafi ƙarfin rubutun ba kuma kuna iya buƙatar yin ƙarin tsaftacewa, amma yakamata ku fara!