Step 1: Enable Google Tag Manager on Your Site #
Before you begin, make sure GTM is installed and correctly embedded in your WordPress site.
You can add the GTM container snippet directly in your siteβs <head> tag or use a plugin such as “Insert Headers and Footers”.
Step 2: Add Conversion Tracking Script #
Add the following script to your themeβs footer.php, or enqueue it via your plugin:
function talkativewpTrackConversion(eventLabel = 'chat_started') {
if (typeof window.dataLayer === 'undefined') {
console.warn('GTM not found');
return;
}
window.dataLayer.push({
event: 'talkativewp_conversion',
event_category: 'TalkativeWP',
event_action: eventLabel,
event_label: window.location.href,
chatbot: true
});
console.log('π Conversion event sent to GTM:', eventLabel);
}
Step 3: Trigger Events in Your Chat Flow #
You can trigger the conversion tracking function based on specific interactions:
π User opens the chat: #
document.getElementById('talkativewp-chat-button')?.addEventListener('click', () => {
talkativewpTrackConversion('chat_opened');
});
π User submits the pre-chat form: #
document.getElementById('talkativewp-start-chat')?.addEventListener('click', () => {
talkativewpTrackConversion('chat_started_form');
});
π User sends a message: #
document.getElementById('talkativewp-send')?.addEventListener('click', () => {
talkativewpTrackConversion('chat_message_sent');
});
You can adjust the event labels (chat_opened, chat_message_sent, etc.) as needed.
Step 4: Configure Google Tag Manager #
In GTM:
- Go to Triggers > New
- Choose Trigger Type β
Custom Event - Set Event name to:
talkativewp_conversion - Choose βAll Custom Eventsβ or filter using conditions (e.g., by
event_action)
Then:
- Create a Tag β GA4 Event
- Connect it to your GA4 property
- Set event name to
chatbot_conversion - Add parameters like
event_category,event_action,event_labelfrom Data Layer variables
π Notes #
- If GTM is not loaded, the function will safely skip and log a warning.
- The system uses standard naming:
event_category,event_action,event_label - This approach works well for tracking soft conversions like chat engagement.