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
- 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.
- If you do not have open projects, then select create a new project.
- Select 3D templates from the dialog.
- Fill out the Project Name: e.g. Unity Firebase Custom Event.
- Select a Location to save your project and click CREATE.
- 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.
- Sign in to Firebase.
In the Firebase console, click Add Project(or Create a project), and name your Firebase project Firebase-iOS-Ads
- 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.
To learn more about Firebase projects, see Understand Firebase projects.
4. Unity configuration
- 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.
- 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)
- After platform change click the Player Settings button to set bundle ID. You can see the text field around the Identification area.
- 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.
- In the Firebase dialog, paste the copied bundle ID into the
iOS bundle IDfield.
- Click Register App.
- Continuing in Firebase, follow the instructions to download the config file
- Open the Project window of your Unity project, then move your config file(s) into the Assets folder.
- 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.
- Go to the Firebase console.
- In the center of the project overview page, click the Unity icon ( ) to launch the setup workflow. If you've already added an app to your Firebase project, click Add app to display the platform options.
- 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.
- 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.
- Where do you find your Unity project's ID?
- (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.
- Click Register app.
Add Firebase Analytics Unity SDKs
- 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.
- In your open Unity project, navigate to Assets > Import Package > Custom Package.
- 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
- In the Import Unity Package window, click Import.
- 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.
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:
- 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.
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.
You will mark ‘text_search' as conversion by sliding ‘mark as conversion' switch to right.
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.
- Go to Firebase Settings by clicking the button right next to Project Overview.
- In the Integrations tab, you will see Google Ads and a Link button. Click Link and Continue.
- Choose Google Ads account.
Now the Firebase part is done.
Now, Go to Google Ads and Login.
- Go to Google Ads and log in, and go to Tools & Settings → Measurement → Conversions for importing custom events as conversion.
- Click + button for adding new conversion action.
- Choose Google Analytics 4 properties (Firebase) and click continue.
- You can see all of the analytics events that are marked as conversions. Find the
clicked_counterevent that we implemented before.
- Check and click the Import and Continue button.
After setting text_search as a conversion action, now is the time to launch a campaign that is targeting users who will likely fire
8. Launching app action campaigns with imported events
- Go to the campaign tab of your current account, and start a new campaign by clicking + button. Click the new campaign and continue.
- For this time, we will launch an App promotion campaign with App Installs option.
- Find your app by providing app name, package name or publisher.
- In the Bidding section, select In-app actions in the dropbox for Ads to focus on actions.
- you can find your custom events in the list provided. Set Target cost per action, and fill other options as well.
- 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.
Congratulations, you've successfully integrated your Firebase to Unity and Google Ads! This will help you boost your campaign performance.
- 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.