Professional Documents
Culture Documents
Complete Guide To Mobile App Campaign Tracking With Firebase, Google Analytics, and Google Tag Manager
Complete Guide To Mobile App Campaign Tracking With Firebase, Google Analytics, and Google Tag Manager
www.e-nor.com
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 1
About the Author
Mahmoud Morsi
Analytics Consultant – Implementation
An enthusiastic advocate for “Work harder but smarter”, Morsi believes that
there is always a solution for any dilemma, “Whatever it takes” is his go to
response in any challenge. Java certified, holding a CIW Master degree in
Web Design and 10+ years of extensive experience in web development,
UI and usability. In addition to Google analytics and Google Analytics APIs ,
Morsi delivers unique exquisite solutions to our client’s needs. His laid back
personality is uncovered by passion to keep learning in every aspect of life,
add to this an impeccable sense of humor and an appetite for soccer, you
will meet a force to be reckoned with.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 2
According to a recent report by Statista, yearly mobile app downloads worldwide now
exceed 178 billion. By 2020, apps are forecast to generate around 189 billion U.S. dollars
in revenue via app stores and in-app advertising. If you’re promoting a mobile app,
competition is fierce. It’s critical to capture the campaign data you need to make timely
business decisions based on clean campaign attribution data.
Mobile app campaign tracking is a multi-step process that requires configuration and
an ongoing commitment to campaign tagging. The steps vary by link type and mobile
operating system. To get it right on the Firebase and Google Analytics platform, you need to
be familiar with key app marketing concepts:
mobile campaigns: broad term that encompasses campaigns on Android and iOS, and
tracked into Google Analytics and/or Firebase Analytics using - as needed per solution
- built-in SDK functionality, your own in-app code, and Google Tag Manager tags,
triggers, and variables.
deep linking: this Firebase feature allows you link directly to an internal screen within
your app. Users who click on the link and but do not yet have the app installed will be
first prompted to install the app.
dynamic linking: this Firebase feature allows you to configure a single link that will
function on different operating systems and also redirect from a general campaign to
an install campaign as needed.
These concepts are separate, but you can coordinate them within the same links, i.e., you
can use Google Analytics campaign parameters with deep and/or dynamic linking, for install
or general campaigns. Additionally, you can parse the same Google Analytics campaign
parameters out of a same URL and populate them into Firebase Analytics and Google
Analytics simultaneously.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 3
Parameters and Tags
• campaign parameters
• campaign tags
• UTM parameters
• UTM tags
Note that tagging in the context of campaigns refers to the query parameters that
you add to the URL, while tagging in the context of Google Tag Manager or another
tag management system usually refers to a functionality that is encapsulated and
deployed in a unit referred to as a tag, which is not directly related to campaign
tagging.
Install campaigns are for tracking when a user installs your app, as the name suggests.
The explosive growth in app usage has created an extremely competitive marketplace, so
more and more marketers are running paid install campaigns.
Tip: include the word install in the campaign names of install campaigns to readily distinguish
them from general campaigns.
General campaigns let you monitor campaigns or referrers that launch your app after it
has been installed. If a campaign directs visitors to a deep page within your mobile app, you
need to use a specific type of link called a deep link. Deep links and dynamic links will be
examined later in the post.
Install and General Campaigns with Legacy GA SDKs and GTM and Firebase
SDK
In 2016, the Google-recommended implementation of Google Analytics in mobile apps
shifted. Until that time, you could choose to implement GA in your Android or iOS app by
including either the GA SDK or the combined GTM/GA SDK. These SDKs are now generally
referred to as legacy.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 4
legacy SDKs: Google Analytics SDK or combined Google Tag Manager/Google Analytics
SDK
Firebase also has a standalone SDK that does not include GTM, but we recommended
using the GTM & Firebase SDK and taking advantage of the parallel tracking in Google
Analytics, as described below, and, as needed, additional tags (for third-party tracking
on Kochava, as an example) available in GTM for mobile apps.
The shift in Google’s recommendation was to include the GTM & Firebase SDK in your
Android or iOS app (instead the GA or GTM/GA SDK) and to translate Firebase events,
parameters, and user properties into GA data through GTM, a process we outline in a later
section.
Depending on the SDK you’re using, and type of campaign you’re running, there are
different requirements for tracking your campaigns into Google Analytics and Firebase
Analytics.
In the case of install campaigns, the legacy SDKs do not require further coding; the Google
Analytics property setting for campaign tracking will do the trick for iOS, and an addition
to the manifest file is all that’s required for Android. In the case of general campaigns, the
legacy SDKs do require special code to read the campaign parameters in from the URL.
Requirements for tracking install and general campaigns using a legacy GA or GTM/GA SDK
vs. the GTM & Firebase SDK.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 5
In the case of the GTM & Firebase SDK, custom code is required to track campaigns in
Firebase, and tagging is needed in Google Tag Manager to parse the campaign parameters
from the Firebase code into Google Analytics.
Below are a few guidelines for mobile app tracking within the Google Analytics and
Firebase hierarchy:
• mobile app view: it’s not a requirement to create a mobile app account or even
a mobile app property to track mobile app activity in Google Analytics. You only
need to make sure that you have a mobile app view, within either a mobile app
property or even a web property.
• separate properties or separate views for Android and iOS: it’s generally
considered best practice to track the Android and iOS versions of your mobile app
in two separate Google Analytics properties, but you can choose to track into the
same property and originally create separate filtered views within the property
for Android and iOS. These can be website properties that contain mobile app
views and that are not actually tracking any website activity.
• same Firebase project for Android and iOS: you can still track the Android and
iOS versions of your app into the same Firebase project, even if you’re tracking
them in separate Google Analytics properties.
• linking not necessary: it’s not a requirement to link Firebase to Google Analytics
in property admin. If you try to create a new mobile app property in Google
Analtics, you’ll be prompted to link to Firebase. This just makes Firebase Analytics
reports accessible within the Google Analytics UI but does not create affect any
aspects of data capture in either Firebase or Google Analytics.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 6
You can create a Mobile App view within a Mobile App property or a Website property.
1. Add the Google Analytics receiver to your AndroidManifest.xml file. To add the
Google Analytics receiver to the manifest, copy and paste the following markup:
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 7
<application>
<!-- Used for Google Play Store Campaign Measurement-->
<receiver android:name=”com.google.android.gms.analytics.
CampaignTrackingReceiver”
android:enabled=”true”
android:exported=”true”>
<intent-filter>
<action android:name=”com.android.vending.INSTALL_
REFERRER” />
</intent-filter>
</receiver>
<service android:name=”com.google.android.gms.analytics.
CampaignTrackingService”
android:enabled=”true”
android:exported=”false” />
</application>
As the first step in tracking Google Analytics install campaigns on a legacy SDK,
add the Google Analytics receiver to your Android manifest file.
Add a referrer parameter to any URLs that will be linking directly to Google Play Store and
set the value of that parameter to a string of Google Analytics campaign parameters that
describe the source, as in this example:
https://play.google.com/store/apps/details?id=com.example.
application
&referrer=utm_source%3Dtwitter
%26utm_medium%3Dpaid-social
%26utm_content%3Dlogolink
%26utm_campaign%3Dspring_sale
As the other step in tracking Google Analytics install campaigns on a legacy SDK, add a referrer parameter to the
Google Play link. The referrer parameter value concatenates multiple Google Analytics campaign parameters.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 8
Autotagging for Google Ads (AdWords) Campaigns
If you have enabled Autotagging in your Google Ads account, you do not need to
manually tag your campaign links.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 9
// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).
getTracker(
TrackerName.APP_TRACKER);
Using the Java setCampaignParamsFromURL to extract UTM parameters for a general campaign
on Android and populate them into Google Analytics through a legacy SDK.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 10
2. Add Google Analytics Campaign Parameters to using the Google Analytics URL
Builder for Android.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 11
Prerequisites for iOS Campaign Tracking
There are three prerequisites for setting up iOS install campaign tracking in Google
Analytics:
• You must have already implemented Google Analytics in your iOS app (through
the legacy Google Analytics SDK or the Google Tag Manager/Google Analytics
SDK, which we discuss in this section, or the Google Tag Manager + Firebase SDK,
which we discuss in a later section).
• You need to enable collection of the Identifier for Advertisers (IDF).
• You need to be tracking one or more screenviews or events in your app.
The prerequisites above apply whether you’re using either a legacy GA or GTM/GA SDK
as described immediately below or the GTM & Firebase SDK as described later in this
guide.
• You must be using version 3.10 or higher of the SDK.
• Your app is linked with libAdIdAccess.a as part of the Google Analytics iOS
release.
• Your app is linked with AdSupport.framework.
• You can enable IDFA collection on your tracker by calling: tracker.
allowIDFACollection = YES; (Note: if you have multiple tracker objects, you have to
enable IDFA collection on each.)
Also:
• If you use CocoaPods to install and manage dependencies, add the
GoogleIDFASupport Cocoapod to the Podfile: pod ‘GoogleIDFASupport’
• If possible, use a debugging proxy application to view HTTP requests and confirm
IDFA is included.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 12
iOS Install Campaigns with Legacy SDK
Campaign Type:
Confirm Tracking Install
Operating System:
Follow these five steps to confirm tracking is enabled for a iOS
Google Analytics property: SDK:
1. Confirm iOS campaign tracking is enabled in Google Legacy GA or GTM/GA
Analytics user interface.
Verify that iOS Campaign tracking is enabled in the Google Analytics property settings.
To correctly attribute a campaign with app data, the iOS campaign tracking URL and your
app tracking implementation need to use the same App ID. To determine the App ID for
an app that you’re currently tracking, create a custom report in the Google Analytics web
interface with App Id as a dimension and Sessions as a metric.
Configure a basic Google Analytics custom report to surface the iOS App ID.
While creating a click iOS campaign tracking URL, use the App ID appearing in the custom
report.
3. Confirm that the GA or GTM/GA SDK is sending the identifier for Advertisers.
Google Analytics uses an Identifier for Advertisers to generate the demographics reports. In
Google Analytics, click the Reporting tab and click Audience > Demographics > Overview to
check if you see demographic data. If you do, the IDFA is being sent correctly.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 13
If the Demographics Overview report is populated in your Google Analytics view where you’re tracking your iOS
app, this indicates that the IDFA is being sent correctly to Google Analytics.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 14
4. Add Google Analytics Campaign Parameters using the Google Analytics URL Builder
for iOS.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 15
iOS General Campaign with Legacy SDK
Campaign Type:
General
After your iOS app has been installed, it can be launched from
Operating System:
various locations like ad campaigns, websites and even other
iOS
apps. You can track general campaign traffic by setting the
SDK:
campaign fields on a tracker object.
Legacy GA or GTM/GA
The easiest way to read in this general campaign data is to use
[GAIDictionaryBuildersetCampaignParametersFromUrl:urlString], where urlString is a string
representing a URL that may contain Google Analytics campaign parameters. Note that in
the following examples, campaign data is not set on the tracker directly, as it only needs to
be sent once. onCreate() method in Android, and viewDidAppear() method in iOS swift.
Code Example:
/*
* MyAppDelegate.m
*
* An example of how to implement campaign and referral
attribution.
* If no Google Analytics campaign parameters are set in the
referring URL,
* use the hostname as a referrer instead.
*/
trackingId:@”UA-XXXX-Y”];
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 16
// setCampaignParametersFromUrl: parses Google Analytics
campaign (“UTM”)
// parameters from a string url into a Map that can be set on a
Tracker.
GAIDictionaryBuilder *hitParams = [[GAIDictionaryBuilder alloc]
init];
Using the GAIDictionaryBuilder utility in Swift code to extract UTM parameters for a general campaign on iOS and
populate them into Google Analytics through a legacy SDK.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 17
Building a Custom Campaign Manually
We recommend using the iOS and Android URL Builders to build custom campaign
URLs as outlined above, as they can help with consistency. That being said, it is
possible to build custom campaign tags manually if you ever need to add extra
parameters. Examples of manual tagging for iOS and Android are shown below.
Android example:
https://play.google.com/store/apps/details?id=com.example.application
&referrer=utm_source%3Dtwitter
%26utm_medium%3Dpaid-social
%26utm_campaign%3Dspring_sale
%26utm_content%3Dlogolink
iOS example:
https://click.google-analytics.com/
redirect?tid=UA-1234-5
&url=https%3A%2F%2Fitunes.apple.com%2Fus%2Fapp%2Fmy-app%2Fid12345678
&aid=e.g. Com.company.app
&idfa=%{idfa}
&cs=twitter
&cm=paid-social
&cn=spring_sale
&ck=3Dlogolink
accommodate your own code for populating custom events and parameters into Firebase
Analytics
allow you to use GTM tags, triggers, and variables to transfer Firebase event, parameter,
and user property data into Google Analytics data
This configuration applies to mobile app tracking with the GTM & Firebase SDK. The app
lifecycle events that are populated automatically into Firebase don’t include campaign
parameters, so the solution for populating campaign data into Firebase Analytics requires
your own coding, which you can then also leverage through Google Tag Manager to
populate campaign data into Google Analytics.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 18
Tracking campaigns in Firebase Analytics and Google Analyitcs using the GTM & Firebase SDK.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 19
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new
OnSuccessListener<PendingDynamicLinkData>() {
@Override
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
// account.
// ...
String cs = String.valueOf(deepLink.
getQueryParameters(“utm_source”));
String cn = String.valueOf(deepLink.
getQueryParameters(“utm_campaign”));
String cm = String.valueOf(deepLink.
getQueryParameters(“utm_medium”));
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 20
params.PutString(FirebaseAnalytics.param.
SOURCE, cs);
params.PutString(FirebaseAnalytics.param.
MEDIUM, cm);
params.PutString(FirebaseAnalytics.param.
CAMPAIGN, cn);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.
Event.CAMPAIGN_DETAILS, params);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.
Event.APP_OPEN, params);
// ...
})
@Override
});
Java code to extract UTM parameters from URL on Android and populate them into Firebase Analytics
through the GTM & Firebase SDK. This code will also expose the URL parameters as Firebase event
parameters in Google Tag Manager, which you can then repurpose as Google Analytics campaign
parameters. For campaign tracking with the GTM & Firebase SDK on iOS, you can log the equivalent
event and parameters.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 21
Viewing Campaign Performance in Firebase Analytics and Google Analytics
If we take advantage of the GTM & Firebase SDK for parallel campaign tracking as described
above, we can populate the same campaign parameters into Firebase Analytics and Google
Analytics.
The official name for the Analytics reporting section within Firebase is Google Analytics
for Firebase, but this is still commonly referred to as Firebase Analytics.
You can use the Sources report in the Acquisition section of Google Analytics to analyze
campaign performance.
The Sources > iTunes Report. For iOS campaigns, the iTunes report will let you see all
campaign information including the source and medium that led users to your iOS app. The
users metric displays the total number of users and the new users metric measures first
open by user. This is the metric for your app install campaigns. (There is not currently an
App Store report broken out separately in GA.)
The Sources > All Report. This report shows all campaign data including the iTunes data.
This report is useful when you are using the same property for an Android and an iOS app.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 22
Campaign data in the Sources > All report
Dynamic Links
If you are using the GTM & Firebase SDK for your mobile app tracking, Firebase provides
handy feature that allows us to create dynamic links to:
• encapsulate the necessary URL structure for both Android and iOS
• automatically prompt an install for a general campaign if the user has not yet installed
the app, which would otherwise need to be coded by your developers
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 23
3. Click on NEW DYNAMIC LINK button
4. Enter all required configuration and click CREATE DYNAMIC LINK button
As mentioned before, deep links are mobile app links that take users deep into a
specific screen of your mobile app.
You can define your own custom URL scheme, and then that URL should be handled
inside the app to take the user to the correct content.
The URL can be anything like open my app, or you can add customize the URL as open
my app/points. In either case, you need to code the logic to open a specific screen in
your app, or use a third-party hosted deep links provider to do so.
5. Enter the link that you will use to encapsulate the dynamic link functionality. This can be
a deep link.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 24
In this example, we’re populating a deep link as a dynamic link. This is the link that you will use for your
campaigns and that will activate the dynamic redirects and deep linking that you have configured.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 25
6. Enter the iOS redirect.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 26
7. Enter the Android redirect.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 27
8. Configure your campaign parameters.
You don’t have to configure campaign parameters with dynamic links, but it makes sense
in most cases, since you probably want to maintain the same campaign parameters for
Android and iOS.
If you do configure campaign parameters within the dynamic link, you don’t have to
configure them in the URL builder tools as shown above.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 28
Manually Constructing a Dynamic Link URL
You can create a Dynamic Link by manually constructing a URL with the following
form:
https://app_code.app.goo.gl/?link=your_deep_link&apn=package_
name[&amv=minimum_version][&afl=fallback_link]
As stated in the previous example of manually tagged campaign links, this approach
would allow you to specify additional parameters that the tagging utilities do not
accommodate.
Summary
Measuring mobile app campaigns in Google Analytics and Google Firebase will help you
understand how users are finding and installing your app. If you’re running paid install
campaigns, tracking is paramount for measuring your return on investment.
Need support for your mobile campaign strategy and implementation? Contact E-Nor.
Complete Guide to Mobile App Campaign Tracking with Firebase, GA, and GTM www.e-nor.com | 29