Track clicks on WhatsApp Chat widget

Hello all,

Unfortunately I am having an issue tracking the conversion of the click to open the whatsapp chat as well.. I’ve been browsing the community for hours and nothing seems to work. (I’ve tried at least 4-5 codes and strategies to make it work but no luck so far)

Would anyone be kind enough to assist me with this? I’d appreciate it.

David.

2 Likes

Hi there, @David_Garraza and welcome to the Community :wave:

Would you prefer tracking clicks via GTM or Google Analytics?

1 Like

Hey Max! Thanks for the super quick response. Working with GTM at the moment!

3 Likes

Okay! Please try to follow these steps:

Adding the code

You should add this code to the Custom JS field on the Appearance tab of your widget’s settings:

function sendAnalyticsEvent(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
        });
    }
}

document.addEventListener('click', function (event) {
    const matchingItems = [
        {
            selector: '[class*="Bubble__BubbleComponent"]',
            label: 'Open/Close Chat Widget'
        },
        {
            selector: '[class*="ChatButton__DefaultButtonComponent-sc"]',
            label: 'Click Start Chat Button'
        },
    ];

    matchingItems.forEach((item) => {
        const match = event.target.closest(item.selector);

        if (match) {
            sendAnalyticsEvent({
                action: 'click',
                category: 'Elfsight Chat Widget',
                label: item.label
            });
        }
    });
});

Creating triggers
  1. Click on New in your GTM account:

  1. Proceed to Trigger Configuration tab:

  1. Choose Custom Event from the list:

  1. Give the name to the event and save it after. You should create 2 events: open-or-close-whatsapp-chat and click-start-chat-button

  1. Once custom events open-or-close-whatsapp-chat and click-start-chat-buttonare created, you should add 2 Google Analytics tags and set the custom events as triggers for these tags:


Give it a try and let me know how it worked :slightly_smiling_face:

1 Like

I’ve tried this multiple times. That’s why I posted a message, none of what I’ve seen has worked for me…

Would that be the trigger event name anyway?

2 Likes

There were some steps missing in the Creating triggers part, apologies for that!

Once custom events open-or-close-whatsapp-chat and click-start-chat-buttonare created, you should add 2 Google Analytics tags and set the custom events as triggers for these tags:

Feel free to try it out and let me know if it worked :slightly_smiling_face:


I’d also like to note, that there is a simpler way to track clicks using the Google Analytics code.

To do this, please add this part of the code to your website <head>:

<!-- Google tag (gtag.js) -->
<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 to the Custom JS field in your widget’s settings:

function sendAnalyticsEvent(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
        });
    }
}

document.addEventListener('click', function (event) {
    const matchingItems = [
        {
            selector: '[class*="Bubble__BubbleComponent"]',
            label: 'Open/Close Chat Widget'
        },
        {
            selector: '[class*="ChatButton__DefaultButtonComponent-sc"]',
            label: 'Click Start Chat Button'
        },
    ];

    matchingItems.forEach((item) => {
        const match = event.target.closest(item.selector);

        if (match) {
            sendAnalyticsEvent({
                action: 'click',
                category: 'Elfsight Chat Widget',
                label: item.label
            });
        }
    });
});

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

2 Likes

Hi Max,

Unfortunately, nothing got triggered after following your instructions. Triggers are there, the Google Ads (Conversion tracker) is linking them, but when I test it out on the Google Tag Assistant, nothing happens.
I’m very new to these as you can tell, but I think I get the general dynamic, but for some reason, no luck here.

Thanks again

2 Likes

Hi @David_Garraza :wave:

I am really sorry about that!

To check why this solution doesn’t work for you, we’ll need temporary access to your GTM account - Providing access to your Google Tag Manager account - Elfsight Help Center.

Could you please provide us with it?

1 Like

Hi Max,

I just did, you must’ve gotten the notification. Let me know if you make any changes. Thank you.

2 Likes

Thank you so much, accepted!

I’ve passed it on to the devs and will report back once I have any news :slightly_smiling_face:

1 Like

Appreciate the time and effort!

2 Likes

Hi there, @David_Garraza :wave:

Devs started working on your request and noticed that you’ve removed the widget from the page. Could you please add it back, so that we could check things?

1 Like

Hi, I shared invited you again. Sorry, I just was thinking I might not need the widget that much after all, but maybe I change my mind if I can actually make it work.

Thanks again

2 Likes

Yeah, we have access to your GTM account, but to check things, we need the widget to be installed on the website. Could you please add the widget back to your website or install to the test page? :folded_hands:

We’ll do our best to make the analytics code work for you!

1 Like

Hi again,

Sorry, I think I’m going to let it stay with a regular link to whatsapp web for the moment.
The widget is very nice and looks great on the site but I have a few other things to juggle at the moment.

I Appreciate the time and effort to solve the issue. I will come back when ready.

thank you.

2 Likes

Okay! If any questions come up in the future, we’re always here to help :slightly_smiling_face:

1 Like