Google Analytics Plugin


For more information, refer to GitHub.


What Does This Plugin Do?

This plugin allows you to track the user interaction with the bot or the bot's behaviour by sending the information to Google Analytics.

Setup

  1. Run npm install --save @botonic/plugin-google-analytics to install the plugin.
  2. Add it to the src/plugins.js file:

src/plugins.js

export const plugins = [
{
id: 'google_analytics',
resolve: require('@botonic/plugin-google-analytics'),
options: {
botName: 'YOUR_BOT_NAME',
trackingId: 'YOUR_TRACKING_ID'
}
}
]

Use

The tracking needs to be done manually as enabling this plugin does not track any user interaction or bot's behaviour by default. You can do the tracking inside the botonicInit method, render method or even inside the Webchat listeners.

static async botonicInit({ input, session, params, lastRoutePath, plugins }) {
const ga = plugins.google_analytics
const eventName = 'botEvent'
const eventData = {
category: 'chatbot',
action: 'user_message_sent',
label: 'rating',
value: 4
}
const callback = () => {
console.log(`event ${eventName} sent`)
}
await ga.track(eventName, eventData, callback)
}

Note: The callback argument is not required.

The fallback content to display on prerendering