/ facebook instant game

#Facebook Instant Game FB小游戏无法使用谷歌分析gtag的解决方法

问题背景

Facebook将于2021年6月30日正式关闭Facebook分析服务,为了更好地进行数据分析,Facebook小游戏需要接入一个第三方分析服务。

在测试谷歌分析服务的时候发现,Facebook小游戏似乎无法发送数据。

这是怎么回事呢?

解决方法

研究发现,这是Facebook的一个限制

https://github.com/firebase/firebase-js-sdk/issues/4046

I think I found a solution. The problem is with this year Chrome cross-site cookie handling.
Due to hosting app in an facebook iframe - cookie_flags: 'max-age=7200;secure;samesite=none' is required for request to pass thru. I'm able to override gtag initialization and push this setting after firebase initial initialization but I wonder if there is a way of passing it in firebase intial config instead of recreating gtag -
gtag('config', 'ID', { cookie_flags: 'max-age=7200;secure;samesite=none' });

在初始化gtag时,需要加入以下参数才可以

gtag('config', 'ID', { cookie_flags: 'max-age=7200;secure;samesite=none' });

这个临时解决方法带来的问题是,一旦Facebook改动了cookie的参数需求,有可能又失效了。