Google Ads with Google Analytics for Firebase custom events - iOS

1. Introduction

Last Updated: 2020-12-14

What you'll build

In this codelab, You will learn how to implement custom events with GA4F iOS SDK and launch action campaigns through Google Ads.

Through this codelab, you can experience the whole process of App business that our clients are facing. If you want to learn a gentler introduction to Firebase iOS, start with Firebase iOS Codelab Swift

What you'll learn

  • How to initialize GA4F (Google Analytics for Firebase) in iOS Swift
  • How to create custom events and parameters.
  • How to import events from Firebase to Google Ads
  • Launch action campaigns with custom events.

What you'll need

  • Xcode
  • Firebase Account
  • Google Ads Account

2. Start a new iOS Swift project

Create a simple templated iOS Swift app. You modify this starter app to create the finished app.

First, Launch Xcode.

  1. If you do not have open projects, then select Create a new Xcode project from the welcome page.
  2. Select iOS at the top of the dialog.
  3. In the Application section, select App and then click Next.
  4. In the dialog that appears, use the following values to name your app and choose additional options for your project, and click Next :
  5. Product Name: e.g. ios-app

Xcode uses the product name you entered to name your project and the app.

  1. Team: If this is not automatically filled in, set the team to None.
  2. Organization Name: The name of your organization or your own name.
  3. Bundle Identifier: This value is automatically generated based on your product name and organization identifier.
  4. Language: Swift
  5. Select a location to save your project and click Create.
  6. Xcode opens your new project in the workspace window.

3. Create and set up a Firebase project

To get started with Firebase, you'll need to create and set up a Firebase project.

Create a Firebase project

If you have an existing Firebase project that doesn't have Google Analytics enabled, you can enable Google Analytics from the Integrations tab of your settings > Project settings. Move on to Firebase configuration Step.

  1. Sign in to Firebase.

In the Firebase console, click Add Project(or Create a project), and name your Firebase project Firebase-iOS-Ads

9b0ae97cc3c6f1d0.png

  1. Click through the project creation options. Accept the Firebase terms if prompted. You should enable Google Analytics for this project, since you need Google Analytics events for tracking action events and conversions.

e58151a081f0628.png

To learn more about Firebase projects, see Understand Firebase projects.

4. Firebase configuration

  1. In the Firebase Console, Select Project Overview > Project Settings in the left nav, then click the iOS button under General > Your apps

You will see the dialog shown in the following screen.

425bb1c07921e71d.png

  1. The important value to provide is the iOS bundle ID, which you'll obtain using the following step.
  2. In your Xcode project for the iOS app, select the top-level app in the project navigator, then select the General tab.
  3. The value of the Bundle Identifier field is the iOS bundle ID (something like com.yourcompany.yourproject). Copy this value.
  4. In the Firebase dialog, paste the copied bundle ID into the iOS bundle ID field.
  5. Click Register App.
  6. Continuing in Firebase, follow the instructions to download the config file GoogleService-Info.plist

26e5b98711c2787a.png

  1. Go to your Xcode Project, then move the GoogleService-Info.plist file (that you just downloaded) into the root of your Xcode project.
  2. Skip the remaining steps and go back to the main page of the Firebase console.

5. Configure Firebase Analytics in Xcode

In this step, you'll start adding Firebase SDK to your Xcode project.

  1. Open a terminal window and navigate to the location of the Xcode project for your app.
  2. Create a Podfile if you don't have one:

$ pod init

  1. Open your Podfile and add :

$ vi Podfile

$ pod 'Firebase/Analytics' 54204c9ce2a49666.png

  1. Save the file and run :

$ pod install

  1. Add initialization code :

To connect Firebase when your app starts up, add the initialization code below to your main AppDelegate class.

import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

  func application(_ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions:
      [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    return true
  }
}
  1. You're all set! Continue to console.

Now you are ready for firing some custom event logs!

6. Log Custom Events with Firebase Analytics

In this step, you'll learn how to log custom events with Firebase Analytics in the iOS app.

Firebase Analytics automatically logs some events for you; you don't need to add any code to receive them. If your app needs to collect additional data, you can log up to 500 different Analytics Custom Event types in your app.

Log events

After you have configured the FirebaseApp instance, you can begin to log events with the logEvent() method.

Analytics.logEvent("text_search", parameters: [
  "name": name as NSObject,
  "full_text": text as NSObject
  ])

Set default event parameters

You can log parameters across events using setDefaultEventParameters. Default parameters are associated with all future events that are logged.

Analytics.setDefaultEventParameters([
  "level_name": "Caverns01",
  "level_difficulty": 4
])

View events in the Xcode debug console

You can enable verbose logging to monitor logging of events by the SDK to help verify that events are being logged properly. This includes both automatically and manually logged events.

You can enable verbose logging as follows:

  1. In Xcode, select Product > Scheme > Edit scheme...
  2. Select Run from the left menu.
  3. Select the Arguments tab.
  4. In the Arguments Passed On Launch section, add -FIRAnalyticsDebugEnabled.

The next time you run your app, your events will display in the Xcode debug console, helping you immediately verify that events are being sent.

View events in the dashboard

You will see your logged event in the Firebase console in several hours. It is located in Analytics → Events. You can also find parameter values by clicking the event.

286b640ed4646163.png

You will mark ‘text_search' as conversion by sliding ‘mark as conversion' switch to right.

a933a338990cba3a.png

You can double check if the event is successfully marked as conversion through the Firebase Analytics Conversions tab. By marking the event as conversion, Google Ads will also be able to import the event as a conversion.

7. Importing analytics events in Google Ads

Your Firebase-iOS setup is finished, and you're ready to launch the app campaign with logged action events. You'll start by linking Firebase to Google Ads. By linking Firebase to Google Ads, app campaigns will be able to learn more about audiences and boost app campaign learnings, which usually lead to better performance and conversions.

  1. Go to Firebase Settings by clicking the button right next to Project Overview.
  2. In the Integrations tab, you will see Google Ads and a Link button. Click Link and Continue.

b711bf2e94fa0895.png

  1. Choose Google Ads account.

Now the Firebase part is done.

Now, Go to Google Ads and Login.

  1. Go to Google Ads and log in, and go to Tools & Settings → Measurement → Conversions for importing custom events as conversion.
  2. Click + button for adding new conversion action.

73cec8d2e80eab03.png

  1. Choose Google Analytics 4 properties (Firebase) and click continue.

4b1d8f6a712b2ac6.png

  1. You can see all of the analytics events that are marked as conversions. Find the clicked_counter event that we implemented before.

ba1bbe6b2924fac8.png 2b9abde9fb95d188.png

  1. Check and click the Import and Continue button.

ab35e341dff32e48.png

After setting text_search as a conversion action, now is the time to launch a campaign that is targeting users who will likely fire text_search events.

8. Launching app action campaigns with imported events

  1. Go to the campaign tab of your current account, and start a new campaign by clicking + button. Click the new campaign and continue.
  2. For this time, we will launch an App promotion campaign with App Installs option.

af98c44d1476558.png

  1. Find your app by providing app name, package name or publisher.
  2. In the Bidding section, select In-app actions in the dropbox for Ads to focus on actions.
  3. you can find your custom events in the list provided. Set Target cost per action, and fill other options as well.

a1f145794f949109.png 3dc838d7f4eeeba5.png

  1. Configure campaign settings. This will be beyond the scope of codelab, so refer to these documents, or contact through any other channels for optimizing settings.

9. Congratulations

Congratulations, you've successfully integrated your Firebase and Google Ads! This will help you boost your campaign performance.

You installed the script, created and staged a new codelab changelist, updated and staged the pending codelab changelist, reviewed and approved the codelab changelist, and submitted and published the codelab changelist.

You've learned

  • How to Configure Firebase for iOS
  • How to log custom events with iOS and Firebase Analytics
  • How to import events and use it for action campaigns.