braze-inc / braze-cordova-sdk

Public repo for the Braze Cordova SDK
https://www.braze.com
Other
21 stars 63 forks source link

iOS > Direct Opens not logging #72

Closed KirstenStake closed 3 years ago

KirstenStake commented 3 years ago

We are trying to send a push notification which links to a web page when the user clicks the push. However, on iOS this linking is not working.

Upon investigating within the dashboard we realised that for iOS the direct opens are not logging either. Is this related to the above issue?

Screen Shot 2021-09-16 at 3 10 45 pm

As a summary, the issues are:

  1. Direct opens not logging for iOS
  2. When iOS user clicks the push (which has a web page linked to redirect to) it is not re-directing user to the web link.
Bucimis commented 3 years ago

@KirstenStake this should be related. Are you integrating push on iOS via our automatic integration or a manual integration (you can check the value of your com.appboy.ios_disable_automatic_push_registration flag in config.xml to confirm.

If deep links and direct opens are not working, the push delegates that send push lifecycle events to Braze are probably not working, either because the user notifications delegate wasn't set properly or they aren't implemented.

KirstenStake commented 3 years ago

@Bucimis thanks for your quick reply!

This is our setup around the plugin:

Bucimis commented 3 years ago

@KirstenStake are you using any other plugins that implement iOS push, such as Firebase?

KirstenStake commented 3 years ago

@Bucimis No, no other push plugins.

For reference the code that was added for custom prompt for push function was this (in case you can see something that might be missing to register or set up something)

- (void)promptForPush:(CDVInvokedUrlCommand *)command {
  UIUserNotificationType notificationSettingTypes = (UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound);
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) {
      UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
      // If the delegate hasn't been set yet, set it here in the plugin
      // if (center.delegate == nil) {
      //   center.delegate = [UIApplication sharedApplication].delegate;
      // }
      UNAuthorizationOptions options = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
      if (@available(iOS 12.0, *)) {
        // options = options | UNAuthorizationOptionProvisional;
      }
      [center requestAuthorizationWithOptions:options
                            completionHandler:^(BOOL granted, NSError *_Nullable error) {
                              NSLog(@"Permission granted.");
                              NSLog(@"Permission granted.");
                              [[Appboy sharedInstance] pushAuthorizationFromUserNotificationCenter:granted];
                            }];
      [[UIApplication sharedApplication] registerForRemoteNotifications];
      NSString* callbackId = command.callbackId;
      NSString* packageName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
      CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:packageName];
      [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
    } else if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) {
      UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationSettingTypes categories:nil];
      [[UIApplication sharedApplication] registerForRemoteNotifications];
      [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    } else {
      [[UIApplication sharedApplication] registerForRemoteNotificationTypes: notificationSettingTypes];
    }
  }

And the three functions we use in the app for ay linkage to appboy plugin are:

Our target SDK is 12.

There are some warnings in xCode during build for AppBoy plugin, will paste them here in case anything stands out?

Screen Shot 2021-09-22 at 6 36 41 pm

Bucimis commented 3 years ago

@KirstenStake that delegate code that is commented out is likely causing issues. You need to set the UNUserNotificationCenter delegate using center.delegate = <your-delegate-instance-here> to receive lifecycle events. Your delegate instance needs to implement UNUserNotificationCenter delegate methods and pass those to Braze. See https://github.com/Appboy/appboy-ios-sdk/blob/41de83d15a755af3819287b06d4efc0ec855792a/HelloSwift/HelloSwift/AppDelegate.swift#L48 for an example

Bucimis commented 3 years ago

closing due to inactivity + I believe ^ is the correct solution

KirstenStake commented 3 years ago

@Bucimis sorry for the delay, I only just got round to uncommenting out the code you mentioned might be the cause.

However, even after doing that, it is still an issue. To summarise, still experiencing the issue of:

Screen Shot 2021-10-28 at 1 15 59 pm

With the deep linking, clicking a push DOES open our app, however it does not navigate to the desired page.

Are you able to provide an example of how this journey would look to set up? Specifically, the setting of a deep link in the dashboard (the screenshot section). How does the app actually know how to redirect to the desired page as there is no code I can see which is doing so?

We also have this set to true in our config:

      'com.appboy.api_key': XXX,
      'com.appboy.firebase_cloud_messaging_registration_enabled': 'true',
      'com.appboy.android_handle_push_deep_links_automatically': 'true',
      'com.appboy.android_small_notification_icon': 'ic_stat_name',
      'com.appboy.android_large_notification_icon': 'ic_stat_name',
      'com.appboy.android_notification_accent_color': '#F6443A',
      'com.appboy.android_api_endpoint': XXX
      'com.appboy.android_fcm_sender_id': XXX,
      'com.appboy.android_default_session_timeout': 'str_5',
      'com.appboy.android_log_level': '0',
      'com.appboy.ios_disable_automatic_push_registration': 'NO',
      'com.appboy.ios_enable_idfa_automatic_collection': 'NO',
      'com.appboy.ios_api_endpoint': XXX
Bucimis commented 3 years ago

Hi @KirstenStake, did you also

  1. Set up your UserNotificationCenter delegate method https://github.com/Appboy/appboy-ios-sdk/blob/41de83d15a755af3819287b06d4efc0ec855792a/HelloSwift/HelloSwift/AppDelegate.swift#L52
  2. Set your UserNotificationCenter delegate to the class you implemented the methods in? https://github.com/Appboy/appboy-ios-sdk/blob/41de83d15a755af3819287b06d4efc0ec855792a/HelloSwift/HelloSwift/AppDelegate.swift#L29

The calls to Appboy (e.g. Appboy.sharedInstance()!.userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler)) are where the contents of the push notification get sent to the SDK for further processing. Inside those methods, Braze handles deep links using the iOS open function (https://developer.apple.com/documentation/uikit/uiapplication/1648685-open)

KirstenStake commented 3 years ago

hi @Bucimis thank you for the guidance. i really appreciate this!

I did not have the above two steps implemented. However, even after implementation, it is still not working. (no direct opens recorded and no deep link navigation triggered)

  1. Have added this function func userNotificationCenter to AppDelegate.swift

  2. Added code section to func application, which results in function looking like so:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let center = UNUserNotificationCenter.current()
    var options: UNAuthorizationOptions = [.alert, .sound, .badge]
    if #available(iOS 12.0, *) {
      options = UNAuthorizationOptions(rawValue: options.rawValue | UNAuthorizationOptions.provisional.rawValue)
    }
    center.requestAuthorization(options: options) { (granted, error) in
      Appboy.sharedInstance()?.pushAuthorization(fromUserNotificationCenter: granted)
    }
    center.delegate = self
    center.setNotificationCategories(ABKPushUtils.getAppboyUNNotificationCategorySet())
    UIApplication.shared.registerForRemoteNotifications()
    
    // enable pasteboard check  
    Branch.getInstance().checkPasteboardOnInstall()
    
    // Override point for customization after application launch.
    Branch.getInstance().initSession(launchOptions: launchOptions)
    
    return true
    }

Push notification opens the app, but no re-directs happen via deep linking and direct opens not logged. (if it helps, same deep link was used for Android and deep. link navigation occurs (except if app is in background, but that's a whole other can of worms)