Track View & Click on Timer

I’d like to see basic analytics about how many times the timer was displayed on the landing page and how many clicks (button clicks) were done through the timer.

1 Like

Hi there @Juliana_Joy and welcome aboard :wave:

The views statistics is available in your dashboard:

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

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

In the code above, you need to replace UA-ID with your actual website ID for Google Analytics. If you are using Google Analytics 4, you need to use G-ID instead of UA-ID (see screenshot). 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, 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, '.eapps-countdown-timer-button', {
    action: 'click',
    category: 'Elfsight Countdown Timer',
    label: 'Click to Countdown Timer button'
  });
}, true);
</script>

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

1 Like