New WhatsApp button metrics

Hi there, @Nicolas_Vinicius :waving_hand:

Thank you so much for the feedback!

We already have this idea on the Wishlist, and it’s planned for consideration. Please upvote it to not miss any updates - Include the tracking option.

As for now, you can track clicks using the Google Analytics code. Please add this part of the code to your website <head>:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-ID');
</script>

In the code above, you need to replace G-ID with your actual website ID for Google Analytics. This article will help you find your ID - Find your Google tag ID.

And then just add the rest of the script right before closing </body> tag


<script>
function eappsDispatchAnalyticsEvent(event, selector, config) {
  function sendEvent(config) {
    if (typeof ga !== "undefined") {
      ga("send", "event", {
        eventAction: config.action,
        eventCategory: config.category,
        eventLabel: config.label,
      });
    }
    if (typeof gtag !== "undefined") {
      gtag("event", config.action, {
        event_category: config.category,
        event_label: config.label,
      });
    }
  }
  function isHitClass(e, selector) {
    return e.target && e.target.closest(selector);
  }
  if (isHitClass(event, selector)) {
    sendEvent(config);
  }
}
document.addEventListener(
  "click",
  function (event) {
    eappsDispatchAnalyticsEvent(event, '[class*="Bubble__BubbleComponent"]', {
      action: "click",
      category: "Open or Close WhatsApp Chat Widget",
      label: "Open or Close WhatsApp Chat Widget",
    });


    eappsDispatchAnalyticsEvent(
      event,
      "[class*='ChatButton__DefaultButtonComponent-sc'][href*='wa.me/']",
      {
        action: "click",
        category: "Click WhatsApp Chat",
        label: "Click WhatsApp Chat",
      }
    );
</script>

Here is an article explaining where you can find the info about clicks -Google Analytics 4 (GA4): Where to find my events - Elfsight Help Center.

Please try it out and let me know if it worked :slightly_smiling_face:

2 Likes