Google Ads with Google Analytics for Firebase custom events - Unity

1. Introduction

Last Updated: 2021-02-19

What you'll build

In this codelab, you'll learn how to implement custom events with GA4F iOS on Unity environment and launch action campaigns through Google Ads.

Throughout 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 and Admob on iOS, start with AdMob+Firebase 101 Unity: Setup & Analytics Basics.

What you'll learn

  • How to initialize GA4F (Google Analytics for Firebase) in Unity + iOS.
  • 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
  • Unity
  • Firebase Account
  • Google Ads Account

2. Start a new Unity project

Create a simple templated Unity app. You modify this simple app to create the finished app.

Launch Unity

  1. If you do not have open projects, then select create a new project.
  2. Select 3D templates from the dialog.
  3. Fill out the Project Name: e.g. Unity Firebase Custom Event.
  4. Select a Location to save your project and click CREATE.
  5. Unity 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.

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

d9519856fc3b4bd0.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. Unity configuration

  1. In the Unity > File > Build Settings. The important value is to set the iOS bundle ID, which you'll obtain using the following step.

You will see the dialog shown in the following screen.

7dbfc36bef1d035c.png

  1. In your Unity project for the iOS app open the Build Settings dialog, File > Build Settings (If the Platform is not set to the iOS you can select iOS Platform and click the Switch Platform button)

8be5416883a70def.png

  1. After platform change click the Player Settings button to set bundle ID. You can see the text field around the Identification area.
  2. The value of the Bundle Identifier field is the iOS bundle ID (something like com.yourcompany.yourproject). Copy this value or set your value and copy it.
  3. In the Firebase dialog, paste the copied bundle ID into the iOS bundle ID field.
  4. Click Register App.
  5. Continuing in Firebase, follow the instructions to download the config file GoogleService-Info.plist
  6. Open the Project window of your Unity project, then move your config file(s) into the Assets folder.
  7. Skip the remaining steps and go back to the main page of the Firebase console.

5. Configure Firebase Analytics in Unity

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

  1. Go to the Firebase console.
  2. In the center of the project overview page, click the Unity icon ( 8c8fc0e0e05dc749.png) to launch the setup workflow. If you've already added an app to your Firebase project, click Add app to display the platform options.
  3. Select which build target of your Unity project that you'd like to register, or you can even select to register both targets now at the same time.
  1. Enter your Unity project's platform-specific ID(s).
  • For iOS — Enter your Unity project's iOS ID in the iOS bundle ID field.
  • For Android — Enter your Unity project's Android ID in the Android package name field. The terms package name and application ID are often used interchangeably.
  1. Where do you find your Unity project's ID?
  1. (Optional) Enter your Unity project's platform-specific nickname(s). These nicknames are internal, convenience identifiers and are only visible to you in the Firebase console.
  2. Click Register app.

Add Firebase Analytics Unity SDKs

  1. In the Firebase console, click Download Firebase Unity SDK, then unzip the SDK somewhere convenient.
  • You can download the Firebase Unity SDK again at any time.
  • The Firebase Unity SDK is not platform-specific.
  1. In your open Unity project, navigate to Assets > Import Package > Custom Package.
  2. From the unzipped SDK, select the supported Firebase products that you want to use in your app.
  • Add the Firebase package for Google Analytics: FirebaseAnalytics.unitypackage
  • Add the packages for any other Firebase products you want to use in your app. For example, to use Firebase Authentication and Firebase Realtime Database: FirebaseAuth.unitypackage and FirebaseDatabase.unitypackage
  1. In the Import Unity Package window, click Import.
  2. Back in the Firebase console, in the setup workflow, click Next.

6. Log Custom Events with Firebase Analytics

In this step, you'll learn how to log custom events with Firebase Analytics in the Unity 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.

Firebase.Analytics.FirebaseAnalytics.LogEvent("text_search", name, text);

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

  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

  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 to Unity and Google Ads! This will help you boost your campaign performance.

You've learned

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

Reference docs