npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@botonic/plugin-hubtype-analytics

v0.30.2

Published

Plugin for tracking in the Hubtype backend to see the results in the Hubtype Dashbord

Downloads

653

Readme

Botonic Plugin Hubtype Analytics

What Does This Plugin Do?

This plugin is used to integrate Hubtype Analytics Service in your Botonic project.

Setup

  1. Install the plugin from npm (or yarn):
npm i @botonic/plugin-hubtype-analytics
  1. Add it to the src/plugins.js file defining the projectId of the Project you want to use:

You can define two optional functions to obtain the language and the country. By default if you do not define these functions it will use the language defined in request.session.user.extra_data.language and country defined in request.session.user.extra_data.country

  export const plugins = [
    {
      id: 'hubtype-analytics',
      resolve: require('@botonic/plugin-hubtype-analytics'),
      options: {
        getLaguange?: (request: BotRequest) => request.session.user.extra_data.lang
        getCountry?: (request: BotRequest) => request.session.user.extra_data.store
      },
    },
  ]

Plugin Options

  • getLaguange: getLaguange(request) function to define the language when it is not in request.session.user.extra_data.language
  • getCountry: getCountry(request) function to define the country when it is not in request.session.user.extra_data.country

Use

All events can be used in bot actions.
The following events can also be used from the frontend (webchat and webviews): EventFeedback, EventWebview, EventCustom

  • To track the content displayed in a bot that is made with Flow Builder you can import the trackFlowContent function of the @botonic/plugin-flow-builder.

e.g. WelcomeAction that display start contents

import { trackFlowContent } from '@botonic/plugin-flow-builder'

export class WelcomeAction extends FlowBuilderMultichannelAction {
  static contextType = RequestContext
  static async botonicInit(
    request: BotRequest
  ): Promise<FlowBuilderActionProps> {
    const flowBuilder = request.plugins.flowBuilder
    const contents = await flowBuilder.getStartContents('es-ES')
    trackFlowContent(request, contents)
    return { contents }
  }
}
  • To track a handoff, you can use an instance of HandOffBuilder from @botonic/core handoffBuilder.withBotEvent() so thaht the backend will create the event after the handoff has been done correctly.
const handOffBuilder = new HandOffBuilder(request.session)
handOffBuilder.withQueue(this.queue.id)
handOffBuilder.withBotEvent({
  language: request.session.user.extra_data.language,
  country: request.session.user.extra_data.country,
})
await handOffBuilder.handOff()
  • To track a feedback given by the user after a handoff. If you add a free comment this field is only stored in hubtype DB and no other service will be used to store this sensitive data.
const hubtypeAnalyticsPlugin = request.plugins.hubtypeAnalytics
const event = {
  action: FeedbackAction.case,
  data: {
    feedbackTargetId: request.session.case_id,
    feedbackGroupId: uuid(),
    possibleOptions: ['*', '**', '***', '****', '*****'],
    possibleValues: [1, 2, 3, 4, 5],
    option: '**',
    value: 2,
    comment: 'free comment writen by the user',
  },
}

try {
  const response = await hubtypeAnalyticsPlugin.trackEvent(request, event)
  console.log(response)
} catch (error) {
  console.error(error)
}
  • To track an event from a webview. In a webview you don't have the plugins initialised, we have to create an instance of BotonicPluginHubtypeAnalytics
const hubtypeAnalytics = new BotonicPluginHubtypeAnalytics()
const event = {
  action: EventAction.WebviewStep,
  webviewThreadId,
  webviewName,
  webviewStepName,
}

try {
  const response = await hubtypeAnalyticsPlugin.trackEvent(request, event)
  console.log(response)
} catch (error) {
  console.error(error)
}
  • Finally, custom events can also be created. In a custom event you can track whatever you want but it is preferable not to use them too much.
const hubtypeAnalytics = new BotonicPluginHubtypeAnalytics()
const event = {
  action: EventAction.Custom,
  customFields: {
    paymentType: 'paypal',
    bagsAdded: 3,
  },
}

try {
  const response = await hubtypeAnalyticsPlugin.trackEvent(request, event)
  console.log(response)
} catch (error) {
  console.error(error)
}