Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Branch
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil) -> Bool {
- let branch: Branch = Branch.getInstance()
- branch.initSession(launchOptions: launchOptions, andRegisterDeepLinkHandler: { params, error in
- if error == nil {
- branch.setRequestMetadataKey("$google_analytics_client_id", value: GAI.sharedInstance().defaultTracker.get(kGAIClientId) as NSString)
- if let id = UserAccountEntity().userId {
- branch.setRequestMetadataKey("$google_analytics_user_id", value: NSNumber(value: id))
- }
- if let cid = params?["cid"] as? String {
- TradeTracker.shared.identifyUser(branchId: cid)
- }
- if let canonicalId = params?["$canonical_identifier"] as? String,
- let url = URL.init(string: canonicalId) {
- DeeplinkCoordinator.shared.processDeeplinking(url)
- }
- BranchTracker.shared.trackInstall()
- let campaign = params?["~campaign"] as? String
- let channel = params?["~channel"] as? String
- let feature = params?["~feature"] as? String
- TradeTracker.shared.trackBranchInitWith(campaign, channel, feature)
- }
- })
- }
- class TradeTracker {
- func trackBranchInitWith( campaign: String?, channel: String?, _ feature: String?) {
- let params = [kGAICampaignName: feature ?? "n/a",
- kGAICampaignSource: channel ?? "n/a",
- kGAICampaignMedium: campaign ?? "n/a",
- kGAIDescription: "welcome_page"]
- let sv = GAIDictionaryBuilder.createScreenView()
- if let built = sv?.setAll(params).build() {
- tracker.send(built as! [AnyHashable : Any])
- }
- var action = "open"
- if firstOpen == false {
- firstOpen = true
- action = "first open"
- }
- let dictionaryBuilder = GAIDictionaryBuilder.createEvent(withCategory: "CustomBranch",
- action: action,
- label: nil,
- value: nil)
- if let build = dictionaryBuilder?.setAll(params).build() {
- tracker.send(build as! [AnyHashable : Any])
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement