Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MBL-1147] Track push notifications #1943

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions Kickstarter-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,19 @@ internal final class AppDelegate: UIResponder, UIApplicationDelegate {
.observeValues { [weak self] writeKey in
guard let strongSelf = self else { return }

let (configuration, appBoyInstance) = Analytics.configuredClient(withWriteKey: writeKey)

appBoyInstance?.saveLaunchOptions(launchOptions)
appBoyInstance?.appboyOptions = [
ABKInAppMessageControllerDelegateKey: strongSelf,
ABKURLDelegateKey: strongSelf,
ABKMinimumTriggerTimeIntervalKey: 5
]
let configuration = Analytics.configuredClient(withWriteKey: writeKey)

if let appBoyInstance = SEGAppboyIntegrationFactory.instance() {
configuration.use(appBoyInstance)
appBoyInstance.saveLaunchOptions(launchOptions)
appBoyInstance.appboyOptions = [
ABKInAppMessageControllerDelegateKey: strongSelf,
ABKURLDelegateKey: strongSelf,
ABKMinimumTriggerTimeIntervalKey: 5
]
}

Analytics.setup(with: configuration)

AppEnvironment.current.ksrAnalytics.configureSegmentClient(Analytics.shared())
}

Expand Down Expand Up @@ -460,10 +462,18 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
}

func userNotificationCenter(
_: UNUserNotificationCenter,
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completion: @escaping () -> Void
) {
// Track notification opened.
// Documentation: https://github.com/Appboy/appboy-segment-ios/blob/master/CHANGELOG.md#added-6.
let appBoyHelper = SEGAppboyIntegrationFactory.instance().appboyHelper
if Appboy.sharedInstance() == nil {
appBoyHelper?.save(center, notificationResponse: response)
}
appBoyHelper?.userNotificationCenter(center, receivedNotificationResponse: response)

guard let rootTabBarController = self.rootTabBarController else {
completion()
return
Expand Down
18 changes: 3 additions & 15 deletions Library/Tracking/Segment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,11 @@ public extension Analytics {
/**
Returns an `Analytics` and `SEGAppboyIntegrationFactory` instance, with Segment, using an `AnalyticsConfiguration`.
*/
static func configuredClient(withWriteKey writeKey: String)
-> (AnalyticsConfiguration, SEGAppboyIntegrationFactory?) {
static func configuredClient(withWriteKey writeKey: String) -> AnalyticsConfiguration {
let configuration = AnalyticsConfiguration(writeKey: writeKey)
configuration
.trackApplicationLifecycleEvents = true

configuration.trackApplicationLifecycleEvents = true
configuration.sourceMiddleware = [BrazeDebounceMiddleware()]
// Braze is always configured but feature-flagged elsewhere.
// Data sent to Braze is feature-flagged by the enabling/disabling Segment.
// FIXME: For some reason this instance of SEGAppyboyIntegrationFactory is not the same as one passed in. It's supposed to be the same singleton.
guard let factoryInstance = SEGAppboyIntegrationFactory.instance() else {
return (configuration, nil)
}

configuration.use(factoryInstance)

return (configuration, factoryInstance)
return configuration
}
}

Expand Down