Tracking Conversions with Google Tag Manager or Google Analytics

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:

  1. Go to Triggers > New
  2. Choose Trigger Type β†’ Custom Event
  3. Set Event name to: talkativewp_conversion
  4. Choose β€œAll Custom Events” or filter using conditions (e.g., by event_action)

Then:

  1. Create a Tag β†’ GA4 Event
  2. Connect it to your GA4 property
  3. Set event name to chatbot_conversion
  4. Add parameters like event_category, event_action, event_label from 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.

What are your feelings

Updated on 18 May 2025
I am here to help chat icon
Chat with TalkativeWP Bot
β€’ β€’ β€’ TalkativeWP Bot on it...