Analytics migration to botpress server


When creating custom analytics are we still following this guide.


For 10.x - yes.
For 11.x - you can check more recent docs.



Just a few questions on the docs you refered me to:

@EdsonLucas @jainsourabh2 @sylvain Am sure you can assist too:

This module has some built-in analytics available from the box but also allows you to set up your own custom analytics. For latter you need to:

  1. Register graphs like this:
    Where do we register these graphs (as in which .js file in particular) and do we register them in the module extracted to the .cache file under modules or we unzip the .tgz, make edits then use npm to create a .tgz and chuck it in the modules dir

const axiosConfig = await bp.http.getAxiosConfigForBot(botId) const graphDefinition = { /* ... */ }'/mod/analytics/graphs', graphDefinition, axiosConfig)

graphDefinition is an object with following keys:

  • name (String)
  • type (one of ‘count’, ‘countUniq’, ‘percent’, ‘piechart’)
  • description (String)
  • variables ([String]),

How do we present the variable to be counted in the name:value pair? Is something like
variable : event.user.tag;

  • fn: (String function definition) that is used to calculate result - optional
  • fnAvg: (String function definition) that gets used for ‘percent’ type to calculate average value - optional
  1. Calling increment , decrement and set APIs to register events that get displayed in analytics like this:

await'/mod/analytics/custom_metrics/set', { name:{metric}~{value}, count: 1 }, axiosConfig) await'/mod/analytics/custom_metrics/increment', { name:{metric}~{value}, count: 1 }, axiosConfig) await'/mod/analytics/custom_metrics/decrement', { name:{metric}~{value}, count: 1 }, axiosConfig)

Again in which particular .js file in the module do we include this. Also please clarify how
‘{ name: ${metric}~${value}, count: 1 }’
Should be formatted and should appear. I suppose you might as well give an example of , say, how I would include a user count graph with all users who visited a flow called ADDRESS which records a variable called “addComp” at the last node after the user completes the flow.
Also,in 10.x we could only use variables stored by the “userTag” action. In 11.x, are we restricted to a certain type of variable only?

Thanks a span


Graphs should be registered within hooks of the bot and can be put into global/hooks/after_bot_mount/01_custom_analytics.js. For this you shouldn’t modify botpress itself.

Calling increment , decrement and set APIs can happen within actions (e.g. global/actions/doSmth.js).

I’ve added some clarification to README at


@alex I followed instrctions as follows:

in global/hooks/after_bot_mount/custom_analytics.js :

const axiosConfig = await bp.http.getAxiosConfigForBot(botId)
const graphDefinition = { 
		name: 'Users who added address';
		type: 'count';
		description: 'Number of users whom supplied their full address to the bot';
		variables: event.state.user.custname;

}'/mod/analytics/graphs', graphDefinition, axiosConfig)

In C:\Users\micheal mukwekezeke\Downloads\Econet Dev Bot\data\global\actions\builtin\graphAct.js :

"use strict";

 * Posts to analytics graph
 * @title Post Metric
 * @category Analytics
 * @author Michael.


const axiosConfig = await bp.http.getAxiosConfigForBot(botId)
await'/mod/analytics/custom_metrics/set', { name: `${metric}~${value}`, count: 1 }, axiosConfig)
await'/mod/analytics/custom_metrics/increment', { name: `${metric}~${value}`, count: 1 }, axiosConfig)
await'/mod/analytics/custom_metrics/decrement', { name: `${metric}~${value}`, count: 1 }, axiosConfig)

Then get this error :

18:08:00.595 DialogEngine Flow started.
18:08:00.596 Actions Running "builtin/getGlobalVariable"
18:08:00.603 Actions Output "#!builtin_image-cGRV4f"
18:08:00.610 Actions Running "builtin/analytoEPR"
18:08:00.618 DialogEngine Error processing "builtin/analytoEPR {}"
                          Err: An error occurred while executing the action "builtin/analytoEPR"
                          Flow: main.flow.json
                          Node: entry


It looks like an error happens in a different action.


sorry typo i meant

In C:\Users\micheal mukwekezeke\Downloads\Econet Dev Bot\data\global\actions\builtin\analytoEPR.js

At any rate please indulge me by implementing an instance of custom analytics and sharing the code or repo anyone