Custom Analytics SOS - please help

I am still having a bit of a headache with custom analytics. So here goes…

In data\global\hooks\after_bot_mount\analytics\00_custom_analytics

"use strict";

const axios = require('axios')

const registerCustomAnalytics = async () => {
  const axiosConfig = await bp.http.getAxiosConfigForBot(botId)
  const countGraph = {
    name: 'Total Gender Flow  Visitors',
    type: 'count',
    description: 'Total number of users who disclosed their gender',
    variables: ['gaveGender' ]
  }

  axios.post('/mod/analytics/graphs', countGraph, axiosConfig)

return registerCustomAnalytics()
} 

Then in the flow (sorry couldnt screenshot but the json looks like this):

      "onEnter": [
        "say #!builtin_single-choice-9zKXxa", 
        "analytics/increment {\"name\":\"gaveGender\",\"group\":\"all\",\"increment\":\"1\"}"
      ],

and then as suggested, a conditional flow which runs this action when num of convos is null


"analytics/set {\"metric\":\"gaveGender\",\"group\":\"all\",\"count\":\"1

Then I cycle through the flow a couple of times, make a coffee, return and the graph is still not showing in the analytics gui.

Is there anything I missed

… NB: Edited with suggestions from @crixx and @rndlaine

Actually I’ve not worked with custom analytics yet, but I’d expect “thegender” also to show up in your the “variables” array of you graph definition?

I didn’t check the code, but the README of the custom actions could help you too. Thus I’d guess your code should look something like this:

 const countGraph = {
    name: 'Total Gender Flow  Visitors',
    type: 'count',
    description: 'Total number of users who disclosed their gender',
    variables: ['thegender']
  }

I could also imagine that you want to call “set” only once and then “increment”, such that you don’t override the values every time…

Did that help?

You’re passing too many variables for a Count graph. Count will only display the total count of a single variable. In your case a piechart graph or 3 different count graphs might be more appropriate.

Take a look at the doc to learn more about custom analytics.

Hope this helps!

@spgin @rndlaine @crixx Where they changes in custom analytics we should know about in 12.7.0. Am trying to implement the old custom analytics hook in after_bot_mount and am getting these errors

03/09/2020 13:32:37.483 Launcher Unhandled Rejection
                        HTTP (post) URL http://localhost:3000/api/v1/bots/bude/mod/analytics/graphs
                        Received "<!DOCTYPE html>
                        <html lang="en">
                        <head>
                        <meta charset="utf-8">
                        <title>Error</title>
                        </head>
                        <body>
                        < (...)"
                        Request failed with status code 404
STACK TRACE
Error: Request failed with status code 404
    at createError (C:\snapshot\build-windows\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\snapshot\build-windows\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (C:\snapshot\build-windows\node_modules\axios\lib\adapters\http.js:237:11)
    at IncomingMessage.emit (events.js:187:15)
    at IncomingMessage.EventEmitter.emit (domain.js:442:20)
    at endReadableNT (_stream_readable.js:1081:12)