Track How Many Users Click On Widget

Hi there, @CopperstateFarms :waving_hand:

Thanks for sharing your idea with us! We agree that it would be great to have the click statistics right in the dashboard. If more users upvote this idea, we’ll try to consider it in the future :slightly_smiling_face:

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 isHitClass(e, selector) {
  return e.target && e.target.closest(selector);
}

function sendEvent(config) {
  if (typeof ga !== "undefined") {
    ga('send', 'event', {
      eventAction: config.action,
      eventCategory: config.category,
      eventLabel: config.label,
      eventTargetLanguage: config.targetLanguage
    });
  }

  if (typeof gtag !== "undefined") {
    gtag('event', config.action, {
      'event_category': config.category,
      'event_label': config.label,
      'event_target_language': config.targetLanguage
    });
  }
}

function eappsDispatchAnalyticsEvent(event, selector, config) {
  if (isHitClass(event, selector)) {
    sendEvent(config);
  }
}

const languageDropdownItemSelector = "[class*='eapps-website-translator'] [class*='dropdown-item__Wrapper-sc']";

document.addEventListener('click', function (event) {
  if (event.target.closest(languageDropdownItemSelector)) {
    const languageName = event.target.querySelector("[class*='name__NameContainer-sc']")?.innerText;

    eappsDispatchAnalyticsEvent(event, languageDropdownItemSelector, {
      action: 'translation_on_click',
      targetLanguage: languageName,
      category: 'translation',
      label: 'Translation on click'
    });
  }
}, true);
</script>

Please let me know if it helps and if you have any other questions :slightly_smiling_face: