How can we tell if somebody clicked the link in the All in One Widget to create an email or WhatsApp rather than doing it directly. I want to know if Elfsight is being used? Does anybody know how I can tell? Many thanks for your help.
1 Like
Hi @user12739 and welcome aboard
Glad to tell you that you can track button clicks using our Google Analytics code. 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, 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 All-in-one Widget',
label: 'Open or Close All-in-one Widget'
});
eappsDispatchAnalyticsEvent(event, "button[title='WhatsApp']", {
action: 'click',
category: 'Click WhatsApp Chat',
label: 'Click WhatsApp Chat'
});
eappsDispatchAnalyticsEvent(event, "button[title='Email']", {
action: 'click',
category: 'Click Email',
label: 'Click Email'
});
}, true);
</script>
In order to see the statistics on clicks, please go to the **Reports** tab of your Google Analytics dashboard
Here you can choose the report type: Realtime Report or Reports Snapshot
Just in case, we have an article that describes how to work with each of them - Google Analytics 4 (GA4): Where to find my events.
Try it out and let me know if it worked