Conversion Tracking with Firebase

Tracking conversions is essential for understanding how effectively our app meets its goals and drives user actions. Firebase provides robust tools for conversion tracking, enabling us to measure key events, optimize user journeys and improve our app’s performance.

In this article, We will learn about Conversion Tracking with Firebase by setting up conversion tracking in Firebase in detail.

What is Conversion Tracking?

Conversion tracking involves measuring specific actions that users take within our app that are valuable to our business. These actions known as conversions can include purchases, sign-ups or any other goal that indicates user engagement and success.

By tracking these conversions, we can:

  • Measure ROI: Understand the return on investment for our marketing campaigns.
  • Optimize User Experience: Identify areas where users drop off and optimize the user journey to improve conversions.
  • Make Data-Driven Decisions: Use insights from conversion data to make informed decisions about our app and marketing strategies.

Setting Up Firebase for Conversion Tracking

Step 1: Create a Firebase Project

  • Go to Firebase Console: Navigate to the Firebase Console.
  • Create a New Project: Click on “Add project” enter your project name, and follow the setup instructions.

Step 2: Register Your App with Firebase

  • Select Your Platform: Choose the platform (Web, iOS, Android) for your app.
  • Register Your App: Enter the necessary details to register our app.
  • Download Configuration File: Firebase will provide a configuration file (google-services.json for Android or GoogleService-Info.plist for iOS). Add this file to our app.

Step 3: Integrate Firebase SDK

For Android

  • Add Firebase SDK: Open your build.gradle file and add the Firebase SDK:
// Project-level build.gradle
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.3'
}
}

// App-level build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

dependencies {
implementation 'com.google.firebase:firebase-analytics:17.4.3'
}

Add Configuration File: Place the google-services.json file in the app/ directory of our project.

For iOS

Add Firebase SDK: Add the Firebase SDK to our Podfile:

# Podfile
platform :ios, '10.0'

target 'YourApp' do
use_frameworks!
pod 'Firebase/Analytics'
end

Install Pods: Run pod install in our project directory.

Add Configuration File: Add the GoogleService-Info.plist file to your Xcode project.

For Web

Install Firebase: Use npm to install Firebase:

npm install firebase

Initialize Firebase: Initialize Firebase in your app:

import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";

// Your Firebase config object
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_PROJECT_ID.appspot.com",
messagingSenderId: "YOUR_SENDER_ID",
appId: "YOUR_APP_ID",
measurementId: "YOUR_MEASUREMENT_ID"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);

This code initializes a Firebase app using the `initializeApp` function from the `firebase/app` module and initializes Firebase Analytics using the `getAnalytics` function from the `firebase/analytics` module. The `firebaseConfig` object contains the configuration settings for your Firebase project, including the API key, project ID, and other identifiers.

Tracking Conversions with Firebase Analytics

Step 1: Define Conversion Events

Identify the key actions you want to track as conversions. Common conversion events include:

  • Sign-Ups: When a user registers for your app.
  • Purchases: When a user completes a purchase.
  • Button Clicks: When a user clicks on a specific call-to-action button.
  • Feature Engagement: When a user engages with a particular feature in your app.

Step 2: Log Conversion Events

Use the Firebase Analytics SDK to log these events. Here are examples for different platforms:

For Android

import com.google.firebase.analytics.FirebaseAnalytics;

// Initialize Firebase Analytics
FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

// Log a sign-up event
Bundle params = new Bundle();
params.putString("method", "email");
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SIGN_UP, params);

// Log a purchase event
Bundle purchaseParams = new Bundle();
purchaseParams.putString("transaction_id", "T12345");
purchaseParams.putDouble("value", 9.99);
purchaseParams.putString("currency", "USD");
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.ECOMMERCE_PURCHASE, purchaseParams);

This code snippet uses the Firebase Analytics library for Android to log events. It initializes Firebase Analytics and then logs two events: a sign-up event with the method of sign-up (email), and a purchase event with the transaction ID, value, and currency.

For iOS

import Firebase

// Initialize Firebase Analytics
let analytics = Analytics.self

// Log a sign-up event
analytics.logEvent(AnalyticsEventSignUp, parameters: [
AnalyticsParameterMethod: "email" as NSObject
])

// Log a purchase event
analytics.logEvent(AnalyticsEventEcommercePurchase, parameters: [
AnalyticsParameterTransactionID: "T12345" as NSObject,
AnalyticsParameterValue: 9.99 as NSObject,
AnalyticsParameterCurrency: "USD" as NSObject
])

The code snippet uses Firebase Analytics to log events. The first event logs a sign-up event with the method of sign-up (email), while the second event logs a purchase event with the transaction ID, value, and currency.

For Web

import { logEvent } from "firebase/analytics";

// Log a sign-up event
logEvent(analytics, 'sign_up', {
method: 'email'
});

// Log a purchase event
logEvent(analytics, 'purchase', {
transaction_id: 'T12345',
value: 9.99,
currency: 'USD'
});

The code snippet logs events using Firebase Analytics. The first event logs a sign-up event with the method of sign-up (email), while the second event logs a purchase event with the transaction ID, value, and currency.

Step 3: Set Up Conversion Tracking in Firebase Console

  • Go to the Events Section: In the Firebase console, navigate to Analytics > Events.
  • Mark Events as Conversions: Select the events we want to track as conversions and mark them as conversion events. This can be done by toggling the conversion switch next to the event name.

Analyzing Conversion Data

Firebase Analytics Dashboard

  • Navigate to Analytics Dashboard: Go to the Firebase console and click on “Analytics.”
  • View Event Reports: Under the Events tab, view reports for your conversion events. This includes metrics such as event count, user count, and engagement metrics.
  • Conversion Funnels: Use the Funnels feature to visualize the user journey and identify where users drop off in the conversion process.
  • User Engagement Report: Displays metrics like average session duration and number of engaged sessions per user.

Example Outputs

  • Conversion Funnel Report: Shows the user journey from initial engagement to conversion, helping you identify drop-off points.
  • Retention Report: Measures user retention rates over time, indicating how often users return to your app.
  • Revenue Report: Provides insights into in-app purchases and total revenue generated.

Conclusion

Conversion tracking with Firebase is a powerful way to measure and optimize key user actions within your app. By setting up and logging custom events, marking them as conversions, and analyzing the data through the Firebase console, you can gain valuable insights into user behavior and make data-driven decisions to enhance your app’s performance.