# ウェブチャットをGoogle analytics,Google tag managerでトラッキングする方法

**URL:** <https://community.hubspot.com/t/google-analytics-google-tag-manager/21441>\
**Category:** Tips, Tricks & Best Practices\
**Created:** [June 5, 2020, 1:33am UTC](https://community.hubspot.com/t/google-analytics-google-tag-manager/21441 "2020-06-05T01:33:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fishburger](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fishburger/32/12855_2.png) [@fishburger](https://community.hubspot.com/u/fishburger)\
**Post date:** [June 5, 2020, 1:33am UTC](https://community.hubspot.com/t/google-analytics-google-tag-manager/21441/1 "2020-06-05T01:33:40Z")

</div>

ウェブチャット（[https://www.hubspot.jp/products/crm/live-chat）でユーザーが何かしらメッセージを送信したら、Google](https://www.hubspot.jp/products/crm/live-chat%EF%BC%89%E3%81%A7%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E3%81%8C%E4%BD%95%E3%81%8B%E3%81%97%E3%82%89%E3%83%A1%E3%83%83%E3%82%BB%E3%83%BC%E3%82%B8%E3%82%92%E9%80%81%E4%BF%A1%E3%81%97%E3%81%9F%E3%82%89%E3%80%81Google) analyticsのコンバージョンとして計測できればといろいろ試しています。

ただ、下記ページを参考に試してみましたがうまくいきませんでした。。。。

参考ページ

[https://community.hubspot.com/t5/forums/replypage/board-id/marketing\_reports/message-id/1653](https://community.hubspot.com/t5/forums/replypage/board-id/marketing_reports/message-id/1653)

[https://developers.hubspot.com/docs/methods/conversations\_api/hubspot-conversations-javascript-api](https://developers.hubspot.com/docs/methods/conversations_api/hubspot-conversations-javascript-api)

例えば、下記のようにしてもコンソールにログすら出力されませんでした。

Goolge tag managerの「タグ：カスタムHTML」に下記のように書きました。

タグのトリガーは「All pages」です。

```auto
<script type="text/javascript">
 function onConversationsAPIReady() {
 console.log('テスト'`);
 }
</script>

```

または

```auto
<script>
window.HubSpotConversations.on('conversationStarted', function(payload){
 console.log('テスト');
});
</script>

```

APIの使い方をなにか間違えているのかもしれません。。。

どなたかご存知の方がいたら教えていただけるとうれしいです。

---

<div class="post-metadata">

**Author:** ![natsumimori](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/natsumimori/32/39807_2.png) [@natsumimori](https://community.hubspot.com/u/natsumimori)\
**Post date:** [June 9, 2020, 4:54am UTC](https://community.hubspot.com/t/google-analytics-google-tag-manager/21441/2 "2020-06-09T04:54:31Z")

</div>

@fishburger さん、HubSpotコミュニティーへようこそ！

コミュニティーのトップコントリビューターからアドバイスがあるか聞いてみますね。

@assi さん、こちらいかがでしょうか？

---

<div class="post-metadata">

**Author:** ![natsumimori](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/natsumimori/32/39807_2.png) [@natsumimori](https://community.hubspot.com/u/natsumimori)\
**Post date:** [June 11, 2020, 1:32am UTC](https://community.hubspot.com/t/google-analytics-google-tag-manager/21441/3 "2020-06-11T01:32:07Z")

</div>

@littlehelp さんもタグしますね。

---

<div class="post-metadata">

**Author:** ![assi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/assi/32/25699_2.png) [@assi](https://community.hubspot.com/u/assi)\
**Post date:** [June 15, 2020, 5:34am UTC](https://community.hubspot.com/t/google-analytics-google-tag-manager/21441/4 "2020-06-15T05:34:23Z")

</div>

すみません、検証に時間がかかりそうなのですが最近なかなか忙しく、6月中のどこかで検証してみますm(\_ \_)m

---

<div class="post-metadata">

**Author:** ![littlehelp](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/littlehelp/32/30934_2.png) [@littlehelp](https://community.hubspot.com/u/littlehelp)\
**Post date:** [June 16, 2020, 10:44am UTC](https://community.hubspot.com/t/google-analytics-google-tag-manager/21441/5 "2020-06-16T10:44:47Z")

</div>

ウェブチャットの読み込みが完了する前にイベントハンドラの設定を行っていることが原因かなと思います。

もしよかったら下記のコードを試してみていただけますでしょうか。

```auto
<script>
window.hsConversationsOnReady = [function () {
 window.HubSpotConversations.on('conversationStarted', function(payload){
 console.log('テスト');
 });
}];
</script>

```

ウェブチャットの読み込みが完了した後にイベントハンドラを設定するようfishburgerさんのコードを修正しました。

参考）Execute functions when HubSpotConversations loads:

[https://developers.hubspot.com/docs/methods/conversations\_api/hsconversationsonready](https://developers.hubspot.com/docs/methods/conversations_api/hsconversationsonready)

---

<div class="post-metadata">

**Author:** ![natsumimori](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/natsumimori/32/39807_2.png) [@natsumimori](https://community.hubspot.com/u/natsumimori)\
**Post date:** [June 17, 2020, 1:10am UTC](https://community.hubspot.com/t/google-analytics-google-tag-manager/21441/6 "2020-06-17T01:10:56Z")

</div>

@assi さん、 @littlehelp さん、お二人ともありがとうございます！

@fishburger さん、ぜひ上記のアドバイスを参考にされてみてください。

---

<div class="post-metadata">

**Author:** ![fishburger](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fishburger/32/12855_2.png) [@fishburger](https://community.hubspot.com/u/fishburger)\
**Post date:** [June 17, 2020, 11:13pm UTC](https://community.hubspot.com/t/google-analytics-google-tag-manager/21441/7 "2020-06-17T23:13:08Z")

</div>

littlehelpさん

ありがとうございます！

教えていただいた方法でコンソールログを出力することが来ました。

このやり方でGTMのdatalayerに送信すれば、コンバージョンを計測することができそうです。

---

<div class="post-metadata">

**Author:** ![littlehelp](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/littlehelp/32/30934_2.png) [@littlehelp](https://community.hubspot.com/u/littlehelp)\
**Post date:** [June 17, 2020, 11:29pm UTC](https://community.hubspot.com/t/google-analytics-google-tag-manager/21441/8 "2020-06-17T23:29:18Z")

</div>

fishburgerさん、  
わー！よかったです！ご丁寧にご報告をありがとうございました。
