> ## Documentation Index
> Fetch the complete documentation index at: https://docs.timothe.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# アナリティクス連携

> セッションイベントを GA4・GTM・Meta Pixel など主要アナリティクスツールへ自動送信する仕組み

Turnint AI のエージェントウィジェットは、ページ上で検出されたアナリティクスツールへセッションイベントを**自動で送信**します。追加のコード記述は不要です。

## 仕組み

ウィジェットがイベントを発火する際、`window` 上に各アナリティクスツールのグローバル関数・オブジェクトが存在するかを検出し、見つかったすべてのツールへイベントを送信します。

<Info>
  GA4 (`gtag`) と GTM (`dataLayer`) は排他的に扱われます。`gtag` が検出された場合は GA4 のみに送信し、`dataLayer` への重複プッシュは行いません。これは `gtag` が内部的に `dataLayer` を使用するため、二重カウントを防止するためです。
</Info>

## 対応ツール

| ツール | 個別ページ |
| - | - |
| Google Analytics 4 | [GA4](/ja/integrations/analytics.ga4) |
| Google Tag Manager | [GTM](/ja/integrations/analytics.gtm) |
| Meta Pixel | [Meta Pixel](/ja/integrations/analytics.meta-pixel) |
| Segment | [Segment](/ja/integrations/analytics.segment) |
| Mixpanel | [Mixpanel](/ja/integrations/analytics.mixpanel) |
| Plausible | [Plausible](/ja/integrations/analytics.plausible) |
| KARTE | [KARTE](/ja/integrations/analytics.karte) |
| Braze | [Braze](/ja/integrations/analytics.braze) |
| PostHog | [PostHog](/ja/integrations/analytics.posthog) |
| Amplitude | [Amplitude](/ja/integrations/analytics.amplitude) |
| Heap | [Heap](/ja/integrations/analytics.heap) |
| HubSpot | [HubSpot](/ja/integrations/analytics.hubspot) |
| Pendo | [Pendo](/ja/integrations/analytics.pendo) |
| FullStory | [FullStory](/ja/integrations/analytics.fullstory) |
| RudderStack | [RudderStack](/ja/integrations/analytics.rudderstack) |

## イベント一覧

すべてのイベント名は `turnint_` プレフィックス付きのスネークケースで送信されます。

| イベント名 | 発火タイミング | 送信データ |
| - | - | - |
| `turnint_started` | セッション開始時 | `{ type: "started" }` |
| `turnint_ended` | セッション終了時 | `{ type: "ended" }` |
| `turnint_slide_viewed` | スライド閲覧時 | `{ type: "slide-viewed", id }` |
| `turnint_action_executed` | アクション実行時 | `{ type: "action-executed", actionId, actionLabel, actionExecType }` |
| `turnint_message_sent` | メッセージ送信時 | `{ type: "message-sent" }` |
| `turnint_context_updated` | ゲート（フォームなど）を通じてユーザー情報が識別されたとき | `{ type: "context-updated" }` |

<Note>
  プライバシー保護のため、メッセージ本文やコンテキストの詳細などの機密データはアナリティクスツールには送信されません。アクションについても、ID・ラベル・実行タイプのみが送信されます。
</Note>

## Portal での設定方法

Portal を使用している場合、ダッシュボードからアナリティクスタグを注入できます。

1. ダッシュボードの **ポータル設定** を開く
2. **詳細設定** セクションを展開
3. **ヘッドスクリプト** に計測タグを貼り付ける

各ツールの具体的なタグについては、個別ページを参照してください。

<Warning>
  ヘッドスクリプトには `<script>`, `<link>`, `<meta>`, `<style>`, `<noscript>` タグのみ使用できます。それ以外のタグは自動的に除去されます。
</Warning>

## CustomEvent API

すべてのイベントは `turnint:event` という名前の `CustomEvent` としても発火されます。独自のリスナーを登録することで、任意のハンドリングが可能です。

```javascript theme={null}
window.addEventListener("turnint:event", (event) => {
  const data = event.detail;
  console.log(data.type, data);
});
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.