インスタンス ID は、アプリの個別のインストールを識別します。それぞれのインスタンス ID は特定のアプリやデバイスに固有であるため、Firebase サービスが特定のアプリ インスタンスを参照する手段になります。たとえば、Cloud Messaging はインスタンス ID を使用して、メッセージの送信先であるデバイスを判別します。
複数の Firebase サービスで、機能を実現するためにインスタンス ID を使用しています。
Analytics
Crashlytics
Cloud Messaging
Remote Config
インスタンス ID に関連付けられているアプリデータを管理する
インスタンス ID を使用してインストールを識別するサービスでは、データとデバイスを関連付けるためのキーとしてもインスタンス ID を使用します。たとえば、Crashlytics はインスタンス ID を使用してデバイスで発生するクラッシュを記録し、Remote Config はインスタンス ID を使用して構成を取得し、Analytics はインスタンス ID を使用して特定のユーザーを追跡します。
インスタンス ID に関連付けられているデータは、一般的には個人を識別するデータではありませんが、ユーザーがデータを管理するオプションとして役に立ちます。そのために、Firebase にはインスタンス ID に関連するデータ収集を管理する 2 つの手段が用意されています。
インスタンス ID の削除。サーバー側またはクライアント側の API 呼び出しでインスタンス ID を削除できます。インスタンス ID を削除すると、ID 自体とそれに関連するすべてのデータが削除されます。
ID を生成するサービスの無効化。インスタンス ID を使用するほとんどの Firebase サービスは、開始時にデバイスにインスタンス ID がない場合、自動的に新しい ID を生成します。アプリで不要なインスタンス ID を作成しないようにするには、これらのサービスの自動初期化を無効にします。
インスタンス ID を削除する
インスタンス ID を削除すると、上記の Firebase サービスでは、その ID に関連付けられているデータも削除されます。そのため、ID の削除はユーザーデータの消去に役立つツールになります。ただし、インスタンス ID に依存する複数のサービスを使用している場合は、ある ID を削除するとそれらすべてのサービスからデータが消去されるため、この点に注意する必要があります。
インスタンス ID サービスは、アプリでインスタンス ID を生成するサービスをすべて無効にしない限り、数日以内に新しい ID を作成します。Firebase では、新しく作成された ID を新しいアプリ インスタンスとみなし、以前の ID には関連付けません。
クライアント API 呼び出しで ID を削除する
Firebase サービスによって生成された ID を削除するには、Firebase インスタンス ID API から適切なメソッドを呼び出します。
SDK を追加したら、選択した言語でインスタンス ID を削除する関数を呼び出すことで、ID を削除します。
Node.js
// An Instance ID sent from a client service SDKconstidToDelete='INSTANCE_ID';admin.instanceId().deleteInstanceId(idToDelete);
Java
// An Instance ID sent from a client service SDKStringidToDelete="INSTANCE_ID";FirebaseInstanceId.getInstance().deleteInstanceIdAsync(idToDelete).get();
Python
fromfirebase_adminimportinstance_id# An Instance ID sent from a client service SDKid_to_delete='INSTANCE_ID'instance_id.delete_instance_id(id_to_delete)
サーバー API 呼び出しによりインスタンス ID を削除すると、Firebase サービスは関連するデータを削除し、その ID に関する新しいデータの受け取りを停止し、数日以内に ID が削除されたことをクライアント アプリに通知します。Firebase がクライアント アプリに通知するまで、アプリのサービスの一部で機能が低下する場合があります。
現在のインスタンス ID を削除し、すぐに新規の独立した ID で Firebase サービスを使用する必要がある場合は、上記のクライアント API のいずれかを使用して削除を処理します。
インスタンス ID の生成を無効にする
インスタンス ID を使用するサービスでは、現時点でインスタンス ID が存在しないアプリでそのサービスが初期化された時点で、自動的に新しい ID が生成されます。通常は、アプリの起動時にも、これらのサービスで自動的に初期化が行われます。インスタンス ID の生成を無効にするには、それらを使用するサービスの自動初期化を無効にする必要があります。
一般的なアプローチでは、データ収集の選択に関するオプションをユーザーに提示します。つまり、インスタンス ID を使用するサービスの自動初期化を無効にし、ダイアログを実装してデータ収集の同意を確認するプロンプトをユーザーに表示し、同意が得られたら手動でサービスを再度有効にします。
インスタンス ID を使用するサービスの自動初期化を無効にして、代わりにそれらのサービスを手動で初期化する方法については、以下のガイドをご覧ください。
[null,null,["最終更新日 2025-04-12 UTC。"],[],[],null,["# Manage Instance ID data\n\n| **Warning:** **The Instance ID API is deprecated.** If you need to access unique app installation identifiers, use the [Firebase installations](/docs/projects/manage-installations) API. See also [Firebase installations and Instance ID](/docs/projects/manage-installations#fid-iid). The [server-side topic management API](https://developers.google.com/instance-id/reference/server#create_relationship_maps_for_app_instances) is still available.\n\nInstance IDs identify individual installations of your app. Since each Instance\nID is unique to a particular app and device, they give Firebase services a way\nto refer to specific app instances. For example, Cloud Messaging uses\nInstance IDs to determine which devices to send messages to.\n\nSeveral Firebase services use Instance IDs to power their features:\n\n- Analytics\n- Crashlytics\n- Cloud Messaging\n- Remote Config\n\nManage app data associated with Instance IDs\n--------------------------------------------\n\nServices that use Instance IDs to identify installations also use them as a key to\nassociate relevant data with that device. For example, Crashlytics uses\nInstance IDs to record crashes that happen on the device, Remote Config uses\nthem to fetch configurations, and Analytics uses Instance IDs to track\nparticular audiences.\n\nData associated with Instance IDs is generally *not* personally-identifying,\nbut it can still be helpful to give users an option to manage it. To that\nend, Firebase offers two ways to manage Instance-ID-related data collection:\n\n- **Delete Instance IDs.** You can delete an Instance ID with a server- or client-side API call. Deleting an Instance ID deletes the ID itself and all data associated with it.\n- **Disable services that generate IDs.** Most Firebase services that use Instance IDs automatically generate a new ID if there isn't one on the device when they start up. To ensure your app doesn't create unwanted Instance IDs, disable auto-initialization for those services.\n\nDelete an Instance ID\n---------------------\n\nDeleting an Instance ID also deletes data associated with that ID in any of the\nFirebase services listed above. That makes ID deletion a helpful tool in\nclearing user data, but also comes with a caveat: if you're using multiple\nservices that rely on Instance IDs, deleting an ID clears data from *all* of\nthem.\n\nThe Instance ID service creates a new ID within a few days, unless you\ndisable all Instance-ID-generating services in your app. Firebase considers the\nnewly-created ID to be a brand new app instance, and doesn't associate it with\nthe previous ID in any way.\n| **Note:** Google Analytics uses its own form of Instance ID to keep track of analytics data. Deleting a regular Instance ID does *not* delete Analytics data. Learn how to [delete Analytics data associated with end users](https://support.google.com/firebase/answer/9019185#delete-on-mobile-device).\n\n### Delete an ID with a client API call\n\nTo delete IDs generated by Firebase services, call the appropriate method from\nthe Firebase Instance ID API: \n\n### Swift\n\n InstanceID.instanceID().deleteID { error in\n if let error = error {\n print(\"Error deleting instance ID: \\(error)\")\n }\n }\n\n### Objective-C\n\n [FIRInstanceID instanceID] deleteIDWithHandler:^(NSError *error) {\n if error != nil {\n NSLog(@\"Error deleting instance ID: %@\", error);\n }\n }];\n\n### Android\n\n FirebaseInstanceId.deleteInstanceId();\n\n### Delete an ID with a server API call\n\nTo delete an Instance ID with server API calls, [add the Firebase Admin SDK to your server](//firebase.google.com/docs/admin/setup),\nif you haven't already.\n\nOnce it's added, delete IDs through a call to the Instance ID deletion function\nin your language of choice: \n\n### Node.js\n\n // An Instance ID sent from a client service SDK\n const idToDelete = 'INSTANCE_ID';\n\n admin.instanceId().deleteInstanceId(idToDelete);\n\n### Java\n\n // An Instance ID sent from a client service SDK\n String idToDelete = \"INSTANCE_ID\";\n\n FirebaseInstanceId.getInstance().deleteInstanceIdAsync(idToDelete).get();\n\n### Python\n\n from firebase_admin import instance_id\n\n # An Instance ID sent from a client service SDK\n id_to_delete = 'INSTANCE_ID'\n\n instance_id.delete_instance_id(id_to_delete)\n\n### Go\n\n client, err := app.InstanceId(ctx)\n if err != nil {\n log.Fatalln(\"error initializing client\", err)\n }\n\n iidToDelete := \"INSTANCE_ID\"\n if err := client.DeleteInstanceId(ctx, iidToDelete); err != nil {\n log.Fatalln(\"error deleting iid\", err)\n }\n\nWhen you delete an Instance ID with a server API call, Firebase services delete\nthe associated data, stop accepting new data for that ID, and, within a few days,\nnotify the client app that the ID was deleted. Until Firebase notifies the client\napp, some of the app's services might experience reduced functionality.\n\nIf you want to delete the current Instance ID and immediately use Firebase\nservices with a new, independent ID, use one of the Client APIs above to\nhandle the deletion.\n\nDisable Instance ID generation\n------------------------------\n\nServices that use Instance IDs automatically generate a new ID when they're\ninitialized in an app that doesn't currently have one. Typically, those services\nalso automatically initialize when your app launches. To disable Instance\nID generation, you have to disable auto-initialization for services that use\nthem.\n\nA common approach is to give users an option to\nopt-in to data collection: disable auto-initialization for\nthe services that use Instance IDs, implement a dialog that prompts\nusers for their consent to data collection, and re-enable the services manually\nonce you have consent.\n\nRead the guides below to find out how to disable auto-initialization for\nInstance-ID-using services and instead manually initialize them:\n\n- Cloud Messaging: [Prevent Auto-initialization (Android)](//firebase.google.com/docs/cloud-messaging/android/client#prevent-auto-init) or [Prevent Auto-initialization (iOS+)](//firebase.google.com/docs/cloud-messaging/ios/client#prevent_auto_initialization)\n- Crash Reporting: [Enable Opt-in Reporting](//firebase.google.com/docs/crash/disable-sdk)\n- Analytics: [Configure Analytics Data Collection](/docs/analytics/configure-data-collection)\n\n| **Note:** Firebase Remote Config also generates Instance IDs, but isn't automatically initialized on app start. To delay ID generation in Remote Config, don't use the service until you're ready to generate an ID."]]