Firebase Analytics
Google Analytics for Firebase provides free, unlimited reporting on up to 500 distinct events. The SDK automatically captures certain key events and user properties, and you can define your own custom events to measure the things that uniquely matter to your business. Let’s see How to add Firebase Analytics in iOS app
Use of Firebase Analytics
Sometimes we need to track our application like (Most view page, most like the product, the number of logins, and places), etc. for that Google fireBase provides functionality.
Google Analytics helps you understand how people use your web, iOS, or Android app.
The SDK automatically captures a number of events and user properties and also allows you to define your own custom events to measure the things that uniquely matter to your business.
Once the data is captured, it’s available in a dashboard through the Firebase console.
This dashboard provides detailed insights about your data — from summary data such as active users and demographics to more detailed data such as identifying your most purchased items.
Getting Started with How to add Firebase Analytics in iOS app
Google Analytics collects usage and behavior data for your app. The SDK logs two primary types of information:
- Events: What is happening in your apps, such as user actions, system events, or errors?
- User properties: Attributes you define to describe segments of your user base, such as language preference or geographic location.
Step 1: Before you begin, add Firebase to your iOS project. You can check here to add a firebase to your project.
Step 2: Now, add analytics SDK to your project.
1 |
pod 'Firebase/Analytics' |
Step 3: Then open AppDelegate file in your project and import Firebase.
Step4: Configure a FirebaseApp shared instance, typically in your app’s application:didFinishLaunchingWithOptions:
method:
1 |
FirebaseApp.configure() |
Please check the following example, how to log an event to check how many times particular Product Details are viewed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
var jeans: [String: Any] = [ AnalyticsParameterItemID: "SKU_123", AnalyticsParameterItemName: "jeans", AnalyticsParameterItemCategory: "pants", AnalyticsParameterItemVariant: "black", AnalyticsParameterItemBrand: "Levi's", AnalyticsParameterCurrency: "Rs", AnalyticsParameterValue: 1000.00 ] var productDetails: [String: Any] = [ AnalyticsParameterCurrency: "Rs", AnalyticsParameterValue: 1000.00 ] // Add items array productDetails[AnalyticsParameterItems] = [jeans] // Log view item event Analytics.logEvent(AnalyticsEventViewItem, parameters: productDetails) |
You can also check the code in Objective-C here.
Step6: To view this event in the Xcode debug console, enable Analytics debugging:
- In Xcode, select Product > Scheme > Edit scheme…
- Select Run from the left menu.
- Select the Arguments tab.
- In the Arguments Passed On Launch section, add
-FIRAnalyticsDebugEnabled
.
Thanks for reading 🙂