Help tracking click on WhatsApp Button

Hello there @user10724 :wave:

Thank you for waiting!

Our devs have double-checked things and recommended replacing the previous code with the new one:

const openChatBtn = document.querySelector(
	'[class*="Bubble__BubbleComponent"]'
);
const startChatBtn = document.querySelector(
	'[class*="ChatButton__DefaultButtonComponent-sc"]'
);

if (!dataLayer || !openChatBtn || !startChatBtn) {
	return;
}

openChatBtn.addEventListener('click', () => {
	dataLayer.push({ event: 'open-or-close-whatsapp-chat' });
});

startChatBtn.addEventListener('click', () => {
	dataLayer.push({ event: 'click-start-chat-button' });
});

If I understood right, under the “variables” you mean the events that will be sent to your GTM account. Here are the events that will be sent:

  • clicks on the Open/Close chat

  • clicks on the Start Chat button


After you’ve added the code above to the Custom JS section, you need to create triggers for these events:

Log in to your GTM account, choose Triggers and click New


"Then click Trigger Configuration and choose Custom Event


Add the event name from the code (Custom JS) to the Event Name field and save changes


Choose any name for the trigger


Please let me know if it helped :slightly_smiling_face: