Hi Max,
Yes I’m definitely interested in that!
(Would it count a click on the close button the same as a click on the popup itself?
Aidan Alexander
Co-founder
FarmKind
Hi Max,
Yes I’m definitely interested in that!
(Would it count a click on the close button the same as a click on the popup itself?
Aidan Alexander
Co-founder
FarmKind
I’ve checked your widgets and see that they also have a Subscribe button. Our devs prepared a Google Analytics code for tracking clicks on the popup, close and submit buttons.
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*="Popup__PopupContent-sc"]', {
action: 'click',
category: 'Popup',
label: 'Click on Elfsight Popup'
});
eappsDispatchAnalyticsEvent(event, '[class*="PopupCloseControl__PopupCloseControlContainer-sc"]', {
action: 'click',
category: 'Popup',
label: 'Click on Elfsight Close Button Popup'
});
eappsDispatchAnalyticsEvent(event, '[class*="ButtonBase__ButtonContainer-sc"]', {
action: 'click',
category: 'Popup',
label: 'Click on Elfsight Subscribe Button Popup'
});
}, true);
</script>
Please try it out and let me know how it worked
@Max
Can we confirm where these scripts should be
GTAG is in Header
Body contain the Install popup and the Custom event code ?
Thanks
Hi there, @AndyF
Yes, the 1st part of the code should be added to the head and the 2nd part to the body. I’ve moved your comment to the related thread.
So, you can see all the details in the comment above
Thanks @max works great
and just to share knowledge if you want track the click on the image eappsDispatchAnalyticsEvent(event, ‘[class*=“MediaImage__Container-sc”]’, {
action: ‘click’,
category: ‘Popup’,
label: ‘Image QR Click’
});
Question is there a chance that “other” widgets also use the same class not just popup
like ‘ButtonBase__ButtonContainer-sc’ , so for example the widget for notifications … buttons ? can it be a bit more specfic to type of widget if that is case ?
Andy
Yes, @AndyF! The button in the Sales Notification app has the same class.
Here is how you can check it: right-click the element you’d like to identify - click Inspect, and you’ll the class of the element
Hey Max,
Sorry for the slow response – it took a moment for us to get this working on our end. Thank you so much for getting it built!
A point of clarification: If a user dismisses the pop-up by clicking elsewhere on the page, does that register as a pop-up close click or not?
Thanks,
Sent with Shift
Glad to hear that! As for your question, if a user dismisses the widget by clicking on some place on the page, it won’t be counted as a close click.
If you have any questions left, we are always here for you