Insights lets you export your Insights conversation and analysis data to BigQuery so that you can perform your own raw queries. The export process writes a schema that is similar to the Speech Analysis Framework. This guide details the export process.
Create a new BigQuery table and dataset
The Insights Exporter requires a BigQuery table in order for the operation to be successful. If you don't have a target table, use this sample to create a new table and dataset using the bq command-line tool. See the BigQuery schema documentation for the output schema and column definitions.
BigQuery has some restrictions on the location of its data source.
See
Location considerations.
Restrictions that apply to Cloud Storage buckets also apply to
Insights. For example, if your BigQuery dataset is in the EU
multi-region location, you can only export Insights data from
one of the europe-*
locations.
bq mk --dataset --location=LOCATION PROJECT:DATASET bq mk --table PROJECT:DATASET.TABLE
Export conversation data to BigQuery
The export tool supports both filtering and writing data to customer-managed encryption key (CMEK)-protected tables. If you don't want to enable this feature, you can skip ahead and export your data to BigQuery.
Add filtering to the request (Optional)
Export to BigQuery is compatible with all combinations of filters that can be
applied to conversation queries.
For example, the following sample will export all conversations with 10 or more
turns handled by agent_id
"007" between January 1st 2021 and January 2nd 2021
PST:
FILTER='create_time>"2021-01-01T00:00:00-08:00" create_time<"2021-01-02T00:00:00-08:00" agent_id="007" turn_count>="10"'
Export data to a CMEK-protected table (Optional)
Provide your Insights service account with the Cloud KMS CryptoKey Encrypter/Decrypter role. See the known issues documentation about service account format. Once you have provided the correct role to your service account, add the fully-qualified name of the KMS key protecting the table to the export request:
KMS_KEY='projects/<project>/locations/<location>/keyRings/<key_ring>/cryptoKeys/<key_name>'
Specify write disposition option in the request (Optional)
CCAI Insights export supports the following write disposition options from BigQuery:
WRITE_TRUNCATE
: If the table already exists, BigQuery overwrites the table data and uses the schema from the query result. This is the default option.WRITE_APPEND
: If the table already exists, BigQuery appends the data to the table.
For example, the following sample will append the exported data to an existing destination table:
WRITE_DISPOSITION='WRITE_APPEND'
Export your data to BigQuery
The following code sample demonstrates how to export your data. See the export reference documentation for complete details.
The export creates a long-running Operation
object. You can
poll the operation
to check its status.
REST
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID.
- DATASET: the name of the BigQuery dataset that the data should be exported to.
- TABLE: the BigQuery table name that your Insights data should be written to.
- FILTER_QUERY: a query that Insights uses to export only conversations that have specific properties. For example, entering the value "agent_id=\"007\"" will result in only conversations associated with agent 007 being exported.
HTTP method and URL:
POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/insightsdata:export
Request JSON body:
{ "bigQueryDestination": { "projectId": "PROJECT_ID", "dataset": "DATASET", "table": "TABLE", }, "filter": "FILTER_QUERY" }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID" }
Python
To authenticate to Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to Insights, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Export data to another project (Optional)
By default, Insights BigQuery export writes data to the same project that owns the Insights data. However, you can also export to BigQuery in another project.
Ensure that your Insights service account has BigQuery access to
the recipient project using either the IAM console or with gcloud
:
gcloud projects add-iam-policy-binding RECEIVER_PROJECT \ --member=serviceAccount:service-PROJECT_NUMBER@gcp-sa-contactcenterinsights.iam.gserviceaccount.com \ --role=roles/bigquery.admin
To export your data to a specific project, input the recipient project's
ID number in the project_id
field in the BigQueryDestination
object.
Query the data in BigQuery
Run this command to query the data in BigQuery. See the BigQuery Quickstart documentation for more query options:
gcloud config set project PROJECT bq show DATASET.TABLE
Querying exported conversations:
bq query --use_legacy_sql=false \ "SELECT conversationName FROM DATASET.TABLE"