Kits

Although the majority of mParticle event integrations are entirely server-side, the mParticle SDK does do some client-side data forwarding. The mParticle SDK works with latest versions of these kits, but just as with other integrations, you are not required to write any client-side code to leverage them. As with other integrations, you should enable and configure the kits listed below on the Services page for your application.

Refer to the iOS and Android SDK GitHub repositories for configuring these kits with the mParticle SDK into your app.

Kits are not currently available for tvOS.

Making direct calls to Kits

If you need to access or use a kit method or functionality not covered by the mParticle SDK, you can obtain the respective internal instance by calling the kitInstance method, passing an enum with the instance you are interested. The method will return the instance in question, or nil/null if the kit is not active.

For the cases where a kit is implemented with class methods, you can call those class methods directly.

#import <AppboyKit.h>

- (void)refreshFeed {
    Appboy *appboy = [[MParticle sharedInstance] kitInstance:MPKitInstanceAppboy];
    if (appboy) {
        [appboy requestFeedRefresh];
    }
}

The mParticle SDK only instantiates kits that are configured for your app. Since services can be turned on and off dynamically, if you need to access a kit API directly, you must make sure that the given service is currently active.

You can also verify at any given moment if a kit is active and enabled to be used in your app.

if ([[MParticle sharedInstance] isKitActive:MPKitInstanceAppboy]) {
    // Do something
}

Kit Availability and Unavailability Notifications

The mParticle SDK also allows you to listen for notifications asynchronously, avoiding the need to repeatedly check if a kit is active or inactive.

- (void)awakeFromNib {
    [super awakeFromNib];

    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
    [notificationCenter addObserver:self
                           selector:@selector(handleKitDidBecomeActive:)
                               name:mParticleKitDidBecomeActiveNotification
                             object:nil];

    [notificationCenter addObserver:self
                           selector:@selector(handleKitDidBecomeInactive:)
                               name:mParticleKitDidBecomeInactiveNotification
                             object:nil];
}

- (void)dealloc {
    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
    [notificationCenter removeObserver:self
                                  name:mParticleKitDidBecomeActiveNotification
                                object:nil];

    [notificationCenter removeObserver:self
                                  name:mParticleKitDidBecomeInactiveNotification
                                object:nil];
}

- (void)handleKitDidBecomeActive:(NSNotification *)notification {
    NSDictionary *userInfo = [notification userInfo];
    NSNumber *kitNumber = userInfo[mParticleKitInstanceKey];
    MPKitInstance kitInstance = (MPKitInstance)[kitNumber integerValue];

    if (kitInstance == MPKitInstanceAppboy) {
        NSLog(@"Appboy is available for use.");
    }
}

- (void)handleKitDidBecomeInactive:(NSNotification *)notification {
    NSDictionary *userInfo = [notification userInfo];
    NSNumber *kitNumber = userInfo[mParticleKitInstanceKey];
    MPKitInstance kitInstance = (MPKitInstance)[kitNumber integerValue];

    if (kitInstance == MPKitInstanceAppboy) {
        NSLog(@"Appboy is unavailable for use.");
    }
}

Deep Linking

Several integrations support the creation and attribution of deep links to install and open an app. A deep link will typically contain some additional information to be used when the user ultimately opens your application, so that you can properly route the user to the appropriate content, or otherwise customize their experience.

As at version 7, the mParticle SDKs offer an integration-agnostic Attribution Listener API that lets you query your integrations at runtime to determine if the given user arrived by way of a deep link.

The following integrations support deep linking:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    MParticleOptions *options = [MParticleOptions optionsWithKey:@"<<Your app key>>" secret:@"<<Your app secret>>"];
    options.onAttributionComplete = ^void (MPAttributionResult *_Nullable attributionResult, NSError * _Nullable error) {
        if (error) {
            NSLog(@"Attribution fetching for kitCode=%@ failed with error=%@", error.userInfo[mParticleKitInstanceKey], error);
            return;
        }

        NSLog(@"Attribution fetching for kitCode=%@ completed with linkInfo: %@", attributionResult.kitCode, attributionResult.linkInfo);

    }
    [[MParticle sharedInstance] startWithOptions:options];

    return YES;
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let mParticleOptions = MParticleOptions(key: "<<<App Key Here>>>", secret: "<<<App Secret Here>>>")
    
    mParticleOptions.onAttributionComplete = { (attributionResult, error) in
        if (error != nil) {
            NSLog("Attribution fetching for kitCode=%@ failed with error=%@", error?._userInfo?[mParticleKitInstanceKey] as? CVarArg ?? "null", error ?? "null");
            return;
        }
        
        NSLog("Attribution fetching for kitCode=%@ completed with linkInfo: %@", attributionResult?.kitCode ?? "null", attributionResult?.linkInfo ?? "null");
    }
    
    MParticle.sharedInstance().start(with: mParticleOptions)
    
    return true
}