firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.65k stars 1.48k forks source link

Firebase Analytics triggers a `session_start` event when app is launched in the background by the iOS from a push notification #12219

Open nzhuk opened 10 months ago

nzhuk commented 10 months ago

Description

We have multiple iOS apps in production which are using Firebase Analytics and our own internal analytics system in parallel to log their sessions. Our internal analytics system is setup to log all app foreground launches & moves from background to the foreground. When comparing those numbers to the session counts produced by Firebase Analytics we noticed suspiciously high session counts on Firebase Analytics side and decided to investigate further.

When the app is launched in iOS simulator and the -FIRDebugEnabled launch argument is included, the session_start event is emitted by Firebase SDK when the simulator receives a push notification payload with content-available: 1 flag, causing the OS to launch the app to the background. This only happens when more than 30 minutes has passed since the last session start event.

Based on Firebase documentation this should not be happening:

a session initiates when a user either opens your app in the foreground or views a page or screen and no session is currently active (e.g. their previous session has timed out).

In the end, we were able to reduce our GA4 session counts considerably by removing the content-available: 1 field from our push payloads.

A potentially related issue which has been already closed: https://github.com/firebase/firebase-ios-sdk/issues/6161

Reproducing the issue

Firebase SDK Version

10.18.0

Xcode Version

15.1

Installation Method

Swift Package Manager

Firebase Product(s)

Analytics

Targeted Platforms

iOS

google-oss-bot commented 10 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

jacao commented 9 months ago

@nzhuk I'm seeing this exact issue (raised an issue with Firebase also https://github.com/firebase/firebase-ios-sdk/issues/12347)! I have been trying to resolve this for a while without having to alter the silent pushes being sent to the iOS app (because these are being sent by a third party for uninstall tracking). I haven't had any joy yet. I think this is a bug in the Firebase Analytics SDK.

javierservatepoq commented 5 months ago

We are experiencing the same. Any luck with it?

jacao commented 5 months ago

@javierservatepoq unfortunately not.

I don't think any engineers at Firebase have looked into it, and as the Analytics library is closed source it's not possible to debug our side.

I'm surprised that Firebase haven't noticed and addressed this before its quite a big issue 😅

Are all of your sessions skewed?

jacao commented 5 months ago

@peterfriese apologies for tagging you but is there any chance you could help get this prioritised.

As Firebase is now the source of truth for GA4 (can no longer use Segment -> GA3) this is quite a big issue 😅

Deadvi5 commented 3 months ago

This is happening also to us, we have false numbers. Any updates on this?

jacao commented 3 months ago

This is happening also to us, we have false numbers. Any updates on this?

Currently in communication with Firebase/Google on this. We are on a paid support plan so hoping to get some more traction on a fix.

DeadSatsuma commented 1 month ago

I'm client that works closely with Google, they've replied with below:

We log the session start event during initialization,by that time UIApplicationDidBecomeActiveNotification] has not been received yet. That is, we don't know if it's a foreground or background launch.

This issue was already reported and our engineering teams are looking into it. However, we don't have any ETA for the fix right now and will keep you posted when I hear more on this.