GTM iOS Setup
Steps for using Google Tag Manager with the Branch iOS SDK.
Overview
You can use Google Tag Manager (GTM) to trigger specific actions related to Branch.
This guide walks you through how to do this for your iOS app, in combination with the Branch iOS SDK.
More specifically, you will learn how to create and log Branch Events.
Prerequisites
In order to use GTM and Branch together, you first need to:
- Create a GTM account that has a container with "iOS" as the chosen platform.
- Integrate the Branch iOS SDK into your iOS app.
Setup
Import GTM
Add the following line to your podfile
to import the GTM library:
pod 'GoogleTagManager', '~> 6.0'
To learn more about how to set up your podfile
, visit the iOS Basic Integration guide and review the CocoaPods steps.
Create Custom Class
You'll now need to write a class that includes your Branch code. This is the code that GTM will be configured to call.
Create a class that extends NSObject
and implements TAGCustomFunction
.
In this example, the class will create and log a Branch PURCHASE
Event when triggered by GTM.
Note the path to this class in your code. You'll need it when you create your tag in GTM.
Implement Branch Features
Track Events
1. Create a Trigger
Create a new trigger that is associated with a Firebase event.
-
In the Workspace tab, click on Triggers.
-
Click New, and create a trigger with type Custom Event.
-
Provide an event name and configure when you want the trigger to fire.
-
Click Save.
2. Create a Tag
Create a new tag, which will describe what you want to have occur when the trigger fires.
-
In the Workspace tab, click on Tags.
-
Click New, and create a tag with type "Function Call".
-
For the Class Path field, add the path that leads to your custom class that calls Branch Event code.
-
In the Key and Value sections, add your relevant variables.
-
In the Triggering section, add the trigger you just created.
-
Click Save.
3. Deploy GTM Changes
Deploy the changes you have made on the GTM side. Once you do this, the Branch Event creation and logging code will run every time the GTM tag is fired.
5. Trigger Firebase Event
In your code, trigger the Firebase event associated with the GTM trigger you created.
let parameters: [String: Any] = [
AnalyticsParameterCurrency: "EUR",
AnalyticsParameterValue: 100
]
Analytics.logEvent(AnalyticsEventPurchase, parameters: parameters)
NSDictionary *parameters = @{
AnalyticsParameterCurrency: @"EUR",
AnalyticsParameterValue: @100
};
[Analytics logEvent:AnalyticsEventPurchase parameters:parameters];
Testing
Liveview
To make sure you've successfully set up GTM to work with the Branch iOS SDK:
- Trigger the event you are interested in, based on the trigger you set up in GTM.
- Go to the Liveview page of the Branch Dashboard.
- Filter the dropdown to the relevant event type that you are interested in, such as "custom event".
- Check to make sure that the event is being triggered with the expected details.
Enable Branch iOS SDK Logging
Make sure you have logging enabled within the Branch iOS SDK so you can see logs related to the Branch Event.
For steps on how to do this, visit our Branch iOS SDK Testing guide.
FAQs
Visit our FAQs section to learn more about implementing Branch with GTM.
Updated 5 months ago