The “Conversion” feature enables you to measure user interactions with beacons and campaigns. With this feature you can track the following informations:

  • how many users were around the beacon region
  • how many campaigns were delivered to the app
  • how many campaign actions were performed by users

The “action” property in PCMCampaignAction

This “action” property is a unique id to report conversion information.

@interface PCMCampaignAction : NSObject
...
// action : unique action fire event identifier
@property (strong, nonatomic) NSString      *action;
@end

When you receive an “PCEventPerformAction” event from the SDK, it will contain an ‘PCMCampaignAction’ object. Now you can use new ‘action’ parameter to report this conversion through ‘PCManager’

Currently we have following 4 conversion types

/**
 PCConversionType
 Represents the conversion type for a specific campaign action
 @since 2.1.2
 */
typedef enum : NSUInteger {
    /**
     *  The campaign action can't "fire" (ex. the user has denied access to local notifications)
     */
    kPCConversionUnavailable = -2,
    /**
     *  The campaign was suppressed by the app
     */
    kPCConversionSuppressed = -1,
    /**
     *  The campaign action has been "fired" but was ignored by the user
     *
     * @discussion: The campaigns are marked as "ignored" by default. To correctly measure conversion, be sure to call [PCManager sharedManager] reportConversion: forCampaignAction:] when performing the campaign action
     */
    kPCConversionIgnored = 0,
    /**
     *  The campaign action has been performed successfully
     */
    kPCConversionSuccessful = 1
} PCConversionType;

Example for kPCConversionSuccessful : When user has interacted with the notification

Create custom method that will handle local notification response. Pass information during interaction with push and alert notification.

ObjC :

// fallback on earlier versions (iOS 9.0)
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    if (notification.userInfo) {
        NSDictionary *dict = [notification.userInfo valueForKey:@"action"];
        PCMCampaignAction *action = [PCUtilities campaignActionFromDictionary:dict];
        if (action)
        {
	        [[PCManager sharedManager] reportConversion:kPCConversionSuccessful forCampaignAction:[action.action copy]];
    }
   }
}

Swift :

func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {

     if ((notification.userInfo) != nil) {  
        let dict = notification.userInfo!["action"]
        let action = PCUtilities.campaignAction(from: dict as! [AnyHashable : Any])

        if ((action) != nil) {
            PCManager.shared().report(PCConversionType.successful, forCampaignAction: action?.action)
        }
    }
}

ObjC :

- (void)takeActionWithLocalNotification:(UNNotification *)localNotification {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:localNotification.request.content.title
                                                                             message:localNotification.request.content.body
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"Ok"
                                                 style:UIAlertActionStyleDefault
                                               handler:^(UIAlertAction * _Nonnull action) {
                                                   // check if user saw this notification
                                               }];
    
    [alertController addAction:ok];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:alertController animated:YES completion:^{
            if (localNotification.request.content.userInfo) {
                NSDictionary *dict = [localNotification.request.content.userInfo valueForKey:@"action"];
                
                PCMCampaignAction *action = [PCUtilities campaignActionFromDictionary:dict];
                if (action) {
                    [[PCManager sharedManager] reportConversion:kPCConversionSuccessful forCampaignAction:[action.action copy]];
                }
            }
        }];
    });
}

Swift :

func takeActionWithLocalNotification(_ localNotification: UNNotification) {
        
        let alert: UIAlertController = UIAlertController(title: localNotification.request.content.title,
                                                         message: localNotification.request.content.body,
                                                         preferredStyle: .alert)
        
        alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { _ in
            alert.dismiss(animated: true, completion: nil)
            // check if user saw this notification
        }))
        
        present(alert, animated: true, completion: nil)
        // action
        if ((localNotification.request.content.userInfo) != nil) {  
            let dict = notification.userInfo["action"]
            let action = PCUtilities.campaignAction(from: dict as! [AnyHashable : Any])
     }
        if ((action) != nil) {
            PCManager.shared().report(PCConversionType.successful, forCampaignAction: action?.action)
        }
    }

ObjC :

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(nonnull void (^)(UNNotificationPresentationOptions))completionHandler {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Notification alert!"
                                                                             message:@"This app just sent you a notification, do you want to see it?"
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *ignore = [UIAlertAction actionWithTitle:@"Ignore"
                                                     style:UIAlertActionStyleDefault
                                                   handler:^(UIAlertAction * _Nonnull action) {
                                                       // check if user decided to ignore notification
                                                   }];
    
    UIAlertAction *view = [UIAlertAction actionWithTitle:@"See"
                                                   style:UIAlertActionStyleDefault
                                                 handler:^(UIAlertAction * _Nonnull action) {
                                                     [self takeActionWithLocalNotification:notification];
                                                 }];
    [alertController addAction:ignore];
    [alertController addAction:view];
    
    
    [self presentViewController:alertController animated:YES completion:^{
    }];
}

Swift :

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    
    let alert: UIAlertController = UIAlertController(title: "Notification Alert!", message: "This app just sent you a notification, do you want to see it?", preferredStyle: .alert)
    
    let ignore = UIAlertAction(title: "Ignore", style: .default, handler: { _ in
        alert.dismiss(animated: true, completion: nil)
        // check if user decided to ignore notification
        completion()
    })
    
    alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { _ in
    alert.dismiss(animated: true, completion: nil)
    }))
    
    alert.addAction(ignore)
    
    present(alert, animated: true, completion: nil)
}

ObjC :

-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(nonnull UNNotificationResponse *)response withCompletionHandler:(nonnull void (^)(void))completionHandler {
    [self takeActionWithLocalNotification:response.notification];
}

Swift :

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    self.takeActionWithLocalNotification(response.notification)
}

Example for kPCConversionUnavailable : when the user cannot be notified.

ObjC :

SUBSCRIBE(PCEventPerformAction)
{
	if (![[PCManager sharedManager] canReceiveNotifications])
    {
        [[PCManager sharedManager] reportConversion:kPCConversionUnavailable forCampaignAction:[action.action copy]];
    }
    else
    {
	    // schedule notification
   }
}

Swift :

func onPCEventPerformAction(event:PCEventPerformAction) {
    if (!PCManager.shared().canReceiveNotifications()) {
        PCManager.shared().report(PCConversionType.unavailable, forCampaignAction: event.campaign.action)
    } else {
        // schedule notification
    }
}

In this case you can also show an alert and let your customer decide whether to perform an action or not.

Default Conversion value for campaign action is “ignored” (kPCConversionIgnored) - we overwrite conversion value when you report conversion through

ObjC :

[[PCManager sharedManager] reportConversionPCConversionType forCampaignAction:action];

Swift :

PCManager.shared().report(PCConversionType, forCampaignAction:action)