Log Branch Events Using Google Tag Manager
Overview
사용 사례 : Google 태그 관리자(GTM), Firebase 및 Branch library를 사용하여 Branch 이벤트를 기록합니다. 이는 GTM 커스텀 함수를 사용하여 수행됩니다.
필수 조건 : Branch SDK는 iOS 및 안드로이드 앱에 반드시 설치되어 있어야 합니다.
경고
This has not been tested intensively (with different use cases)!
안드로이드에서 커스텀 태그 설정
전제 조건
안드로이드에 Branch SDK가 설치되어 있는지 확인하세요.
- GTM 컨테이너 가져 오기
- Implement a class that extends
com.google.android.gms.tagmanager.CustomTagProvider
.
Please see an example below :
import android.support.annotation.Keep;
import java.util.Map;
import branch
@Keep
public class HighScoreProvider implements com.google.android.gms.tagmanager.CustomTagProvider {
@Override
...
}
- If using ProGuard, make sure that the class names and methods are not obfuscated. Use the Keep annotation to specify this.
- 이 커스텀 클래스 내에서 다음 함수를 사용하십시오.
public abstract void execute (Map<String, Object> parameters)
- Within this function, read the parameters passed by GTM within the "execute" function and log a Branch standard /custom event. Please ensure you import the Branch library.
@Keep
public class TagProviderImpl implements CustomTagProvider {
...
@Keep
public void execute(Map<String, Object> variables) {
BranchEvent event = new BranchEvent("View Event");
for (String key: variables.keySet()) {
event.addCustomDataProperty(key, variables.get(key).toString());
}
event.logEvent(context);
}
}
iOS에서 커스텀 태그 설정
전제 조건
iOS에 Branch SDK가 설치되어 있는지 확인하십시오.
- GTM 컨테이너 가져 오기
- 브리징 헤더가 포함되어 있는지 확인하십시오 (특히 Swift와 Objective-C를 모두 사용하는 코드베이스의 경우).
- Xcode를 오픈합니다.
- File > New > File을 클릭합니다.
- iOS > Source에서 헤더 파일을 선택하십시오.
- 다음을 클릭합니다.
- Enter the header file name
BridgingHeader.h
.

6. Click Create.
- 빌드 설정에 Objective-C 브리징 헤더 추가
- Xcode에서 프로젝트를 클릭합니다.

2. Click Build Settings in the editor area.
3. Select All and Combined and search for bridging.
4. In the right column of the row containing Objective-C Bridging Header, enter `BridgingHeader.h`.

- CustomEventTagFunction과 같은 커스텀 클래스 구현
import Foundation
import GoogleTagManager
@objectivec(CustomEventTagFunction)
final class CustomEventTagFunction : NSObject, TAGCustomFunction {
...
}
- 이 커스텀 클래스 내에서 다음 함수를 사용하십시오.
@objectivec func execute(withParameters parameters: [AnyHashable : Any]!) -> NSObject! { ...}
- Within this function, read the parameters passed by GTM within the "execute" function and log a Branch standard or custom event. Please ensure you import the Branch library. This is an example:
import Foundation
import GoogleTagManager
import Branch
@objectivec(CustomEventTagFunction)
final class CustomEventTagFunction : NSObject, TAGCustomFunction {
@objectivec func execute(withParameters parameters: [AnyHashable : Any]!) -> NSObject! {
print("********************* parameters: \(String(describing: parameters))")
let event_Name = parameters["event_name"] as! String
let event = BranchEvent.customEvent(withName: event_Name)
parameters.keys.forEach { key in
let a = parameters[key] as! String
event.customData[key] = a
print("*", a)
}
event.logEvent()
return nil
}
}
Firebase 이벤트를 통해 이벤트 트리거
- GTM을 통해 트리거 된 이벤트가 있는지 확인하십시오.
다음은 예시입니다.
dataLayer.push(["event": "branch_event", "screenName": "Home Screen"])
GTM 설정
- 이벤트에 대한 트리거를 설정합니다.
- Add filters for when this trigger is fired.

- Add relevant event variables of what to add in.
- 새 변수 만들기
- 'Event Parameter'를 선택합니다.
- Branch 판매 엔지니어 또는 솔루션 엔지니어와 협력하여 생성할 변수를 결정하십시오.

- Create a new Tag under the Tags section and provide a name.
- Click on Tag Configuration, and under Tag type, select Function Call.
- 클래스 경로 섹션에서 생성된 클래스 경로를 제공합니다.
- iOS :이 섹션을 보십시오
- 안드로이드: 이 섹션을 보십시오
- Expand the “Add Argument” section and provide the key as "event_name" with the event name macro. Add in other keys which you need.
- 트리거링 섹션을 클릭하고 이 태그를 실행할 적절한 트리거를 선택합니다.

- iOS 및 안드로이드에서 각각 컨테이너를 업데이트했는지 확인하십시오.
Updated 3 months ago