If Google Tag Manager is installed on your website, the Click to Chat plugin sends dataLayer Object.
We can use this dataLayer object and can create a custom event. ( in Google Analytics, Facebook Pixel, and many more places .. )
If you like to go in advance, we can use variables.
Step-1: Create a trigger
Triggers -> new
and at, ‘Trigger configuration’ –> at ‘others’ select – ‘Custom Event’
Name the event ( here we added – Click to Chat )
and at trigger fires on select ‘some custom Events’.
select as ‘event’ – ‘contains’ – Click to Chat
Save the trigger.
Create a tag and then assign it to Google Analytics 4.
at ‘Tags’ –> ‘New’
At ‘Tag configuration’, select where to send the event.
Here, we will use Google analytics 4 (GA4). So, let us select ‘Google Analytics – GA4 Event’
Configure the GA4 tag and name the event.
and then, let us select when to trigger this. As we created a trigger, we will choose that.
It looks like this.
preview/submit and test it.
Now, When a user clicks on WhatsApp icon/Button, an event will be created at Google analytics.
‘Click to Chat’ event.
Now, we know there is a click event.
Anyhow, google tag manager sends some values to the event, like the page_location, page_title, etc.
Now, we will check how to get the WhatsApp Number and attach it to the Event.
Click to Chat plugin sends some variables with the dataLayer.
Variable key: Variable Value
`event: 'Click to Chat', type: 'chat', number: id, title: post_title, url: url, event_category: ga_category, event_label: ga_label, event_action: ga_action,`
The variable values are dynamic. we will use variable key to get the value at GTM and send it to Google Analytics.
‘Variables’ at ‘User Defined Variables’ -> ‘New’
At ‘Variable Configuration’ select –> ‘Data Layer Variable’.
(Click to Chat sends multiple variables, here we will add a number, type variable)
Number: we will get the WhatsApp number.
and at ‘Data Layer Variable Name’ add the Variable Key – ‘number’.
and we will add ‘type’ variable. (repeat the steps)
Let us attach this variable to the event tag.
Go the tag where it is created earlier. At the Event, Parameters we will add the variables.
Preview/Submit and Test.
When the user clicks on the WhatsApp icon/button, an event will be sent to Google Analytics.
Here, we can notice the variables added to google analytics – WhatsApp Number, Chat/Group/Share
if we navigate to the Number we can check the number.