Support

Tracking GoSquared Assistant Events in Google Analytics

How to track GoSquared Assistant events with Google Analytics.

For a variety of use cases, you may want to track an event in Google Analytics based on an interaction with the GoSquared Assistant. To allow you to do that we provide two specific events.

The event ‘message_sent’ is fired when a message is sent by a website visitor to an agent.

The event ‘widget_opened’ is fired when a website visitor opens the GoSquared Assistant widget.

Tracking events directly in Google Analytics:

Message Sent

To track an event in Google Analytics when a message is sent from a site visitor, just add this extra line of code after the main GoSquared code snippet:

gtag.js implementation

<script>
_gs('chat', 'on', 'message_sent', function() {
  gtag('event', 'Chat message sent', {
    'event_category': 'GoSquared',
    'event_label': 'GoSquared chat message sent'
    });
  });
</script>

analytics.js implementation

<script>
_gs('chat', 'on', 'message_sent', function() {
  ga('send', 'event', 'GoSquared', 'Chat message sent', 'GoSquared chat message sent');
  });
</script>

Widget Opened

To track an event in Google Analytics when a website visitor opens the Assistant widget, just add this extra line of code after the main GoSquared code snippet:

gtag.js implementation

<script>
_gs('chat', 'on', 'widget_opened', function() {
  gtag('event', 'Chat widget opened', {
    'event_category': 'GoSquared',
    'event_label': 'GoSquared chat widget opened'
    });
  });
</script>

analytics.js implementation

<script>
_gs('chat', 'on', 'widget_opened', function() {
  ga('send', 'event', 'GoSquared', 'Chat widget opened', 'GoSquared chat widget opened');
  });
</script>

Tracking events in Google Tag Manager:

For Google Tag Manager, you’ll need to create two tags.

  • One to capture the GoSquared Interaction and pass variables to the Data Layer, triggered by the gtm.dom event.
  • One to track the event in Google Analytics with the Data Layer variables, triggered by the GoSquared Interaction.
  1. Create a Custom HTML tag and add the following script to it to capture the message_sent and widget_opened interactions.


<script>
  _gs('chat', 'on', 'message_sent', function() {
   {
       dataLayer.push({
              'event': 'GoSquaredInteraction',
              'eventCategory': 'GoSquared',
              'eventAction': 'Chat message sent'
       });
    }
  });

  _gs('chat', 'on', 'widget_opened', function() {
   {
       dataLayer.push({
              'event': 'GoSquaredInteraction',
              'eventCategory': 'GoSquared',
              'eventAction': 'Chat widget opened'
       });
    }
  });
</script>

Give it a memorable name and click save.

GTM Interaction Tag

Add a trigger with a trigger type of 'custom event' with the event name equal to ‘gtm.dom’.

GTM DOM tag

Give it a memorable name click save.

With this done you will now be able to capture the GoSquared interaction. The next step is to use that to track the event in Google Analytics.

  1. Create a new Google Analytics : Universal Analytics tag with the track type ‘Event’. Then pass your Data Layer variables to the respective event category and action.

For the trigger, create a custom event and set the event name to equal ‘GoSquaredInteraction’.

Give it a memorable name click save.

GTM select container

With this published, you should will now be able to track an event in Google Analytics based on when a site visitor sends a chat message through Assistant and when a site visitor opens the chat widget.