Google BigQuery Integration
The Google BigQuery Jovo integration allows you to monitor and analyze voice and chat conversations between your Jovo app and its users.
Introduction
Google Cloud's BigQuery allows you to easily collect, process, and analyze data streams in real time.
The BigQuery Jovo analytics plugin can be used to automatically track events for your voice apps and chatbots. Use it to send data about sessions, intents, entities, etc. to BigQuery. It's also possible to track custom events in your Jovo handlers using the $bigQuery
property.
Learn more in the following sections:
Installation
To successfully use Jovo with BigQuery, you need to follow the steps detailed in the sections below:
Set up BigQuery
To set up BigQuery, you need to create a service account, download the JSON file, and include it in your project's src
folder. Typically, we name the file serviceAccount.json
.
Follow these steps:
- In the Google Cloud Console, create a new project.
- Select the project.
- Create a Service Account and set the Service Account ID.
- Assign the Service Account the role of "BigQuery Data Editor".
- Select the Service Account and on the Keys tab, click the Add Key button.
- Create a new key with JSON key type.
- The JSON file will download. Copy the file to your Jovo project's
src
folder and rename it toserviceAccount.json
. - In your Google project, open BigQuery and create a
dataset
and atable
. - Define the table schema using the starter schema
To learn more about service account credentials, see Authenticating with a service account key file. The service account must include the BigQuery Data Editor role to insert rows to the table.
Before you can log to the BigQuery table, you need to create the table and define a schema. Use this starter schema and paste into the text area when you toggle on "Edit as text".
Add BigQuery Integration to Jovo App
Install the Jovo plugin like this:
$ npm install @jovotech/analytics-bigquery
In your app configuration, add BigQuery to any stage you like, e.g. app.prod.ts
(analytics is usually added to the production stage only, learn more about staging here):
import { BigQueryAnalytics } from '@jovotech/analytics-bigquery'; import serviceAccount from './service-account.json'; // ... app.configure({ plugins: [ new BigQueryAnalytics({ appId: '<YOUR-APP-ID>', datasetId: '<YOUR-DATASET-ID>', tableId: '<YOUR-TABLE-ID>', libraryConfig: { credentials: serviceAccount, }, // ... }), // ... ], });
For the integration to work, you need the service account created in the Set up BigQuery section. And at least the configuration options shown in the code example above.
Learn about all configurations below.
Configuration
The following configurations can be added:
new BigQueryAnalytics({ appId: '<YOUR-APP-ID>', datasetId: '<YOUR-DATASET-ID>', tableId: '<YOUR-TABLE-ID>', libraryConfig: { /* ... */ }, dryRun: false, insertRowOptions: { /* ... */ }, logging: true, onAddEvent: async (jovo: Jovo, event: AnalyticsEvent) => { event.timeZone = ''; }, addEventFilter: (jovo: Jovo, event: AnalyticsEvent) => event.eventType !== 'device_capabilities', }),
It includes these properties:
appId
: Required. Matches appId column in BigQuery table. Logged with every event to distiguish one app's log entries from another.datasetId
: Required. The name of the BigQuery dataset to write to.tableId
: Required. The name of the BigQuery table to write to.libraryConfig
: Required. BigQuery options including credentials file. See libraryConfig for more information.dryRun
: Default isfalse
. When true, the plugin'ssendEvents
function does not insert the events into the BigQuery table.insertRowOptions
: Used to configure the insert of rows into BigQuery. See insertRowOptions for more information.logging
: Default isfalse
. Whentrue
, logs plugin calls foraddEvent
andsendEvents
. See logging for more information.onAddEvent
: Optional. Allows modification of theevent
before it is sent to BigQuery. See onAddEvent for more information.addEventFilter
: Optional. Allows filtering anevent
before it is sent to BigQuery. See addEventFilter for more information.
libraryConfig
This config property is of the type BigQueryOptions
. The config will be used when initializing the BigQuery client.
Add the service account JSON file to the src
folder.
The BigQuery client config includes:
import { BigQueryAnalytics } from '@jovotech/analytics-bigquery'; import serviceAccount from './serviceAccount.json'; // ... new BigQueryAnalytics({ libraryConfig: { credentials: serviceAccount, // ... }, // ... }),
or:
import { BigQueryAnalytics } from '@jovotech/analytics-bigquery'; import serviceAccount from './serviceAccount.json'; // ... new BigQueryAnalytics({ libraryConfig: { projectId: serviceAccount.project_id, keyFilename: './serviceAccount.json', }, // ... }),
credentials
: imported service account JSON (including project_id)projectId
: BigQuery project id.keyFilename
: Path to the service account JSON file.- For more properties, see the official reference.
insertRowOptions
Configure the options for inserting rows into BigQuery.
The insert row options include:
new BigQueryAnalytics({ insertRowOptions: { skipInvalidRows: true, ignoreUnknownValues: true }, // ... }),
skipInvalidRows
: Iftrue
(default), insert all valid rows of a request, even if invalid rows exist.ignoreUnknownValues
: Iftrue
(default), accept rows that contain values that do not match the schema. The unknown values are ignored.
See BigQuery Table insert for more details.
logging
You can configure all logging options with a simple true
or false
(default):
new BigQueryAnalytics({ logging: true, // ... }),
All request and response events are added to an array with addEvent
and then later sent to BigQuery with sendEvents
.
You can enable logging for specific plugin functions:
new BigQueryAnalytics({ logging: { addEvent: true, sendEvents: true, }, // ... }),
addEvent
: This logs the event just after the optional call to theonAddEvent
function defined in config, or before being filtered by the optionaladdEventFilter
function.sendEvents
: Sends the events to BigQuery. If there are errors inserting the rows, they will be logged.
onAddEvent
As a final chance to update an event before it is added to the list of event to log, define the onAddEvent
function:
import { BigQueryAnalytics, AnalyticsEvent } from '@jovotech/analytics-bigquery'; // ... new BigQueryAnalytics({ onAddEvent: async (jovo: Jovo, event: AnalyticsEvent) => { event.timeZone = ''; }, // ... }),
This shows how you can use the TimeZone plugin to set the timezone:
import { BigQueryAnalytics, AnalyticsEvent } from '@jovotech/analytics-bigquery'; import { TimeZonePlugin } from '@jovo-community/plugin-timezone'; // ... plugins: [ new TimeZonePlugin(), new BigQueryAnalytics({ onAddEvent: async (jovo: Jovo, event: AnalyticsEvent) => { event.timeZone = await jovo.$timeZone.getTimeZone(); }, // ... }), ]
addEventFilter
Define a addEventFilter
function, in order to filter out events from being sent to BigQuery. This function returning or resolving to false
will filter the event out.
This shows how to filter out events with eventType === 'device_capabilities'
:
import { BigQueryAnalytics, AnalyticsEvent } from '@jovotech/analytics-bigquery'; // ... new BigQueryAnalytics({ addEventFilter: (jovo: Jovo, event: AnalyticsEvent) => event.eventType !== 'device_capabilities', // ... }),
Event Tracking
Common Properties
All calls to $bigQuery.addEvent(event)
track the following properties:
eventId
(string) - generated UUID for the eventappId
(string) - the appId from configeventDate
(string) - UTC date in ISO 8601 formatepochMilliseconds
(number) - the number of milliseconds elapsed since January 1, 1970 00:00:00 UTCepochSeconds
(number) - the number of seconds elapsed since January 1, 1970 00:00:00 UTClocale
(string) - the locale from the request (ex: 'en' or 'en-US')timeZone
(string) - timeZone from the request (ex: 'America/Phoenix') if it exists. UseonAddEvent
for platforms that don't pass the timeZone in the request.userId
(string) - platform-supplied user idsessionId
(string) - platform-supplied session idrequestId
(string) - generated UUID that groups all events for a given request
Built-in Events
The following events are tracked automatically and add additional properties (as shown):
-
device_capabilities
deviceId
(string) - the platform-supplied device idsupportScreen
(boolean) - if device supports a screensupportAudio
(boolean) - if device supports SSML audiosupportLongformAudio
(boolean) - if device supports long-form audiosupportVideo
(boolean) - if device supports video
-
error
errorName
(string) - the name of the errormessage
(string) - the error messagestack
(string) - the error stack trace
-
execute_handler
component
(string) - the name of the componenthandler
(string) - the name of the handler
-
intent
intent
(string) - the resolved intent
-
intent_entity
intent
(string) - the resolved intententityName
(string) - the name of the entityentityId
(string) - the id of the entityentityResolved
(string) - the resolved value of the entityentityValue
(string) - the value of the entity
-
new_user (only common properties)
-
request_start (only common properties)
-
request_end
elapsed
(number) - milliseconds since request_start event
-
session_start (only common properties)
-
session_end
elapsed
(number) - milliseconds since session_start eventreason
(string) - reason for the session to end ('user' or 'error')
-
transcript
transcriptText
(string) - the text transcription from ASR
Custom Events
Include your own custom events by calling $bigQuery.addEvent(event)
or $bigQuery.addError(error)
.
For any custom properties you add in code, update the Google BigQuery table schema to include them.
Event
await this.$bigQuery.addEvent({ eventType: 'game_start', player: 'player-name', });
Error
try { //... } catch (error) { await this.$bigQuery.addError(error); }