create account

Google Assistant Chatbase Analytics guide by cm-steem

View this thread on: hive.blogpeakd.comecency.com
· @cm-steem · (edited)
$55.71
Google Assistant Chatbase Analytics guide
![](https://steemitimages.com/DQmWg9qqunbLxrabNNNASke63fuzi9ZsQYZ4TYTuK28AAkM/image.png)

# Google Assistant Chatbase analytics snippet

I couldn't find full examples of Chatbase integration for the Google Assistant other than the [snippets in the chatbase-node readme](https://github.com/google/chatbase-node/), so here's the snippet recently created for [Beyond Bitshares](https://steemit.com/bitshares/@cm-steem/beyond-bitshares-google-assistant-upgrading-to-latest-action-on-google-alpha-release).

Recently, Dialogflow announced further Chatbot integration [enabling session flow within the Dialogflow web UI](https://blog.dialogflow.com/post/session-flow-analytics/), despite these recent improvements there is still additional functionality available within Chatbase worth exploring.

A quote from the above blog post:

> We’re continually working with Chatbase, the cloud service for more easily analyzing and optimizing bots, on expanding the Analytics dashboard to help you monitor and improve agent performance.

### Why use Chatbase?

> #### Save time on bot analysis
> Track key metrics like active users, sessions, and retention across multiple chat platforms.
> #### Improve bot accuracy
> Automatically identify problems and get suggestions for doing quick optimizations via machine learning.
> #### Increase conversion rates
> Visualize the flow of conversations to understand how efficiently users interact with your bot.
>
> [Source](https://chatbase.com/welcome/)


## Pre-Reqs

Include the following dependencies in your package.json:

```
    "@google/chatbase": "^1.1.0",
    "actions-on-google": "2.0.0-alpha.2",
```

## Import the package: in your code:

Register on Chatbase, get your key and replace 'API_KEY' with it.

```
var chatbase = require('@google/chatbase')
              .setApiKey('API_KEY') // Your Chatbase API Key
              .setPlatform('Google Assistant'); // The type of message you are sending to chatbase: user (user) or agent (bot)
```

## Create functions for errors and invalid input

```
function catch_error(conv, error_message, intent) {
  /*
  Generic function for reporting errors & providing error handling for the user.
  */
  chatbase_analytics(
    conv,
    `Error within intent ${intent}`, // input_message
    intent, // input_intent
    'error' // win_or_fail
  );

  if(error_message instanceof Error) {
      console.error(error_message);
  } else {
      console.error(new Error(error_message));
  }
  return conv.close(
      new SimpleResponse({
      // If we somehow fail, do so gracefully!
      speech: "An unexpected error was encountered! Let's end our Beyond Bitshares session for now.",
      text: "An unexpected error was encountered! Let's end our Beyond Bitshares session for now."
    })
  );
}

function invalid_input(conv, intent_name) {
  /*
  Reducing code duplication.
  Replace conv.close with a direction to a fallback intent in the future!
  */
  chatbase_analytics(
    conv,
    `User input invalid data within intent ${intent_name}`, // input_message
    intent_name, // input_intent
    'fail' // win_or_fail
  );

  return conv.close(
      new SimpleResponse({
      // If we somehow fail, do so gracefully!
      speech: "You provided invalid input data, try again with alternative input!",
      text: "You provided invalid input data, try again with alternative input!"
    })
  );
}
```

## Then create the chatbase_analytics function: 

Similarly in this section, change the 'API_KEY' to your chatbase analytics key.

```
function chatbase_analytics(conv, input_message, input_intent, win_or_fail) {
  /*
  Integrating chatbase chat bot analytics.
  Will help optimize user experience whilst minimizing privacy impact.
  */
  var userId = conv.user.id;

  if (win_or_fail === 'Win') {
    // For reporting successful bot interaction
    chatbase.newMessage('API_KEY')
    .setPlatform('Google Assistant')
  	.setMessage(input_message)
  	.setVersion('1.0')
  	.setUserId(userId.toString())
    .setAsTypeUser() // sets the message as type user
    .setAsHandled() // set the message as handled -- this means the bot understood the message sent by the user
    .setIntent(input_intent) // the intent of the sent message (does not have to be set for agent messages)
    .setTimestamp(Date.now().toString()) // Only unix epochs with Millisecond precision
  	.send()
  	.then(msg => console.log(msg.getCreateResponse()))
  	.catch(err => console.error(err));
  } else {
    // For reporting fallback attempts
    chatbase.newMessage('API_KEY')
    .setPlatform('Google Assistant')
    .setMessage(input_message)
    .setVersion('1.0')
    .setUserId(userId.toString())
    .setAsTypeUser() // sets the message as type agent
    .setAsNotHandled() // set the message as not handled -- this means the opposite of the preceding
    .setIntent(input_intent) // the intent of the sent message (does not have to be set for agent messages)
    .setTimestamp(Date.now().toString()) // Only unix epochs with Millisecond precision
    .send()
    .then(msg => console.log(msg.getCreateResponse()))
    .catch(err => console.error(err));
  }
}
```

## Then finally - call the function at the end of intents

### For successful intent outcome

```
chatbase_analytics(
  conv,
  'About page', // input_message
  'About', // input_intent
  'Win' // win_or_fail
);
```

### For invalid user input outcome

```
return invalid_input(conv, `account_balances`);
```

### For handling errors

```
return catch_error(conv, error_message, 'account_balances');
```

### Input message contents?

Try to include useful information, like what the user did in the function, including potentially limited input variable information.

---

Have any questions about the above? Just write a comment below!


Cheers,
@cm-steem
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 168 others
properties (23)
authorcm-steem
permlinkgoogle-assistant-chatbase-analytics-guide
categorygoogle
json_metadata{"tags":["google","chatbase","bots","programming","bitshares"],"users":["cm-steem"],"image":["https://steemitimages.com/DQmWg9qqunbLxrabNNNASke63fuzi9ZsQYZ4TYTuK28AAkM/image.png"],"links":["https://github.com/google/chatbase-node/","https://steemit.com/bitshares/@cm-steem/beyond-bitshares-google-assistant-upgrading-to-latest-action-on-google-alpha-release","https://blog.dialogflow.com/post/session-flow-analytics/","https://chatbase.com/welcome/"],"app":"steemit/0.1","format":"markdown"}
created2018-03-25 22:32:00
last_update2018-03-31 13:00:57
depth0
children16
last_payout2018-04-01 22:32:00
cashout_time1969-12-31 23:59:59
total_payout_value45.247 HBD
curator_payout_value10.464 HBD
pending_payout_value0.000 HBD
promoted1.000 HBD
body_length5,792
author_reputation58,522,774,254,119
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,580,818
net_rshares21,921,275,999,545
author_curate_reward""
vote details (232)
@angelina66 · (edited)
$0.06
Google Assistant Chatbase useage very important for us. sometimes we want to more information & our ptoblemetic soluation. that time we knock to Googlr assistant chatbase & find out our answer.
>I trying to use by mobile phone, so many time i trying it but i can't to this.
I think this chatbase not available for mobile phone.

**@cm-steem Thank you so much for your kind information**
πŸ‘  
properties (23)
authorangelina66
permlinkre-cm-steem-google-assistant-chatbase-analytics-guide-20180326t160508797z
categorygoogle
json_metadata{"tags":["google"],"app":"steemit/0.1","users":["cm-steem"]}
created2018-03-26 16:05:21
last_update2018-03-26 16:06:51
depth1
children0
last_payout2018-04-02 16:05:21
cashout_time1969-12-31 23:59:59
total_payout_value0.045 HBD
curator_payout_value0.014 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length386
author_reputation1,649,340,563,353
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,723,197
net_rshares24,450,990,427
author_curate_reward""
vote details (1)
@atjehsteemit ·
Very nice post and good information
πŸ‘  
properties (23)
authoratjehsteemit
permlinkre-cm-steem-google-assistant-chatbase-analytics-guide-20180325t234524566z
categorygoogle
json_metadata{"tags":["google"],"app":"steemit/0.1"}
created2018-03-25 23:45:27
last_update2018-03-25 23:45:27
depth1
children0
last_payout2018-04-01 23:45:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length35
author_reputation1,134,338,995,221
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,588,601
net_rshares6,112,747,606
author_curate_reward""
vote details (1)
@ava66 ·
$0.06
i don't knew about Google have any Chatbase, if it have then it is very well for us. how can I  Register on Chatbase??
I am very intersted & excited so @cm-steem you if you have any link fot registration so give me please. I needed.
πŸ‘  
properties (23)
authorava66
permlinkre-cm-steem-google-assistant-chatbase-analytics-guide-20180326t161456272z
categorygoogle
json_metadata{"tags":["google"],"users":["cm-steem"],"app":"steemit/0.1"}
created2018-03-26 16:15:09
last_update2018-03-26 16:15:09
depth1
children2
last_payout2018-04-02 16:15:09
cashout_time1969-12-31 23:59:59
total_payout_value0.045 HBD
curator_payout_value0.014 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length232
author_reputation204,104,148,889
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,724,884
net_rshares24,450,990,427
author_curate_reward""
vote details (1)
@cm-steem ·
https://chatbase.com/welcome

Uses a google authentication system, so make a google account :)
πŸ‘  
properties (23)
authorcm-steem
permlinkre-ava66-re-cm-steem-google-assistant-chatbase-analytics-guide-20180326t195806058z
categorygoogle
json_metadata{"tags":["google"],"links":["https://chatbase.com/welcome"],"app":"steemit/0.1"}
created2018-03-26 19:58:06
last_update2018-03-26 19:58:06
depth2
children1
last_payout2018-04-02 19:58:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length94
author_reputation58,522,774,254,119
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,759,402
net_rshares879,115,782
author_curate_reward""
vote details (1)
@ava66 ·
okay. thanks for your kind information. 
properties (22)
authorava66
permlinkre-cm-steem-re-ava66-re-cm-steem-google-assistant-chatbase-analytics-guide-20180327t074636181z
categorygoogle
json_metadata{"tags":["google"],"community":"busy","app":"busy/2.4.0"}
created2018-03-27 07:46:39
last_update2018-03-27 07:46:39
depth3
children0
last_payout2018-04-03 07:46:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length40
author_reputation204,104,148,889
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,847,357
net_rshares0
@dmilliz ·
$0.40
Wow way too advanced for me ! Gotta research this more.
πŸ‘  ,
properties (23)
authordmilliz
permlinkre-cm-steem-google-assistant-chatbase-analytics-guide-20180326t002255301z
categorygoogle
json_metadata{"tags":["google"],"app":"steemit/0.1"}
created2018-03-26 00:22:57
last_update2018-03-26 00:22:57
depth1
children0
last_payout2018-04-02 00:22:57
cashout_time1969-12-31 23:59:59
total_payout_value0.304 HBD
curator_payout_value0.099 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length55
author_reputation252,325,572,793,175
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,592,779
net_rshares159,843,113,405
author_curate_reward""
vote details (2)
@ebargains ·
$0.07
re-cm-steem-google-assistant-chatbase-analytics-guide-20180326t002629372z
You got a 66.67% upvote and resteem from @ebargains courtesy of @cm-steem. Thank you for using the @ebargains UPVOTE and RESTEEM bot. 

If you are looking to earn a passive no hassle return on your Steem Power, delegate your SP to @ebargains by clicking on one of the ready to delegate links:
[50SP](https://steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=ebargains&vesting_shares=50%20SP) | [100SP](https://steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=ebargains&vesting_shares=100%20SP) | [250SP](https://steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=ebargains&vesting_shares=250%20SP) | [500SP](https://steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=ebargains&vesting_shares=500%20SP) | [1000SP](https://steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=ebargains&vesting_shares=1000%20SP) | [5000SP](https://steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=ebargains&vesting_shares=5000%20SP) | [Custom Amount](https://steembottracker.com/delegation.html?delegatee=ebargains)
 
You will earn 80% of the voting bot's earnings based on your delegated SP's prorated share of the bot's SP pool at the end of EACH voting round! That is up to 38.5% APR! You can also undelegate at anytime.
πŸ‘  
properties (23)
authorebargains
permlinkre-cm-steem-google-assistant-chatbase-analytics-guide-20180326t002629372z
categorygoogle
json_metadata{"app":"postpromoter/1.9.2"}
created2018-03-26 00:26:30
last_update2018-03-26 00:26:30
depth1
children0
last_payout2018-04-02 00:26:30
cashout_time1969-12-31 23:59:59
total_payout_value0.067 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,292
author_reputation46,529,372,336,823
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,593,166
net_rshares26,972,041,484
author_curate_reward""
vote details (1)
@hak4life ·
nice post @cm-steem
>* You can use Tisko Bot to promote your post.
Send 0.200 STEEM/SBD and the URL in the memo to @tisko to use the bot for a resteem and to get 5 good upvots.
>[Click here to see how to use Tisko Bot.](https://steemit.com/ts/@tisko/tisko-bot-faq)
properties (22)
authorhak4life
permlinkre-cm-steem-google-assistant-chatbase-analytics-guide-20180326t182155935z
categorygoogle
json_metadata{"tags":["google"],"users":["cm-steem","tisko"],"links":["https://steemit.com/ts/@tisko/tisko-bot-faq"],"app":"steemit/0.1"}
created2018-03-26 18:22:00
last_update2018-03-26 18:22:00
depth1
children0
last_payout2018-04-02 18:22:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length264
author_reputation8,256,053,055
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,745,401
net_rshares0
@prince121 ·
$0.41
Google always gives us wonderful and interesting facilities and product...
Chatbase is one of them, It has really amazing facilities...specially Improve bot accuracy...its just fabulous.. I  have a question..i use it in laptop. Is chatbase mobile apps  has been launched?? @cm-steem
πŸ‘  
properties (23)
authorprince121
permlinkre-cm-steem-google-assistant-chatbase-analytics-guide-20180326t063250962z
categorygoogle
json_metadata{"tags":["google"],"users":["cm-steem"],"app":"steemit/0.1"}
created2018-03-26 06:32:51
last_update2018-03-26 06:32:51
depth1
children2
last_payout2018-04-02 06:32:51
cashout_time1969-12-31 23:59:59
total_payout_value0.309 HBD
curator_payout_value0.102 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length282
author_reputation9,599,341,656,885
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,637,893
net_rshares161,987,811,582
author_curate_reward""
vote details (1)
@cm-steem ·
> Is chatbase mobile apps has been launched??

Not sure, I'm only using the web interface for their analytics, it does appear that they offer A/B testing functionality to mobile devices, that'd be great in the google assistant! I don't see any official chatbase android app though.
properties (22)
authorcm-steem
permlinkre-prince121-re-cm-steem-google-assistant-chatbase-analytics-guide-20180326t121053088z
categorygoogle
json_metadata{"tags":["google"],"app":"steemit/0.1"}
created2018-03-26 12:10:54
last_update2018-03-26 12:10:54
depth2
children1
last_payout2018-04-02 12:10:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length281
author_reputation58,522,774,254,119
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,683,101
net_rshares0
@prince121 ·
Thanks @cm-steem.. If there have no chatbase official mobile apps, hope that mobile apps will be launched soon...
properties (22)
authorprince121
permlinkre-cm-steem-re-prince121-re-cm-steem-google-assistant-chatbase-analytics-guide-20180326t124727377z
categorygoogle
json_metadata{"tags":["google"],"community":"busy","app":"busy/2.4.0"}
created2018-03-26 12:47:30
last_update2018-03-26 12:47:30
depth3
children0
last_payout2018-04-02 12:47:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length113
author_reputation9,599,341,656,885
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,688,729
net_rshares0
@rehenuma ·
$0.10
@cm-steem its really amazing. thanks for this important information share with us. I have question for you. if i lost my code then what can i do?
πŸ‘  
properties (23)
authorrehenuma
permlinkre-cm-steem-google-assistant-chatbase-analytics-guide-20180326t194102047z
categorygoogle
json_metadata{"tags":["google"],"users":["cm-steem"],"app":"steemit/0.1"}
created2018-03-26 19:41:09
last_update2018-03-26 19:41:09
depth1
children2
last_payout2018-04-02 19:41:09
cashout_time1969-12-31 23:59:59
total_payout_value0.103 HBD
curator_payout_value0.001 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length145
author_reputation605,322,909,819
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,756,951
net_rshares42,789,233,248
author_curate_reward""
vote details (1)
@cm-steem ·
If you lost your chatbase api key code? You can easily retrieve it from their web ui.
properties (22)
authorcm-steem
permlinkre-rehenuma-re-cm-steem-google-assistant-chatbase-analytics-guide-20180326t194302108z
categorygoogle
json_metadata{"tags":["google"],"app":"steemit/0.1"}
created2018-03-26 19:43:03
last_update2018-03-26 19:43:03
depth2
children1
last_payout2018-04-02 19:43:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length85
author_reputation58,522,774,254,119
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,757,234
net_rshares0
@rehenuma ·
oh i see. that's good. @cm-steem thanks for your feedback. tomorrow i will be registerd on here. i hope it will be well.
properties (22)
authorrehenuma
permlinkre-cm-steem-re-rehenuma-re-cm-steem-google-assistant-chatbase-analytics-guide-20180326t200744074z
categorygoogle
json_metadata{"tags":["google"],"users":["cm-steem"],"app":"steemit/0.1"}
created2018-03-26 20:07:48
last_update2018-03-26 20:07:48
depth3
children0
last_payout2018-04-02 20:07:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length120
author_reputation605,322,909,819
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,760,740
net_rshares0
@saiful39 ·
nice information&post 
@upvote & @resteem done
properties (22)
authorsaiful39
permlinkre-cm-steem-google-assistant-chatbase-analytics-guide-20180326t025511573z
categorygoogle
json_metadata{"tags":["google"],"users":["upvote","resteem"],"app":"steemit/0.1"}
created2018-03-26 02:55:15
last_update2018-03-26 02:55:15
depth1
children0
last_payout2018-04-02 02:55:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length46
author_reputation9,197,601,696,972
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,610,930
net_rshares0
@tts ·
$0.39
To listen to the audio version of this article click on the play image.
[![](https://s18.postimg.org/51o0kpijd/play200x46.png)](http://ec2-52-72-169-104.compute-1.amazonaws.com/cm-steem__google-assistant-chatbase-analytics-guide.mp3)
Brought to you by [@tts](https://steemit.com/tts/@tts/introduction). If you find it useful please consider upvote this reply.
πŸ‘  ,
properties (23)
authortts
permlinkre-google-assistant-chatbase-analytics-guide-20180325t230126
categorygoogle
json_metadata""
created2018-03-25 23:01:27
last_update2018-03-25 23:01:27
depth1
children0
last_payout2018-04-01 23:01:27
cashout_time1969-12-31 23:59:59
total_payout_value0.294 HBD
curator_payout_value0.095 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length359
author_reputation-4,535,154,553,995
root_title"Google Assistant Chatbase Analytics guide"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,584,030
net_rshares153,716,411,579
author_curate_reward""
vote details (2)