How to Integrate Simple Analytics Into Your Chatbot?

Maxim Abramchuk
Chatbots Life
Published in
3 min readJun 27, 2017

--

Analytics is super important. If you’ve launched the product and haven’t setup analytics — it’s pretty similar to riding a bike with closed eyes. You don’t know what’s happening, how many users are leaving your bot immediately, how many minutes users are spending playing with your bot, what’s the most popular feature and much more.

There are a lot of analytics tools, even for bots, you can find a full list of them here: https://github.com/BotCube/awesome-bots#analytics. But a lot of people still keep asking me in our BotChat or in DM about ability to use Google Analytics inside their bot. Yea, people are used to GA and they want to use it everywhere. Though I decided to write a very simple article explaining how to integrate Google Analytics into a bot written in Node.js.

So, to start with — the result of this article will be a simple ES6 class that can be integrated into any bot app. Let’s start.

At first we need to create a GoogleAnalytics class and initialize it.

Here I require universal-analytics library for communication with Google Analytics and bluebird to wrap all the universal-analytics callback functions and transform them to Promise instances. Here I also pull Google Analytics ID from the config file and initialize a “visitor” instance passing my Google Analytics id and user ID to the instance of universal-analytics.

So, our visitor is initialized and the only thing missing is to save info about different events user does to GA. Let’s implement that 😉

We need to implement a method that will be sending an event to GA. It’s pretty simple, take a look at the code snippet below:

So, the method sendEvent is accepting 3 parameters: category, action and label. Let’s say you want to log that user has gone through the onboarding scenario, so you put:

category = 'scenarios'
action = 'onboarding'

And that’s it. That simple. The full class code is below:

Then, after logging a couple of events you can go the the Google Analytics, find Behaviour -> Events -> Overview section there and at the right bottom corner you’ll see your categories:

Clicking on these categories you can open open particular actions like onboarding and much more.

If you still have questions — feel free to reach me out on Facebook.

Get ALL USEFUL INFORMATION about bots in one free awesome repo on Github!

If you like what you read be sure to 💚 it below — as a writer it means the world

--

--

Co-Founder and CTO at @getstorylinecom, @boostvc Tribe X, Voice-powered Cyborg 🤖