如何使用userDeletionRequests:upsert从Firebase删除用户分析数据? [英] How do I delete user analytics data from Firebase using userDeletionRequests:upsert?

查看:75
本文介绍了如何使用userDeletionRequests:upsert从Firebase删除用户分析数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Android应用通过Firebase的Google Analytics(分析)收集数据.出于隐私方面的考虑,用户必须选择从Firebase服务器上删除其数据.

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.

该应用通过将其Firebase APP_INSTANCE_ID转发到我自己的服务器来请求删除.该服务器已预先通过我的个人Google帐户(通过oauth2)使用凭据准备好,用于管理Firebase项目.服务器使用www.googleapis.com进行身份验证,然后使用提供的APP_INSTANCE_ID调用upsert.

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.

通用Google Analytics(分析)API 文档所述.适合执行此任务.

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

在遇到一些最初的麻烦之后(b/c我没有正确的身份验证范围,并且没有正确启用Analytics API),googleapis.com现在为每个upsert请求返回HTTP 200. (顺便说一句,即使您提供了伪造的APP_INSTANCE_ID,它也会返回200.)

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.)

这是来自upsert的示例响应,没有显示任何错误:

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' }

我知道firebaseProjectId是正确的,因为如果更改它,则会出现错误.我已经证实APP_INSTANCE_ID是正确的,并且一直稳定到resetAnalyticsData()将其重置之前.

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().

要测试删除操作,我使用以下过程(Nexus 5X模拟器,未配置Google Play,未配置Google帐户,但没有任何区别)向Firebase填充了几个自定义事件:

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. 安装应用
  2. 触发一些自定义事件(FirebaseAnalytics.logEvent)
  3. 观察这些事件出现在Firebase控制台上
  4. (大约一分钟后:)进行upsert调用,遵守HTTP 200,并记下"deletionRequestTime"
  5. 立即调用FirebaseAnalytics.resetAnalyticsData(清除设备上缓存的所有事件数据)
  6. 卸载应用
  7. 冲洗&重复7或8次
  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

但是,即使在24小时后,事件表中仍然存在100%的Firebase事件.由于出现了更新问题,Firebase服务器上没有发生明显的状态变化.

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.

那么,我在做什么错?如何从Google Analytics for Firebase成功删除用户数据?

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

编辑

这是我用来发出请求的代码(来自node.js):

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)
}

这是相同请求的控制台输出(相同的userId以及所有内容):

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' }

推荐答案

Firebase支持刚刚回到我身边,我引用:

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

Upsert方法删除我们记录的任何个人用户数据,但不会重新计算汇总指标.这意味着您可能不会在Analytics(分析)控制台的事件"标签中看到任何更改.

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.

这当然提出了一个问题,即人们如何确定API确实在工作……但是HTTP 200足够了.

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

这篇关于如何使用userDeletionRequests:upsert从Firebase删除用户分析数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆