Home > Tracking Events with Google Analytics

Categories: |


(Last Updated On: August 9, 2018)

We know Google Analytics is a massive piece of software and can be difficult to track events with, so we hope with this new help doc all about tracking events can help it can be a smoother process for you.

Tracking codes?

The first thing to keep in mind is that the tracking code could vary among three options:

  • gtag (gtag.js) (This is the newest version)
  • ga (analytics.js) (Universal Analytics and maybe the most common)
  • _gaq (ga.js)    (This is legacy code)

How can I tell which code we are using?

You should be able to see 1 of 3 codes on your site; gtag , ga , or _gaq.

Legacy users, why are you using the legacy ga.js code?

We would kindly like to ask you to switch to the new version. Go here to help migrate existing implementations.

Where do you find the tracking code?

You will find your tracking code (1.3) under Admin (1.1) > Tracking code (1.2):

Is it possible to see a different version of the code in the Analytics account and a different one on your site?

Yes. The fact that you can currently see the latest version of the tracking code in your account DOES NOT mean that the code you have installed is this one. It could easily be a previous version, so please confirm the version of the code installed on the website.

Why does it matter what kind of code you are using? The events we track do not change.

The events do not change but the code snippet to track the events does change and depends on the tracking code you use.

For example, if you track the OpenProactive event the code will change accordingly:

Universal Analytics


SnapEngage.setCallback(‘OpenProactive’, function(agent, msg) {
seAgent = agent;
ga(‘send’,’event’,’SnapEngage’, ‘proactivePrompt’, agent);
});

Latest version


SnapEngage.setCallback(‘OpenProactive’, function(agent, msg) {
seAgent = agent;
gtag(‘event’, ‘ProactiveChat’, {
‘event_category’ : ‘SnapEngage’,
‘event_label’ : agent
});
});

Legacy version


SnapEngage.setCallback(‘OpenProactive’, function(agent, msg) {
seAgent = agent;
_gaq.push([‘_trackEvent’, ‘SnapEngage’, ‘Booh!’, agent]);
});

As you can see the three snippets are different.

 

Where do I find more info about the events we track again?

Here.

analytics.js – ga – Universal Analytics

 

Tracking code


(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,’script’,’https://www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘UA-5735xxx4-1’, ‘auto’);
ga(‘send’, ‘pageview’);

Below you can find the tracking snippet for each event for Universal Analytics. Mind the labels. I have been playful!

 

Events

OpenProactive


SnapEngage.setCallback(‘OpenProactive’, function(agent, msg)
seAgent = agent;
ga(‘send’,’event’,’SnapEngage’, ‘proactivePrompt’, agent);
});

StartChat


SnapEngage.setCallback(‘StartChat’, function(email, msg, type)
{
ga(‘send’,’event’,’SnapEngage’, ‘startchat’, seAgent);
});

MessageSubmit


SnapEngage.setCallback(‘MessageSubmit’, function(email, msg)
{
ga(‘send’,’event’,’SnapEngage’, ‘offline’);
});

     

ChatMessageReceived


SnapEngage.setCallback(‘ChatMessageReceived’, function(agent, msg)
{
ga(‘send’,’event’,’SnapEngage’, ‘agentmessage’, seAgent);
});

ChatMessageSent


SnapEngage.setCallback(‘ChatMessageSent’, function(msg)
{
ga(‘send’,’event’,’SnapEngage’, ‘visitormessage’);
});

Close


SnapEngage.setCallback(‘Close’, function(type, status) {
ga(‘send’,’event’,’SnapEngage’, ‘closechat’);
});

Open


SnapEngage.setCallback(‘Open’, function(status) {
ga(‘send’,’event’,’SnapEngage’, ‘openworks’);
});

StartCallme


SnapEngage.setCallback(‘StartCallme’, function (phone) {
ga(‘send’,’event’,’SnapEngage’, ‘Bell’, phone);
});

 

gtag (gtag.js) – latest version of tracking code

Tracking code


Below you can find the tracking snippet for each event for the latest version of the code. Mind the labels, we’ve have been playful!

Events

StartChat


var seAgent;
SnapEngage.setCallback(‘StartChat’, function(agent, msg, type) {
seAgent = agent;
gtag(‘event’, ‘Chat’, {
‘event_category’ : ‘SnapEngage’,
‘event_label’ : agent
});
});

OpenProactive


SnapEngage.setCallback(‘OpenProactive’, function(agent, msg) {
seAgent = agent;
gtag(‘event’, ‘ProactiveChat’, {
‘event_category’ : ‘SnapEngage’,
‘event_label’ : agent
});
});

ChatMessageReceived


SnapEngage.setCallback(‘ChatMessageReceived’, function(agent, msg) {
seAgent = agent;
gtag(‘event’, ‘AgentMessages’, {
‘event_category’ : ‘SnapEngage’,
‘event_label’ : agent
});
});

Close


SnapEngage.setCallback(‘Close’, function(type, status) {
gtag(‘event’, ‘closingchat’, {
‘event_category’ : ‘SnapEngage’,
});
});

Open


SnapEngage.setCallback(‘Open’, function(status) {
gtag(‘event’, ‘openingchat’, {
‘event_category’ : ‘SnapEngage’,
});
});

StartCallme


SnapEngage.setCallback(‘StartCallme’, function(phone) {
gtag(‘event’, ‘BattleStar’, {
‘event_category’ : ‘SnapEngage’,
‘event_label’ : phone
});
});

ChatMessageSent


SnapEngage.setCallback(‘ChatMessageSent’, function(msg) {
gtag(‘event’, ‘Thisisavisitormessage’, {
‘event_category’ : ‘SnapEngage’,
});
});

MessageSubmit


SnapEngage.setCallback(‘MessageSubmit’, function(email, msg) {
gtag(‘event’, ‘Thisisanofflinemessage’, {
‘event_category’ : ‘SnapEngage’,
});
});

ga.js (legacy)

ga.js is a legacy library and we – but mainly Google- recommend you use the latest version of analytics.

Tracking code


Below you can find the tracking snippet for each event for the legacy version of the code. Mind the labels, we’ve have been playful!

Events

StartChat


SnapEngage.setCallback(‘StartChat’, function(email, msg, type) {
_gaq.push([‘_trackEvent’, ‘SnapEngage’, ‘AChatJustStarted’, seAgent]);
});

OpenProactive


SnapEngage.setCallback(‘OpenProactive’, function(agent, msg) {
seAgent = agent;
_gaq.push([‘_trackEvent’, ‘SnapEngage’, ‘Booh!’, agent]); });

ChatMessageReceived


SnapEngage.setCallback(‘ChatMessageReceived’, function(agent, msg)  {
seAgent = agent;
_gaq.push([‘_trackEvent’,’SnapEngage’, ‘AgentTalking’, seAgent]);
});

Close


SnapEngage.setCallback(‘Close’, function(type, status) {
_gaq.push([‘_trackEvent’,’SnapEngage’, ‘DontGo’]);
});

Open


SnapEngage.setCallback(‘Open’, function(status) {
_gaq.push([‘_trackEvent’,’SnapEngage’, ‘WhereHaveYouBeen’]);
});

StartCallme


SnapEngage.setCallback(‘StartCallme’, function(phone) {
_gaq.push([‘_trackEvent’, ‘SnapEngage’, ‘ThunderCats’, phone]);
});

ChatMessageSent


SnapEngage.setCallback(‘ChatMessageSent’, function(msg)  {
_gaq.push([‘_trackEvent’,’SnapEngage’, ‘VisitorTalking’]);
});

MessageSubmit


SnapEngage.setCallback(‘MessageSubmit’, function(email, msg)
{
_gaq.push([‘_trackEvent’,’SnapEngage’, ‘WeAreNotHere’]);
});

Where will you see those events?

In your Google Analytics account under  Behaviour > Events > Overview.

Click here to see a clear screenshot

Can I change the names, labels of the tracked events?

You can give them dinosaur names if you want. Whatever works for you. Below you can see which part is the one you can change in order to label the event:

 

 

What happens with Google Tag Manager

It is vital that the tracking Google Analytics code is in the same tag as the SnapEngage code. If you think that the whole code comprises of three parts:

  • Google Analytics Code
  • SnapEngage code
  • Tracking events code snippets,

they all need to be in the same tag.

Below is an example of how the code should be:


If any of those parts is missing there will be no events tracked in Google Analytics.

So you only want to track Proactive Chat Engagement?

You can find the code for this here. What you do with this snippet is to track the StartChat event only in case the chat was a proactive one:
ga.js (legacy analytics)


analytics.js


gtag.js


 

Since you will be tracking all proactive chat invites with OpenProactive and with StartChat the responded proactive chats, you divide the latter with the first and you get the percentage of how many proactive invites have been answered by visitors.

Using the labels of the above screenshot:

Proactive Chat Engagement = ProactiveEngaged / proactivePrompt

When you use this proactive engagement tracking, can you still use a separate StartChat tracking snippet to track all chats? Manual included.

Of course, you can! Sky’s the limit.

Want to track Proactive Chat Engagement AND manual chats?

Here are some more examples for you.
ga.js (legacy analytics)


analytics.js


gtag.js


 

 

 

 

 

Did you find this article helpful?

Not HelpfulNeeds WorkSo-soHelpfulVery Helpful (No Ratings Yet)
Loading ... Loading ...

Published July 27, 2018