{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/ja/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Treasure AI モバイル SDK でのセッショントラッキング","description":"Treasure AI モバイル SDK のグローバルセッションとインスタンスセッションの違い、td_session_id と td_session_event の仕組み、セッションタイムアウト、使い分けを解説します。","siteUrl":"https://docs.treasure.ai","lang":"en-US","jsonLd":{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.treasure.ai/","name":"Treasure AI","url":"https://www.treasure.ai/","logo":"https://www.treasure.ai/hubfs/assets/images/logos/primary-logo.svg"},{"@type":"WebSite","@id":"https://docs.treasure.ai/#website","name":"Treasure AI Documentation","url":"https://docs.treasure.ai/","inLanguage":["en","ja"],"publisher":{"@id":"https://www.treasure.ai/"}}]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"モバイル-sdk-でのセッショントラッキング","__idx":0},"children":["モバイル SDK でのセッショントラッキング"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["セッションは、アプリが送信するイベントをひとまとまりのユーザーアクティビティ期間としてグループ化する仕組みです。セッションを使うと、ユーザーの滞在時間、1 回の利用で行った操作、コンバージョンが発生した訪問などを、訪問単位で分析できます。Treasure AI のモバイル SDK（Android、iOS、Unity、Cordova、React Native）には、",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["インスタンスセッション"]},"と",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["グローバルセッション"]},"という 2 つのセッション機構があり、スコープ、書き込まれる列、セッションの開始・終了イベントを記録するかどうかが異なります。このページでは両方の機構を定義し、それぞれがテーブルに何を書き込むかを示し、適切な使い分けを解説します。インストールや一般的なイベントトラッキングについては、",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#sdk-%E3%81%94%E3%81%A8%E3%81%AE%E3%82%BB%E3%83%83%E3%82%B7%E3%83%A7%E3%83%B3-api"},"children":["SDK ごとのセッション API"]}," にリンクされている各 SDK のページを参照してください。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"グローバルセッションとインスタンスセッションの違い","__idx":1},"children":["グローバルセッションとインスタンスセッションの違い"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["インスタンスセッション"]},"は、1 つの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TreasureData"]}," インスタンスにスコープされます。開始時に明示的な開始イベントを、終了時に明示的な終了イベントを、指定したテーブルに記録します。",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["グローバルセッション"]},"は、アプリ内のすべての ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TreasureData"]}," インスタンスで共有されます。グローバルセッション自体はイベントを記録しません。代わりに、アクティブな間にトラッキングされるすべてのイベントに共有の ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," を付与し、短い中断の後にセッションを再開できるため、短時間のアプリ切り替えを 1 つのセッションとして扱えます。"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"width":"30%","data-label":"項目"},"children":["項目 "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"35%","data-label":"インスタンスセッション"},"children":["インスタンスセッション "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"35%","data-label":"グローバルセッション"},"children":["グローバルセッション "]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["スコープ"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["1 つの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TreasureData"]}," インスタンス"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["アプリ全体 — すべての ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TreasureData"]}," インスタンスで共有"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["開始と終了の方法"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["テーブル名を取るインスタンスメソッド。例: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession(\"demotbl\")"]}," と ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession(\"demotbl\")"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["テーブル引数を取らない static（クラスレベル）メソッド。例: Android の ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TreasureData.startSession(context)"]}," と ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TreasureData.endSession(context)"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_event"]}," の開始・終了イベントを記録"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["はい — 開始時と終了時にそれぞれ 1 レコードを、指定したテーブルに記録"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["いいえ — グローバルセッション自体はイベントを一切書き込まない"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["トラッキングしたイベントへの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," の付与"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["はい（セッションがアクティブな間）"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["はい（セッションがアクティブな間）。両方のセッションがアクティブな場合はグローバルセッションの ID が優先される"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["想定される用途"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["開始・終了レコードによる明示的なセッション境界 — 例: チェックアウトフローを 1 つの単位としてトラッキング"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["セッションタイムアウトを利用して、短い中断（画面回転、短時間のアプリ切り替え）を 1 つの連続したセッションとして扱う"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"セッションがテーブルに書き込む内容","__idx":2},"children":["セッションがテーブルに書き込む内容"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["SDK が管理する専用のセッションテーブルはありません。セッションは、イベントをストリーミングしているテーブルに次の列を追加します。"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," — セッションを識別する UUID 文字列。セッションがアクティブな間にトラッキングされるすべてのイベントに、SDK が自動的に追加します。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_event"]}," — ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["start"]}," または ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["end"]},"。インスタンスセッションのみが書き込みます。",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession"]}," と ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession"]}," はそれぞれ、この列を含むレコードを 1 件、指定したテーブルに追加します。"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["たとえば、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession(\"demotbl\")"]}," を呼び出し、その後 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession(\"demotbl\")"]}," を呼び出すと、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["demotbl"]}," に次の 2 レコードが生成されます。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"[\n  {\"td_session_id\": \"cad88260-67b4-0242-1329-2650772a66b1\", \"td_session_event\": \"start\", \"time\": 1418880000},\n  {\"td_session_id\": \"cad88260-67b4-0242-1329-2650772a66b1\", \"td_session_event\": \"end\", \"time\": 1418880123}\n]\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["この 2 つの呼び出しの間にトラッキングした他のイベントには、送信先のテーブルがどこであっても同じ ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," が付与されます。",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession"]}," と ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession"]}," にメインのイベントテーブルを渡してセッション境界とイベントを同じテーブルにまとめることも、開始・終了レコード用に専用テーブルを使うこともできます。いずれの場合も、セッションの分析は ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," でイベントをグループ化して行います。",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_uuid"]},"（デバイス ID）などのオプション列は、有効化していれば併せて出力されます。詳細は ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/integration-hub/streaming/mobile/about-mobile-tracking-and-mobile-sdks"},"children":["About Mobile Tracking and Mobile SDKs"]}," を参照してください。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"グローバルセッションタイムアウトの仕組み","__idx":3},"children":["グローバルセッションタイムアウトの仕組み"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["グローバルセッションは、グローバルの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession"]}," を呼び出しても即座には終了しません。セッション ID はセッションタイムアウトの長さ（デフォルト 10 秒）だけ保持されます。そのウィンドウ内にアプリがグローバルの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession"]}," を再度呼び出すと、前のセッションが同じ ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," で再開され、新しいセッションは作成されません。ウィンドウを過ぎると、次の ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession"]}," で新しいセッション ID が生成されます。これにより、Android の Activity の破棄・再生成や、ユーザーが一時的にアプリを離れた場合でもセッションを継続できます。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["主な動作:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Android と iOS では、セッションを開始する前に ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TreasureData.setSessionTimeoutMilli(...)"]}," でウィンドウを変更できます。Unity では再開ウィンドウは 10 秒です。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["グローバルの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession"]}," の後は、セッションがまだ再開可能な間でも、グローバルの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["getSessionId"]}," は ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["null"]}," を返します。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["resetSessionId"]},"（Android と iOS）を呼び出すと、新しいグローバルセッション ID が直ちに生成され、以降のイベントは前のセッションに関連付けられなくなります。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["セッション ID はメモリ内にのみ保持されます。アプリのプロセスが強制終了されると現在のセッション ID は破棄され、タイムアウトに関係なく、次回の起動で新しいセッションが開始されます。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["SDK が自動的にセッションを開始・終了することはなく、アプリがフォアグラウンドにある間に非アクティブでセッションが失効することもありません。セッションが終了するのは、アプリが ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession"]}," を呼び出したとき、またはプロセスが終了したときだけです。セッション API はアプリのライフサイクルコールバックから呼び出してください — 例: Android の ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["onStart"]},"/",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["onStop"]},"、iOS の ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["applicationDidBecomeActive:"]},"/",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["applicationDidEnterBackground:"]},"。"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Web およびアプリ分析で一般的な慣例は 30 分の非アクティブウィンドウです。この動作にするには、タイムアウトを 30 分に設定し、アプリがフォアグラウンドに出入りするタイミングでグローバルセッションを開始・終了します。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"// Android — onCreate 内\nTreasureData.setSessionTimeoutMilli(30 * 60 * 1000); // 30 分\n\n// onStart 内 / アプリがフォアグラウンドに入ったとき\nTreasureData.startSession(this);\n\n// onStop 内 / アプリがフォアグラウンドから出たとき\nTreasureData.endSession(this);\nTreasureData.sharedInstance().uploadEvents();\n","lang":"java"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["この設定では、30 分未満の間隔で発生したフォアグラウンド訪問は 1 つの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," を共有し、30 分以上経ってから（またはプロセスが強制終了された後に）戻ると新しいセッションが開始されます。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"session_start-と-session_end-イベントの記録","__idx":4},"children":["session_start と session_end イベントの記録"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_event"]}," レコードを書き込むのはインスタンスセッションだけです。グローバルの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession"]}," と ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession"]}," は、イベントに付与される ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," を変更するだけで、イベント自体は送信しません。そのため、グローバル API のみでセッションをトラッキングしている場合、テーブルには明示的な開始・終了レコードは存在しません。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["グローバル API でセッションを管理しつつ境界イベントも必要な場合 — たとえばセッション開始を分析したい、後続の処理をトリガーしたい場合 — は、セッションを開始・終了するのと同じ箇所で ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["addEvent"]}," を使って自分で記録します。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"// Android\nTreasureData.startSession(this);\nMap<String, Object> event = new HashMap<>();\nevent.put(\"event\", \"session_start\");\nTreasureData.sharedInstance().addEvent(\"demotbl\", event);\n","lang":"java"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["グローバルセッションがアクティブなため、このレコードには現在の ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," が自動的に付与されます。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["セッションタイムアウトとの相互作用に注意してください。ユーザーがタイムアウトウィンドウ内に離脱して戻ってきた場合、訪問ごとに独自の開始・終了レコードが生成されますが、SDK が同じセッションを再開したため、それらはすべて 1 つの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," を共有します。これは想定どおりの動作です — 各レコードはフォアグラウンド訪問の境界を示し、共有された ID がそれらの訪問を 1 つのセッションにグループ化します。訪問ごとに別のセッションにしたい場合は、タイムアウトを短くするか、新しいセッションを開始する前に ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["resetSessionId"]}," を呼び出してください。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"グローバルセッションとインスタンスセッションの併用","__idx":5},"children":["グローバルセッションとインスタンスセッションの併用"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["両方のセッションタイプを同時に実行することは避けてください。インスタンスセッションとグローバルセッションの両方がアクティブな場合、グローバルセッションが優先されます。トラッキングされるすべてのイベント — インスタンスの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession"]}," と ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession"]}," が書き込む開始・終了レコードを含む — にはグローバルセッションの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," が付与され、インスタンスセッションの ID は無視されます。この状態になると SDK は警告をログに出力します。2 つの ID はそれぞれ独立して生成された別の値であり、グローバルセッションがアクティブな間、インスタンスセッションの ID が書き込まれることはありません。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["アプリごとに 1 つの機構を選んでください。短い中断をまたいで継続するアプリ全体のセッションが必要ならグローバルセッションを、追加のコードなしで明示的な開始・終了レコードが必要ならインスタンスセッションを使います。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"sdk-ごとのセッション-api","__idx":6},"children":["SDK ごとのセッション API"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["メソッド名は SDK ごとに異なります。Cordova と React Native のプラグインはインスタンスセッションのみを公開しています。"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"width":"16%","data-label":"SDK"},"children":["SDK "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"34%","data-label":"インスタンスセッション"},"children":["インスタンスセッション "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"50%","data-label":"グローバルセッション"},"children":["グローバルセッション "]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/integration-hub/streaming/mobile/android"},"children":["Android"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession(table)"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession(table)"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["getSessionId()"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TreasureData.startSession(context)"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TreasureData.endSession(context)"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TreasureData.getSessionId(context)"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TreasureData.setSessionTimeoutMilli(millis)"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TreasureData.resetSessionId(context)"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/integration-hub/streaming/mobile/ios"},"children":["iOS"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession:"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession:"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["getSessionId"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["[TreasureData startSession]"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["[TreasureData endSession]"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["[TreasureData getSessionId]"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["[TreasureData setSessionTimeoutMilli:]"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["[TreasureData resetSessionId]"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/int/unity-sdk"},"children":["Unity"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["StartSession(tableName)"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["EndSession(tableName)"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GetSessionId()"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["StartGlobalSession()"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["EndGlobalSession()"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GetGlobalSessionId()"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/integration-hub/streaming/mobile/cordova/api"},"children":["Cordova"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession(sessionTable, sessionDatabase)"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession(sessionTable, sessionDatabase)"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["プラグインでは公開されていません"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/integration-hub/streaming/mobile/react-native/api"},"children":["React Native"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession(sessionTable, sessionDatabase)"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession(sessionTable, sessionDatabase)"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["プラグインでは公開されていません"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"よくある質問","__idx":7},"children":["よくある質問"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"イベントに-td_session_event-がないのはなぜですか","__idx":8},"children":["イベントに td_session_event がないのはなぜですか？"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["グローバルセッションは ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_event"]}," を書き込みません。開始・終了イベントを記録するのは、インスタンスの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startSession(table)"]}," と ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["endSession(table)"]}," メソッドだけです。グローバルセッション API を使用していて境界レコードが必要な場合は、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["addEvent"]}," で自分で追加してください。",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#session_start-%E3%81%A8-session_end-%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E3%81%AE%E8%A8%98%E9%8C%B2"},"children":["session_start と session_end イベントの記録"]},"を参照してください。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"アプリを強制終了するとグローバルセッション-id-はリセットされますか","__idx":9},"children":["アプリを強制終了するとグローバルセッション ID はリセットされますか？"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["はい。セッション ID はメモリ内にのみ保持されるため、アプリを強制終了する（または OS がプロセスを終了する）と、現在のグローバルセッション ID は破棄されます。セッションタイムアウトウィンドウ内であっても、次回の起動では新しい ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," で新しいセッションが開始されます。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"グローバルセッションとインスタンスセッションは同時に使えますか","__idx":10},"children":["グローバルセッションとインスタンスセッションは同時に使えますか？"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["技術的には両方をアクティブにできますが、SDK は警告をログに出力し、インスタンスセッションの ID は無視されます。インスタンスセッション自身の開始・終了レコードを含むすべてのイベントには、グローバルの ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," が付与されます。アプリごとに 1 つの機構を使用してください。",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#%E3%82%B0%E3%83%AD%E3%83%BC%E3%83%90%E3%83%AB%E3%82%BB%E3%83%83%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%A8%E3%82%A4%E3%83%B3%E3%82%B9%E3%82%BF%E3%83%B3%E3%82%B9%E3%82%BB%E3%83%83%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%AE%E4%BD%B5%E7%94%A8"},"children":["グローバルセッションとインスタンスセッションの併用"]},"を参照してください。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"mobile-in-app-messaging-にはどちらのセッションタイプを使うべきですか","__idx":11},"children":["Mobile In-App Messaging にはどちらのセッションタイプを使うべきですか？"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["記録したい内容に合った機構を使用してください。In-App Messaging のロジックが明示的なセッション開始・終了イベントをトリガーとする場合、インスタンスセッションはそれらを自動的に提供します。グローバルセッションの場合は境界イベントを自分で記録する必要があります。トリガーフローの仕組みは ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/marketing-cloud/engage-studio/channels/mobile-inapp"},"children":["Mobile In-App Messaging"]}," を参照してください。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"アプリではなく-sql-でセッションを計算できますか","__idx":12},"children":["アプリではなく SQL でセッションを計算できますか？"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["はい。イベントにタイムスタンプとユーザーまたはデバイスの識別子がすでにあれば、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TD_SESSIONIZE_WINDOW"]}," ウィンドウ関数を使って、任意の非アクティブタイムアウトに基づきクエリ実行時にセッション ID を割り当てられます。Trino 関数リファレンスの ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/data-workbench/queries/sql-reference/td_trino_function_reference#td_sessionize_window"},"children":["TD_SESSIONIZE_WINDOW"]}," を参照してください。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"次のステップ","__idx":13},"children":["次のステップ"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/integration-hub/streaming/mobile/android"},"children":["Android SDK"]}," — ライフサイクル全体のコード例"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/integration-hub/streaming/mobile/ios"},"children":["iOS SDK"]}," — Objective-C と Swift の例"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/int/unity-sdk"},"children":["Unity SDK"]}," — グローバルセッションとインスタンスセッションの使用方法"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/integration-hub/streaming/mobile/about-mobile-tracking-and-mobile-sdks"},"children":["About Mobile Tracking and Mobile SDKs"]}," — SDK の機能とアカウント設定"]}]}]},"headings":[{"value":"モバイル SDK でのセッショントラッキング","id":"モバイル-sdk-でのセッショントラッキング","depth":1},{"value":"グローバルセッションとインスタンスセッションの違い","id":"グローバルセッションとインスタンスセッションの違い","depth":2},{"value":"セッションがテーブルに書き込む内容","id":"セッションがテーブルに書き込む内容","depth":2},{"value":"グローバルセッションタイムアウトの仕組み","id":"グローバルセッションタイムアウトの仕組み","depth":2},{"value":"session_start と session_end イベントの記録","id":"session_start-と-session_end-イベントの記録","depth":2},{"value":"グローバルセッションとインスタンスセッションの併用","id":"グローバルセッションとインスタンスセッションの併用","depth":2},{"value":"SDK ごとのセッション API","id":"sdk-ごとのセッション-api","depth":2},{"value":"よくある質問","id":"よくある質問","depth":2},{"value":"イベントに td_session_event がないのはなぜですか？","id":"イベントに-td_session_event-がないのはなぜですか","depth":3},{"value":"アプリを強制終了するとグローバルセッション ID はリセットされますか？","id":"アプリを強制終了するとグローバルセッション-id-はリセットされますか","depth":3},{"value":"グローバルセッションとインスタンスセッションは同時に使えますか？","id":"グローバルセッションとインスタンスセッションは同時に使えますか","depth":3},{"value":"Mobile In-App Messaging にはどちらのセッションタイプを使うべきですか？","id":"mobile-in-app-messaging-にはどちらのセッションタイプを使うべきですか","depth":3},{"value":"アプリではなく SQL でセッションを計算できますか？","id":"アプリではなく-sql-でセッションを計算できますか","depth":3},{"value":"次のステップ","id":"次のステップ","depth":2}],"frontmatter":{"seo":{"title":"Treasure AI モバイル SDK でのセッショントラッキング","description":"Treasure AI モバイル SDK のグローバルセッションとインスタンスセッションの違い、td_session_id と td_session_event の仕組み、セッションタイムアウト、使い分けを解説します。"}},"lastModified":"2026-08-17T04:53:10.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/ja/products/customer-data-platform/integration-hub/streaming/mobile/tracking-sessions-with-mobile-sdks","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}