Learn business growth with Google Analytics 4 Forums Google Analytics 4 Retrieving App Instance ID and Client ID from Firebase SDK for Web: Sending Google Analytics Events via API

  • Retrieving App Instance ID and Client ID from Firebase SDK for Web: Sending Google Analytics Events via API

    Posted by Jack on 5 February 2023 at 10:01 am

    “Hey fellow coders, I’m stuck on something. I’m trying to snag the app_instance_id or client_id from the Firebase SDK for a web client. Just to clarify, I’m not using gtag.js. Here’s a link that I’ve been referencing for help: (https://developers.google.com/analytics/devguides/collection/protocol/ga4/sending-events?client_type=firebase).

    I attempted to use firebase/installations with this bit of code:

    const installationId = await installations.getId(

    But when I tried to validate a request with the given installationId through the ga4 API, I got this error message:

    description: “Measurement app_instance_id is expected to be a 32 digit hexadecimal number but was [22] digits.”
    fieldPath: “app_instance_id”
    validationCode: “VALUE_INVALID”

    How can I fix this?”

    Lucy replied 10 months, 4 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Sofia

    23 June 2023 at 9:45 am

    Sure, so essentially the error you’re seeing is because the ID you’re getting from Firebase isn’t in the right format. The ID should be a 32-digit hex number, but the one you have is only 22 digits.

    So, what you can do is firstly, in Firebase, allow streaming into BigQuery tables. Find the app_instance_id or client_id there – they’re under labels that say ‘user_pseudo_id’ and ‘user_id’ respectively.

    If that doesn’t work, you could use a proxy, like Charles or mitm, to get the exact logs from your app and find the ids there.

    A third option is to use Android’s ‘adb’ tool. This lets you dig into logs while your device is connected to your PC. You can search the logs there to find the correct ids.

    Basically, there are multiple ways to get these IDs – you just need to figure out which one works best for you.

  • Lucy

    24 June 2023 at 4:28 am

    The issue you’re encountering has to do with the format of the ‘app_instance_id’ you’re attempting to retrieve from Firebase. This ID needs to be a 32-digit hexadecimal number, but the ID you’re receiving is a 22-digit number. Firebase’s ‘installations’ service provides an ID, but it seems that this ID isn’t suitable for use as an ‘app_instance_id’ in the ga4 API. You need to find a different method to obtain the ‘app_instance_id’. The Firebase SDK documentation or Google Analytics documentation may have more information on how you can correctly obtain this ID.

Log in to reply.