Search code examples
firebasefirebase-analytics

Get user_pseudo_id from firebase client sdk?


In the Firebase Analytics, user_pseudo_id is automatically log into bigquery. But, I want to get this value in the firebase client sdk (ex: android, ios sdk) to specify user. I found on docs of firebase but couldnt found any reference about this issue of my. Have any suggest to get it?

Thanks so much!


Solution

  • I just found it, it is documented here. I also tested that it returns values that I can find in the BigQuery user_pseudo_id column.

    Example for android:

        FirebaseAnalytics.getInstance(this).getAppInstanceId().addOnCompleteListener(new OnCompleteListener<String>() {
            @Override
            public void onComplete(@NonNull Task<String> task) {
                if (task.isSuccessful()) {
                    String user_pseudo_id = task.getResult();
                }
            }
        });
    

    And for web I used the next snippet (tested on Feb 10th, 2023, I got the code from here):

    var gaUserId = document.cookie.match(/_ga=(.+?);/)[1].split('.').slice(-2).join(".")
    
    

    I am not sure about IOS but it may be this one.