If Google Tag Manager is installed on your website, 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. ( will discuss later )
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’
and 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 will select ‘Google Analytics – GA4 Event’
Configure the GA4 tag and name the event
and then will select when to trigger this.
as we created a trigger, will select that.
It looks like this.
preview/submit and test it.
Now When a user clicks on WhatsApp icon/Button an event will create at Google analytics
‘Click to Chat’ event
Now we know there is a click event.
Anyhow, google tag manager send some values to the event, like the page_location, page_title, …
Now 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 dyanamic. 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 send multiple variables, here we will add a number, type variable. )
Number: will get the WhatsApp number
and at ‘Data Layer Variable Name’ add the Variable Key – ‘number’
and will add type variable. (repeated the steps)
Will attach this variable to the event tag.
Go the tag where we created it early.
At Event, Parameters will add the variables.
Preview/Submit and Test.
Now when the user clicks on WhatsApp icon, the button and event will send 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.