Skip to content

Commit c243720

Browse files
agrimnE-B-Smith
authored andcommitted
ATAN-523 Code snippets for Adjust reattribution (#827)
* Code snippets for Adjust reattribution * Refactored the Adjust Reattribution code into a different block
1 parent a22823a commit c243720

File tree

1 file changed

+42
-17
lines changed

1 file changed

+42
-17
lines changed

Branch-TestBed-Swift/TestBed-Swift/AppDelegate.swift

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,44 @@ class AppDelegate: UIResponder, UIApplicationDelegate, AdjustDelegate, AppsFlyer
9292
return
9393
}
9494

95+
96+
let clickedBranchLink = params?[BRANCH_INIT_KEY_CLICKED_BRANCH_LINK] as! Bool?
97+
98+
if let referringLink = paramsDictionary["~referring_link"] as! String?,
99+
let trackerId = paramsDictionary["ios_tracker_id"] as! String?,
100+
let clickedBranchLink = clickedBranchLink,
101+
clickedBranchLink {
102+
var adjustUrl = URLComponents(string: referringLink)
103+
var adjust_tracker:URLQueryItem
104+
//
105+
// Here's how to add Adjust attribution:
106+
//
107+
// Check if the deeplink is a Universal link.
108+
if referringLink.starts(with: "https://") || referringLink.starts(with: "http://") {
109+
adjust_tracker = URLQueryItem(name: "adjust_t", value: trackerId)
110+
} else {
111+
adjust_tracker = URLQueryItem(name: "adjust_tracker", value: trackerId)
112+
}
113+
let adjust_campaign = URLQueryItem(name: "adjust_campaign", value: paramsDictionary[BRANCH_INIT_KEY_CAMPAIGN] as? String)
114+
let adjust_adgroup = URLQueryItem(name: "adjust_adgroup", value: paramsDictionary[BRANCH_INIT_KEY_CHANNEL] as? String)
115+
let adjust_creative = URLQueryItem(name: "adjust_creative", value: paramsDictionary[BRANCH_INIT_KEY_FEATURE] as? String)
116+
let queryItems = [adjust_tracker,adjust_campaign,adjust_adgroup,adjust_creative]
117+
adjustUrl?.queryItems = queryItems
118+
Adjust.appWillOpen(adjustUrl?.url as URL!)
119+
}
120+
95121
// Deeplinking logic for use when automaticallyDisplayDeepLinkController = false
96-
if let clickedBranchLink = params?[BRANCH_INIT_KEY_CLICKED_BRANCH_LINK] as! Bool? {
122+
if let clickedBranchLink = clickedBranchLink,
123+
clickedBranchLink {
124+
let nc = self.window!.rootViewController as! UINavigationController
125+
let storyboard = UIStoryboard(name: "Content", bundle: nil)
126+
let contentViewController = storyboard.instantiateViewController(withIdentifier: "Content") as! ContentViewController
127+
nc.pushViewController(contentViewController, animated: true)
97128

98-
if clickedBranchLink {
99-
let nc = self.window!.rootViewController as! UINavigationController
100-
let storyboard = UIStoryboard(name: "Content", bundle: nil)
101-
let contentViewController = storyboard.instantiateViewController(withIdentifier: "Content") as! ContentViewController
102-
nc.pushViewController(contentViewController, animated: true)
103-
104-
let referringLink = paramsDictionary["~referring_link"] as! String
105-
let content = String(format:"\nReferring link: \(referringLink)\n\nSession Details:\n\(paramsDictionary.JSONDescription())")
106-
contentViewController.content = content
107-
contentViewController.contentType = "Content"
108-
}
129+
let referringLink = paramsDictionary["~referring_link"] as! String
130+
let content = String(format:"\nReferring link: \(referringLink)\n\nSession Details:\n\(paramsDictionary.JSONDescription())")
131+
contentViewController.content = content
132+
contentViewController.contentType = "Content"
109133
} else {
110134
print(String(format: "Branch TestBed: Finished init with params\n%@", paramsDictionary.description))
111135
}
@@ -168,20 +192,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate, AdjustDelegate, AppsFlyer
168192
sourceApplication: sourceApplication,
169193
annotation: annotation
170194
)
171-
Adjust.appWillOpen(url)
172-
if (!branchHandled) {
195+
if(!branchHandled) {
173196
// If not handled by Branch, do other deep link routing for the Facebook SDK, Pinterest SDK, etc
197+
Adjust.appWillOpen(url)
174198
}
175199
return true
176200
}
177201

178202
// Respond to Universal Links
179203
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
180-
Branch.getInstance().continue(userActivity)
204+
let branchHandled = Branch.getInstance().continue(userActivity)
181205
if (userActivity.activityType == NSUserActivityTypeBrowsingWeb) {
182206
let url = userActivity.webpageURL
183-
184-
Adjust.appWillOpen(url!)
207+
if(!branchHandled) {
208+
Adjust.appWillOpen(url as URL!)
209+
}
185210
}
186211

187212
// Apply your logic to determine the return value of this method

0 commit comments

Comments
 (0)