Firebase analytics for iOS Today extension(widget extension) - ios

I tried to add firebase analytics in today extension.
So I input the configuration code
if (![FIRApp defaultApp]) {
[FIRApp configure];
}
in today extension's viewDidLoad.
And in the Xcode's Product > scheme > Edit scheme > Run > Arguments tab, I added the '-FIRAnalyticsDebugEnabled' as I want to show the logged event in firebase console's DebugView page. But, Any events didn't printed in the page.
The log added into App (not today extension) is checked in the DebugView in real time. What should I do to show today extension's log in firebase DebugView in real time?

From my experience, you can't use the app argument on the extension. I could add break point in the extension but I could see that the flag didn't have any effect on the extension. Therefore, extensions cannot send data in debug mode for now.

You can do it from code by calling setLoggerLevel method on FirebaseConfiguration singleton and set the logger level.
please see Firebase analytics documentation :
https://firebase.google.com/docs/reference/ios/firebasecore/api/reference/Classes
Enable debug mode by passing the -FIRDebugEnabled argument to the
application. You can add this argument in the application’s Xcode
scheme. When debug mode is enabled via -FIRDebugEnabled, further
executions of the application will also be in debug mode. In order to
return to default mode, you must explicitly disable the debug mode
with the application argument -FIRDebugDisabled.
It is also possible to change the default logging level in code by
calling setLoggerLevel: on the FIRConfiguration interface.

Related

Will Firebase Analytics work from the simulator in Xcode?

In an IOS app I have
and I ensured the plist "defeat" entry is not there, and then I have analytics events like
Analytics.logEvent("touchedButton", parameters: nil)
In fact, if I run the app just in the Xcode simulator .. are these events reported to Firebase Analytics and show up?
Or perhaps if you build to an iPhone?
Or does it only work if it's an actual build which has gone through TestFlight?
Surprisingly I couldn't find this info anywhere.
Is it precisely here that such custom events will show:
Yes, both simulator or device will work.
If you haven't already read, read their getting started tutorials, it covers most of it https://firebase.google.com/docs/analytics/ios/start
A couple of points
Make sure when you configure your Firestore settings , you enable analytics
AnalyticsConfiguration.shared().setAnalyticsCollectionEnabled(true)
I do all of this initial settings in AppDelegate
something like
//init Firebase
FirebaseConfiguration.shared.setLoggerLevel(.min)
FirebaseApp.configure()
Fabric.with([Crashlytics.self])
let _ = FirebaseConfig.sharedInstance // This is a custom singelton class where I enable the analytics
In Scheme settings for your target you need to add -FIRAnalyticsDebugEnabled
As you can see I have also a disable option there, sometimes analytics goes crazy and spams the console , so I'd like to disable it with . -FIRDebugDisabled
Analytics clusters your events unless you specify it is a custom event.
For example I use following to tag the viewcontroller names
func logEvent(eventTitle:String , eventContent:String)
{
Analytics.logEvent(AnalyticsEventSelectContent, parameters: [
AnalyticsParameterItemID: "AppName-\(eventTitle)" as NSObject,
AnalyticsParameterItemName: eventTitle as NSObject,
AnalyticsParameterContentType: eventContent as NSObject
])
}
But int the firestore these are clustered under select_content section because I used AnalyticsEventSelectContent key when creating the log.
Under main events screen , select_content my view controlers logged with above function
4.There is a specific DebugView in the FirestoreConsole that works with a device, it updates every 60 seconds as long as settings for -FIRAnalyticsDebugEnabled is true in the scheme.
There is a significant delay in the Event Section of Firestore console, I don't know why this happens, but sometimes there is a delay up to 15 - 30 mins. Havent researched that issue yet, it really doesnt bother me.
Just follow https://firebase.google.com/docs/analytics/ios/start
To enable Analytics Debug mode on your development device, specify the following command line argument in Xcode :
-FIRDebugEnabled
It works perfectly for Simulator and device.
Note: For react-native debugging, launch app from xcode with the selected scheme and not with 'yarn ios', then it works perfectly for Simulator also

Completely disable Firebase/Analytics to stop console spam on app startup

I've installed Google/SignIn cocoapod into my application (which I need to support GoogleDrive), but it depends on Google/Core which depends on FirebaseAnalytics. I don't want or need FirebaseAnalytics.
FirebaseAnalytics spams the developer console with 8 lines of output when our app starts:
2017-06-07 18:07:19.612994+0100 son[2909:877661] [Firebase/Analytics][I-ACS005000] The AdSupport Framework is not currently linked. Some features will not function properly. Learn more at http://gooX.gl/9vSsPb
2017-06-07 18:07:19.613 son[2909] <Warning> [Firebase/Analytics][I-ACS005000] The AdSupport Framework is not currently linked. Some features will not function properly. Learn more at http://gooX.gl/9vSsPb
2017-06-07 18:07:19.613896+0100 son[2909:877661] [Firebase/Analytics][I-ACS023007] Firebase Analytics v.3900000 started
2017-06-07 18:07:19.614 son[2909] <Notice> [Firebase/Analytics][I-ACS023007] Firebase Analytics v.3900000 started
2017-06-07 18:07:19.614525+0100 son[2909:877661] [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://gooX.gl/RfcP7r)
2017-06-07 18:07:19.614 son[2909] <Notice> [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://gooX.gl/RfcP7r)
2017-06-07 18:07:19.622560+0100 son[2909:877662] [Firebase/Analytics][I-ACS023013] Firebase Analytics disabled
2017-06-07 18:07:19.623 son[2909] <Notice> [Firebase/Analytics][I-ACS023013] Firebase Analytics disabled
(I had to add X to the URLs in the above output to get past stackoverflow's URL shortener blocker.)
I tried setting FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED to YES in my Info.plist, that removed 2 lines, but added another 2 lines to tell me that Analytics is disabled (FFS!).
This spammed output makes it difficult for our developers to see any console output that is actually important. How can I disable it?
(Failing that, a suggestion on how to get it outputting each line only once would be really welcome.)
You can find this buried in the output:
<Notice> [Firebase/Analytics][I-ACS023008] To enable debug logging
set the following application argument: -FIRAnalyticsDebugEnabled
Disabling is the opposite - set the argument: -noFIRAnalyticsDebugEnabled:
Additionally, you can control the default Firebase logging level with the setLoggerLevel method in FIRConfiguration. For example to disable all Firebase logging:
[[FIRConfiguration sharedInstance] setLoggerLevel:FIRLoggerLevelMin];
[FIRApp configure];
or in Swift:
FirebaseConfiguration.shared.setLoggerLevel(FirebaseLoggerLevel.min)
FirebaseApp.configure()
More details in the FIRLogger implementation here
To the best of my knowledge, these two lines:
[[FIRConfiguration sharedInstance] setLoggerLevel:FIRLoggerLevelMin];
[[FIRAnalyticsConfiguration sharedInstance] setAnalyticsCollectionEnabled:NO];
placed very early in the app delegate's didFinishLaunchingWithOptions: will completely disable FireBase analytics, including stopping all the console output.
I've also since discovered that the Google/SignIn cocoapod is deprecated - the recommended one to use is GoogleSignIn (ie. no '/'). If you use GoogleSignIn, then this doesn't have a dependency on Firebase Analytics, so the original problem goes away. Now I have Google Drive support in my app and don't have Firebase Analytics!
Swift 4.0:
FirebaseConfiguration.shared.setLoggerLevel(.min)
FirebaseConfiguration.shared.analyticsConfiguration.setAnalyticsCollectionEnabled(false)
In Xcode 11.x (Swift 5 era):
This one can be a bit hairy, you may have to restart XCode even after applying the proper solution below.
Open Scheme: press COMMAND + SHIFT + < (the comma) to open up the Scheme which will drop down from the top of XCode as another window.
On the left select "Run Debug"
select the "Arguments" tab at the top of the window
enter the code below into the "Arguments Passed On Launch" section by pressing the little "+" button on the lower left.
(copy paste this)
-FIRDebugDisabled
This will disable Debug mode for Firebase for both Firestore, Firebase, and Fire Analytics.
If you haven't loaded Fire Analytics, then you can simply enter the following code into your AppDelegate.swift file:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
let db = Firestore.firestore()
// This below is the line of code to enter, but it won't stop Firebase Analytics from printing its mess in the consoleLog, but this works if you're not using FireBase Analytics.
FirebaseConfiguration.shared.setLoggerLevel(.min)
return true
}
NOTE/ADDITIONAL: You can open up your Google info.plist and write "NO" for enabling Firebase. To get Google's info.plist, just click on info.plist file, then at the top click on info.plist in the Navigation window, and it will open up a selector with Google's info.plist as a selectable item. See Figure 2.
Figure 1: What the drop-down looks like.
Figure 2: Google's info.plist

Firebase iOS Debug Console not logging anything

I have setup firebase in both the console and in the app. Everything configures correctly, and events appear to be logging in the app.
Output to console:
<FIRAnalytics/DEBUG> Logging event: origin, name, params: app,
log_something, {
"_o" = app;
"full_text" = khbsdpibdsjl;
name = lwkjbgskljsavdkjl;
}
I have the debug flag enabled: -FIRDebugEnabled.
Yet in the debugging events console there is NOTHING. I see no devices available, no events being logged, absolutely 0 indication of anything connected. I must be missing something?
edit: I have been following this for setting up Debugging Events. https://firebase.google.com/docs/analytics/debugview#enabling_debug_mode
I am seeing events in the StreamView, but nothing in the debug view even though I have debug mode enabled.
Try this , This is work for me ,
Follow below steps ,
1.In Xcode, select Product → Scheme → EditScheme.
2.Select Run from left Menu and Select Arguments tab
In the Arguments Passed on + option
add -FIRDebugEnabled
For detail debug view follow steps DebugView track Firebase doc
To send an event in Xcode project follow code below,
Objective C
[FIRAnalytics logEventWithName:#"share_image"
parameters:#{#"name": name, #"full_text": text}];
Swift
Analytics.logEvent("share_image", parameters: ["name": name, "full_text": text])
For events log follow detail steps Log events in Application Firebase doc
Hope this will help someone.
Make sure to remove the OS_ACTIVITY_MODE:disable from the Environment Variables in your project scheme if you added it at some point.
Make sure to add ONE DASH before -FIRDebugEnabled
I wasted a whole day making silly mistake having missed that DASH
Hope that doesn't happen to others!
Now it doesn't matter much but still for the people who are getting errors on this issue. Debug mode of firebase analytics does not work sometimes due to issue in GoogleServices-Info.plist file
Simply makes these 2 changes.
Set IS_ANALYTICS_ENABLED to YES
Set FIREBASE_ANALYTICS_COLLECTION_DEACTIVATE to NO
I also have the same problems.
1 check your Cocopods' s Firebase version.
use pod update Firebase
List item
make sure that is the latest
2 open debug mode
In the Arguments Passed On Launch part
add - FIRDebugEnabled.
I made it possible by writing the following:
func application(_ application: UIApplication, didFinishLaunchingWithOptions, ...) {
// some other initialization
FirebaseApp.configure()
Firebase.Analytics.setAnalyticsCollectionEnabled(true)
}
Alternatively you can do that inside your AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
var newArguments = ProcessInfo.processInfo.arguments
newArguments.append("-FIRDebugEnabled")
ProcessInfo.processInfo.setValue(newArguments, forKey: "arguments")
}
---EXTRA---
And just some thoughts:
Regarding
Firebase.Analytics.setAnalyticsCollectionEnabled(true)
If we inspect the method:
So it's kind of POINTLESS...
Check if you have an ad blocker enabled while visiting the Firebase website.
I had uBlock origin enabled and it would block every page (Dashboard, Events, StreamView, DebugView...) and they'd all be blank.
Everything worked as expected as soon as I whitelisted it.
I recently had an issue where the Xcode console said everything was fine, and all was being logged and sent, and I had the "-FIRDebugEnabled" and I tried all other suggestions in this thread, but nothing worked.
Nothing was being sent to Firebase's DebugView.
Looking through my git-history, I determined the issue occurred due to a pod update, and the solution to my issue was another pod update.
I don't know which pod had failed, but I suspect either Moya, Alamofire or FirebaseAnalytics... after this, I'm strongly considering locking my pod-versions.
I had the same configuration as jaywant-khedkar, but no events or devices were showing up in the Firebase Debug View.
Found out that my pi-hole on my network was eating all the events.
So if if you have any kind of ad blocker on your network, disable it and try again.
Happy debugging!
If you've done everything that the Firebase documentation states, then it could be that you have the wrong "Debug Device" selected in Firebase Analytics' "Debug View". After changing the debug device in the top left, all my analytics events from before were displayed! So it wasn't that my events weren't being sent to Firebase, I was just seeing the wrong view. Image attached.
Had this issue a few days ago, after trying every solution I found on the internet and none of them working, these are the steps I used to finally enabled DebugView to find my device:
Close the app on the device you’re working on
Go to the Firebase console and sign out of your account
Sign back in again, go to the console and select the project you’re working on.
Again, not sure if this made a difference however do NOT click on DebugView item under the “Project shortcuts” list. Instead, click on the “Analytics” drop-down and select DebugView from there.
It may be possible that this process updates the data stream used in the DebugView page - after following these steps I noticed events which had been missed initially were now showing up - almost as if the event was sent/received properly however the DebugView wasn’t showing the correct data stream.
Bonus tip:
Had issues with this again today, and after signing out/in to Firebase the DebugView still wasn't finding my device. What fixed it was, on my device, move the app into the background i.e. swipe up from the bottom to go to the home screen...
When you re-open the app into the foreground, the DebugView should now start displaying events. I imagine this works because the action of moving the app into the background I believe triggers any saved events on the device to be sent to Firebase, essentially flushing the queue.

"[Crashlytics:Crash] Reporting is disabled"

I am getting the following error messages when our production iOS app initializes:
[Crashlytics] Version 3.8.4 (121)
[Crashlytics] Running on iOS Simulator (iPhone), 10.3.0 (16E195)
[Crashlytics:Crash] Reporting is disabled
[Crashlytics] Crash reporting could not be initialized
[Answers] Initialized
[Fabric] Initialized with kit versions: {
"com.twitter.answers.ios" = "1.3.4";
"com.twitter.crashlytics.ios" = "3.8.4";
"io.fabric.sdk.ios" = "1.6.11";
}
Every subsequent call to log an event gets the following error:
[Crashlytics:Crash] WARNING: CLSLog has been used before (or concurrently with)
Crashlytics initialization and cannot be recorded. The message was: ...
The non-production versions of the app work fine running the exact same code but with different bundleIDs. Normally when the app initializes for the first time, then I see the app populate in the Fabric dashboard, but in this case the app is not showing up.
We have an Android and an iOS version of the app, and they both use the same bundleID, so I am wondering if there is a conflict because of that? I see the Android version of the app in the dashboard, and it seems to be working properly. This is an app that originally was a Xamarin app that compiled to both platforms, neither of which incorporated Fabric/Crashlytics. We have now written native apps on each platform, and both are using Fabric/Crashlytics.
Since this is a pre-existing app in both stores, we do not have the option of changing either app’s bundleID.
Make sure you initialize Crashlytics with Fabric before calling any Crashlytics methods:
Fabric.with([Crashlytics.self])
One step I routinely miss is to make sure you've added the build phase on your target:
"${PODS_ROOT}/Fabric/run" ${FABRIC_API_KEY} ${FABRIC_BUILD_SECRET}
and either replace ${FABRIC_API_KEY} and ${FABRIC_BUILD_SECRET} with your key and secret or add custom build settings for each.
There are apparently cases where Crashlytics does not auto-activate new apps so that they show up under your list of apps, even though everything is coded correctly and data is going to their servers. In this case, send an email to Crashlytics support (support#fabric.io) that contains a copy of the info.plist entries for the app in question and they will activate it for you. I have had to do this several times, especially with app extensions.
When I finally traced it down in my situation, the error was entirely correct, but not obvious.
I saw these errors in various testing targets where the code we tested was using a custom logging wrapper which called CLSNSLogv(), but the test didn't actually go through the AppDelegate and therefore did NOT initialize Crashlytics. After trying a few things I was convinced that it worked when executed as an app, but in our configuration it was not working under the unit test configuration.
I'll likely alter our custom wrapper to bypass CLSNSLogv() during testing anyway. The biggest benefit of using that is when crashes occur on devices, so we won't be missing anything.

How to stop Firebase from logging status updates when app is launched

Whenever I launch the FireBase app, it logs the status of various Firebase features. Right now this is what is being logged:
Configuring the default app.
<FIRAnalytics/INFO> Firebase Analytics v.3200000 started
<FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see ...)
<FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
<FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
<FIRAnalytics/INFO> Firebase Analytics enabled
I looked through the pods and didn't find any print statements so how else would I go about stopping these from being logged overtime I run the app?
You can disable the debug logging with the flag -FIRDebugDisabled.
You can add it to your scheme:
Select Scheme toolbar
Edit Scheme
Select Run
Click Arguments and add -FIRDebugDisabled
Add FirebaseConfiguration.shared.setLoggerLevel(.min) before FirebaseApp.configure() to achieve the minimum amount of logging.
func setupFirebase() {
FirebaseConfiguration.shared.setLoggerLevel(.min)
FirebaseApp.configure()
}
By default, Firebase will log info, errors, and warnings.
So u can set the logger level for which ever u need.
If you set for .Error you wil get min log only when error accours.
setLoggerLevel before FirebaseApp.configure() as shown below
In Swift 2.3 and Firebase 4
FirebaseConfiguration.sharedInstance().setLoggerLevel(.Error)
FirebaseApp.configure()
In Swift 3 and Firebase 4
FirebaseConfiguration.shared.setLoggerLevel(.min)
FirebaseApp.configure()
In my case to hide the extra chunk of console log from Firebase I did the following:
Navigate to Product -> Scheme -> Edit Scheme.
Under Arguments tab in the Environment Variables section add OS_ACTIVITY_MODE = disable
Just in case you will need that, just simply uncheck the box.
Disabling OS_ACTIVITY_MODE sometimes will disable logs for all exceptions as well
Edit 1: As #jesus-adolfo-rodriguez said, this is related to Xcode. So, if you don’t want OSLog on the Xcode console, put OS_ACTIVITY_MODE Environment variable to “disable” in your scheme.
Edit 2:
FirebaseConfiguration.shared.setLoggerLevel(FirebaseLoggerLevel.min)
FirebaseApp.configure()
More details in the FIRConfiguration implementation here
Edit 3: 2019
According to this issue:
https://github.com/firebase/firebase-ios-sdk/issues/2774#issuecomment-482780714
Adding -FIRDebugDisabled argument and cleaning the project did the trick.
The logging system in Firebase
The logging system has two modes: default mode and debug mode. In
default mode, only logs with log level Notice, Warning and Error will
be sent to device. In debug mode, all logs will be sent to device. The
log levels that Firebase uses are consistent with the ASL log levels.
Enable debug mode by passing the -FIRDebugEnabled argument to the
application. You can add this argument in the application’s Xcode
scheme. When debug mode is enabled via -FIRDebugEnabled, further
executions of the application will also be in debug mode. In order to
return to default mode, you must explicitly disable the debug mode
with the application argument -FIRDebugDisabled.
It is also possible to change the default logging level in code by
calling setLoggerLevel: on the FIRConfiguration interface.
Swift 4 Firebase 4.10
Set logger level in your AppDelegate.swift
FirebaseConfiguration().setLoggerLevel(FirebaseLoggerLevel.min)
Here is full code:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseConfiguration().setLoggerLevel(FirebaseLoggerLevel.min)
FirebaseApp.configure()
return true
}
FIRConfiguration.sharedInstance().setLoggerLevel(.min)
FIRApp.configure()
In Swift 4
By default Firebase Analytics will only log 4 INFO lines in production + errors/warnings. That should be very little output if things work correctly. Adding -noFIRAnalyticsDebugEnabled will only disable DEBUG level logs and ERROR/WARN are always logged. If you see any warnings or errors you probably need to do something to resolve the cause. Some things will likely not work correctly if warnings/errors are logged. App that is correctly setup should not log errors/warnings.
Messages tagged with FIRInstanceID/* are logged by Firebase Notification and errors/warnings are always logged.
I think there is a big and a very important confusion going on.
By using -FIRDebugDisabled it will disable debug mode which then your measurements will be affected during testing and development.
Currently there is no way to enable debug mode and disable logs at the same time. So the FirebaseConfiguration.shared.setLoggerLevel(.min) will work basically on not debug mode only.
As workaround you can use -noFIRAnalyticsDebugEnabled which is only for Xcode console logging, this one does not disable your debug mode.
As djabi said, you cannot disable those logs if they are INFO, WARNING or ERROR.
I want to add to Nitin Gohel's answer since I can't comment: The flag FirebaseAppDelegateProxyEnabled is not for disabling logs. If you turn it off, you will lose the auto campaign tracking and you will need to add the methods from FIRAnalytics(AppDelegate) to handle URL and user activity yourself.
To add to Alex' answer, from https://firebase.google.com/docs/cloud-messaging/ios/client
FirebaseAppDelegateProxyEnabled is for swizzling your app delegate 's methods
The FCM API performs method swizzling in two key areas: mapping your APNs token to the FCM registration token and capturing analytics data during downstream message callback handling. Developers who prefer not to use swizzling can disable it by adding the flag FirebaseAppDelegateProxyEnabled in the app’s Info.plist file and setting it to NO (boolean value). Relevant areas of the guides provide code examples, both with and without method swizzling enabled.
If you want the clean and necessary logs in console, just set your scheme like this. Open the "Edit Scheme" and select "Arguments".
-FIRAnalyticsDebugEnabled (don't forget "-")
OS_ACTIVITY_MODE = disable

Resources