来自 iOS 的 Firebase Analytics 事件未显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37416159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:09:16  来源:igfitidea点击:

Firebase Analytics events from iOS not showing up

iosfirebasefirebase-analytics

提问by Daniel Saidi

I am testing the new Google-powered Firebase, and have implemented remote notifications and crash reporting. I am, however, having massive problems with getting Analytics to work.

我正在测试由 Google 提供支持的新 Firebase,并已实施远程通知和崩溃报告。然而,我在让 Analytics 工作时遇到了很多问题。

I track events with FIRAnalytics.logEventWithName(...)and save user pproperties with FIRAnalytics.setUserPropertyString(...). However, no matter what I do, no data shows up in the Firebase Analytics Console.

我跟踪事件FIRAnalytics.logEventWithName(...)并使用FIRAnalytics.setUserPropertyString(...). 但是,无论我做什么,Firebase 分析控制台中都不会显示任何数据。

Well, I do receive some events, but those are not sent by me (like first_openand session_start). Also, this data seems to drop in after a very long time.

好吧,我确实收到了一些事件,但那些不是我发送的(比如first_opensession_start)。此外,这个数据似乎在很长一段时间后下降。

Furthermore, when I track events and save user data, I receive the following:

此外,当我跟踪事件并保存用户数据时,我会收到以下信息:

Upload task scheduled to be executed in approx. (s): 3102.294599890709

Upload task scheduled to be executed in approx. (s): 3102.294599890709

This seems really strange - Firebase waiting almost an hour before trying to send the next batch of data must be a bug, or is it configurable? When I waited that extremely long delay out, data was sent...but does not show up.

这看起来真的很奇怪 - Firebase 在尝试发送下一批数据之前等待了将近一个小时一定是一个错误,还是可以配置?当我等待那极长的延迟时,数据已发送......但没有出现。

回答by djabi

Firebase events are batched together and uploaded once every hour in order to prevent excessive battery drain on the devices. On iOS when you background the app before the 1h upload target the events will be dispatched at this time in the background.

Firebase 事件会一起批处理并每小时上传一次,以防止设备过度消耗电池电量。在 iOS 上,当您在 1 小时上传目标之前将应用程序后台运行时,此时将在后台调度事件。

You can enable debug logging for iOS (https://firebase.google.com/docs/analytics/ios/events#view_events_in_the_xcode_debug_console) to see when events are uploaded in debug console.

您可以为 iOS 启用调试日志记录 ( https://firebase.google.com/docs/analytics/ios/events#view_events_in_the_xcode_debug_console) 以查看事件何时在调试控制台中上传。

Once the events are uploaded there is delay at about 3h before the data will show up in the Firebase Analytics dashboard. Also the default day range excludes "today" so you only see events from yesterday. You can switch the date picker to include Today if you like to see the latest events.

事件上传后,数据会延迟大约 3 小时,然后才会显示在 Firebase Analytics 仪表板中。此外,默认日期范围不包括“今天”,因此您只能看到昨天的事件。如果您想查看最新事件,可以将日期选择器切换为包括今天。

The main reason to delay/batch data uploading is to save battery. Each time the network is used the device mobile network modem is put in hi power mode and stay in this mode for a while. If network is used regularly it has sever impact on the battery life. By batching the uploads together and delaying the upload the impact on the battery is significantly reduced.

延迟/批量数据上传的主要原因是为了节省电池。每次使用网络时,设备移动网络调制解调器都会进入高功率模式并在此模式下停留一段时间。如果经常使用网络,它会对电池寿命产生严重影响。通过批量上传和延迟上传,显着降低了对电池的影响。

回答by urvashi bhagat

In Swift it should be like:

在 Swift 中它应该是这样的:

FIRAnalytics.logEvent(withName: "SignUp", parameters: ["user_id": userid, "user_name": username])

To view this event in Firebase:

要在 Firebase 中查看此事件:

  1. Go to Firebase console → Analytics tab
  2. Click on DebugView tab; your Events are shown there
  1. 转到 Firebase 控制台 → 分析选项卡
  2. 单击 DebugView 选项卡;您的活动显示在那里

To view this event in Xcode:

要在 Xcode 中查看此事件:

  1. In Xcode, select Product → Scheme → EditScheme
  2. Select Run from left Menu
  3. Select Arguments tab
  4. In the Arguments Passed on Launch, add -FIRAnalyticsDebugEnabled
  1. 在 Xcode 中,选择 Product → Scheme → EditScheme
  2. 从左侧菜单中选择运行
  3. 选择参数选项卡
  4. 在启动时传递的参数中,添加 -FIRAnalyticsDebugEnabled

One dash only!!

只冲一冲!!

Note that -FIRAnalyticsDebugEnabled has only ONEdash in front of it.

请注意, -FIRAnalyticsDebugEnabled前面只有一个破折号。

回答by Zulqarnain

If you are not receiving events in console, it may be because you are not following naming convention, as I experienced if there is a space in event name it will never show up in the console like following:

如果您没有在控制台中接收事件,可能是因为您没有遵循命名约定,正如我所经历的,如果事件名称中有空格,它将永远不会出现在控制台中,如下所示:

mFirebaseAnalytics.logEvent("Add Camera", bundle);

But when you remove the space like following:

但是,当您删除空格时,如下所示:

mFirebaseAnalytics.logEvent("Add_Camera", bundle);

Now you will see events in console, after approximately 3 hours. Application will dispatch the data to console in following cases:

现在,大约 3 小时后,您将在控制台中看到事件。在以下情况下,应用程序会将数据发送到控制台:

1- Data is more than an hours old
2- App goes into the background

You can watch this tutorial for more information: Getting Started with Firebase Analytics on iOS: Events - Firecasts

您可以观看本教程以获取更多信息: iOS 上的 Firebase Analytics 入门:事件 - Firecasts

回答by crashoverride777

Another thing to check is making sure your logging entries in the Arguments Passed on Launchare correct. They should start with a -e.g

要检查的另一件事是确保您的日志记录条目Arguments Passed on Launch正确无误。他们应该以-例如开头

-FIRAnalyticsDebugEnabled

and not

并不是

FIRAnalyticsDebugEnabled

I wasted an hour the other day wondering why nothing gets logged.

前几天我浪费了一个小时想知道为什么没有记录。

回答by Kuza Grave

React-Native App (IOS/Android)

React-Native 应用程序 (IOS/Android)

I had the same problem, debugView wasn't working, and streamView glitchesa few times, the best way ive found to test my events was to logEvents with my createPageEvent()and then

我遇到了同样的问题,debugView 无法正常工作,并且 streamView 出现几次故障,我发现测试我的事件的最佳方法是使用我的 logEventscreatePageEvent()然后

the important thing is to put the app into background after logging the events, they will show up almost in realtime on firebase events or in streamView (check this articleto see when events are sent to firebase)

重要的是在记录事件后将应用程序置于后台,它们几乎会实时显示在 firebase 事件或 streamView 中(查看本文以了解何时将事件发送到 firebase)

events are only sent after 1 hour since they have been logged or immediately if you put your app in background.

事件仅在记录后 1 小时后发送,或者如果您将应用程序置于后台,则立即发送。

import firebase, { RNFirebase } from 'react-native-firebase';

export default class AnalyticsService  {

    static async initialize() {
        firebase.analytics().setAnalyticsCollectionEnabled(true);
    }

    static async createPageEvent(screen: string) {
        firebase.analytics().setCurrentScreen(screen)
        firebase.analytics().logEvent(`open_${screen}`)
    }

}

the result is this in streamView almost realtime ->

结果是在 streamView 中几乎是实时的 ->

enter image description here

在此处输入图片说明

Now you can start building funnels and stuff

现在您可以开始构建漏斗和其他东西

回答by Antoine Guénard

first_open, session_startare listed by Firebase as Automatically collected events.

first_opensession_start被 Firebase 列为自动收集的事件

I can not help you with the extreme upload task delay you encounter on your custom events.. but Firebase Analytics is less than a week old and it may be just a bug on their side.

对于您在自定义事件中遇到的极端上传任务延迟,我无法帮助您。但 Firebase Analytics 还不到一周,这可能只是他们这边的一个错误。

I found this StackOverflow questionwhich mention the same debug lines but related to Google App Measurement or old Google Mobile Analytics SDK.

我发现这个 StackOverflow 问题提到了相同的调试行,但与 Google App Measurement 或旧的 Google Mobile Analytics SDK 相关。

Also, be aware that Firebase Console won't show events in real-time (source):

另外,请注意 Firebase 控制台不会实时显示事件 ( source):

You can view aggregrated statistics about your events in the Firebase console dashboards. These dashboards update periodically throughout the day. For immediate testing, use the logcat output as described in the previous section.

您可以在 Firebase 控制台仪表板中查看有关事件的汇总统计信息。这些仪表板全天定期更新。要立即进行测试,请使用上一节中所述的 logcat 输出。

回答by delimiter

Just a simple note here: according to this little video https://www.youtube.com/watch?v=5pYdTgSkW5Eafter playing with your simulator you mustpress the home button on the Xcode, otherwise the data will not be sent to the server.

这里只是一个简单的说明:根据这个小视频https://www.youtube.com/watch?v=5pYdTgSkW5E在玩完模拟器后,您必须按下 Xcode 上的主页按钮,否则数据将不会发送到服务器。

回答by Abdullah

The most common problem most of the people are facing is the firebase is not logging events even though everything is working perfectly fine This is what i found in there docs

大多数人面临的最常见问题是即使一切正常,firebase 也没有记录事件这是我在那里的文档中发现的

If you need to deactivate Analytics collection permanently in a version of your app, set FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED to YESin your app's Info.plist file. Setting FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED to YEStakes priority over any values for FIREBASE_ANALYTICS_COLLECTION_ENABLEDin your app's Info.plistas well as any values set with setAnalyticsCollectionEnabled.

如果您需要FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED to YES在应用程序的某个版本中永久停用 Analytics 集合,请在应用程序的 Info.plist 文件中进行设置。设置FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED to YES优先FIREBASE_ANALYTICS_COLLECTION_ENABLED于应用程序中的Info.plist任何值以及使用 setAnalyticsCollectionEnabled 设置的任何值。

To re-enable collection, remove FIREBASE_ANALYTICS_COLLECTION_DEACTIVATEDfrom your Info.plist. Setting FIREBASE_ANALYTICS_COLLECTION_DEACTIVATEDto NOhas no effect and results in the same behavior as not having FIREBASE_ANALYTICS_COLLECTION_DEACTIVATEDset in your Info.plist file.

要重新启用收藏,请FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED从您的Info.plist. 设置FIREBASE_ANALYTICS_COLLECTION_DEACTIVATEDNO无效并导致与未FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED在您的Info.plist file.

So you have to remove FIREBASE_ANALYTICS_COLLECTION_DEACTIVATEDfrom your google-servicesinfo.plistfile to make analytics work

所以你必须FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED从你的google-servicesinfo.plist文件中删除才能使分析工作