Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete user analytics data from Firebase using userDeletionRequests:upsert?

Problem Description

My Android app collects data via Google Analytics for Firebase. For privacy reasons, users must be able to wipe their data off the Firebase servers, should they choose to do so.

The app requests a deletion by forwarding its Firebase APP_INSTANCE_ID to my own server. This server has been prepared in advance with credentials, from my personal Google account (via oauth2), for managing the Firebase project. The server authenticates with www.googleapis.com, and, using the supplied APP_INSTANCE_ID, invokes the upsert.

As noted by the documentation, the generic Google Analytics API is appropriate for this task.

After some initial trouble (b/c I didn't have the correct auth scope, and the Analytics API wasn't properly enabled), googleapis.com now returns HTTP 200 for each upsert request. (As an aside, even if you supply a bogus APP_INSTANCE_ID, it returns 200.)

Here is a sample response from the upsert, which shows nothing amiss:

{ kind: 'analytics#userDeletionRequest',
  id: 
   { type: 'APP_INSTANCE_ID',
     userId: (REDACTED 32-char hexidecimal string) },
  firebaseProjectId: (REDACTED),
  deletionRequestTime: '2018-08-28T12:46:30.874Z' }

I know the firebaseProjectId is correct, because if I alter it, I get an error. I have verified that the APP_INSTANCE_ID is correct, and stable up until the moment it is reset with resetAnalyticsData().

Test Procedure

To test the deletions, I populated Firebase with several custom events, using the procedure below (Nexus 5X emulator, no Google Play, no Google accounts configured, but that shouldn't make any difference):

  1. Install the app
  2. Fire off some custom events (FirebaseAnalytics.logEvent)
  3. Observe those events appear on the Firebase console
  4. (About a minute later:) Make the upsert call, observe HTTP 200, and note the "deletionRequestTime"
  5. Immediately call FirebaseAnalytics.resetAnalyticsData (to clear any event data cached on the device)
  6. Uninstall the app
  7. Rinse & repeat 7 or 8 times

However, even 24 hours later, 100% of the Firebase events are still present in the events table. No discernable state change has taken place on the Firebase server as a result of the upserts.

Question

So, what am I doing wrong? how do I successfully delete user data from Google Analytics for Firebase?

EDIT

Here's the code I'm using to make a request (from node.js):

const request = require( 'request' ); 

... 

_deletePersonalData( data ) 
{ 
    return new Promise( (resolve, reject) => { 
        request.post({ 
            url: 'https://www.googleapis.com/analytics/v3/userDeletion/userDeletionRequests:upsert', 
            body: { 
                kind: 'analytics#userDeletionRequest', 
                id: { 
                    type: 'APP_INSTANCE_ID', 
                    userId: data.firebaseAppInstanceId 
                }, 
                firebaseProjectId: (REDACTED) 
            }, 
            headers: { 
                Authorization: 'Bearer ' + iap.getCurAccessToken() 
            }, 
            json: true 
        }, (err, res, body) => { 
            console.log( 'user-deletion POST complete' ); 
            console.log( 'Error ' + err ); 
            console.log( 'Body ', body ); 

            if( err ) 
            { 
                reject( err ); 
                return; 
            } 

            if( body.error ) 
            { 
                reject( new Error( 'The Google service returned an error: ' + body.error.message + ' (' + body.error.code + ')' ) ); 
                return; 
            } 

            resolve({ deletionRequestTime: body.deletionRequestTime }); 
        }); 
    });
} 

Here's a sample request body:

{
  kind: 'analytics#userDeletionRequest',
  id: {
    type: 'APP_INSTANCE_ID',
    userId: (REDACTED 32-char hexidecimal string)
  },
  firebaseProjectId: (REDACTED)
}

And here's the console output for that same request (same userId and everything):

user-deletion POST complete
Error: null
Body: { kind: 'analytics#userDeletionRequest',
  id: 
  { type: 'APP_INSTANCE_ID',
    userId: (REDACTED 32-char hexidecimal string) },
  firebaseProjectId: (REDACTED),
 deletionRequestTime: '2018-08-29T17:32:06.949Z' }
like image 582
greeble31 Avatar asked Aug 28 '18 19:08

greeble31


People also ask

Can you delete data from Analytics?

If you need to delete data from the Analytics servers for any reason, then you can use a data-deletion request to issue a request for its removal. You can have a maximum of 12 active (in grace period / pending deletion) requests per property at any one time.

Do you provide a way for users to request that their data is deleted?

How do I ask for my data to be deleted? You should contact the organisation and let them know what personal data you want them to erase. You don't have to ask a specific person – you can contact any part of the organisation with your request. You can make your request verbally or in writing.


1 Answers

Firebase support just got back to me, and I quote:

Upsert method deletes any individual user data we have logged, but aggregate metrics are not recomputed. This means that you might not see any changes in the events tab in your Analytics console.

So, basically my mistake was expecting the events to disappear from the console.

This, of course, raises the question of how one determines that the API is actually working... but maybe the HTTP 200 is enough.

like image 172
greeble31 Avatar answered Oct 17 '22 10:10

greeble31