Leanplum

Sending Location Engine SDK Events to Leanplum

Leanplum is a mobile engagement platform that helps forward-looking brands meet the real-time needs of their customers. By transforming data into an understanding of users’ needs and wants, Leanplum delivers unified experiences that are timely, tested, and relevant. The Factual Engine SDK can be paired with Leanplum to help understand users in the physical world and to build personalized experiences driving user engagement and revenue. The steps below illustrate the simplicity of integrating the two services.


Prerequisites

This document assumes an understanding of Leanplum platform. For background please review:

🚧

Jump to platform-specific instructions


Android

Before following the steps below please review:


1: Include the Leanplum SDK

After upgrading your gradle file following Leanplum's documentation, include the leanplum-core library

dependencies {
    // Existing dependencies 
    ....

    // Engine Library
    implementation 'com.factual:engine-sdk:[ENGINE_VERSION]'

    // Leanplum Library
    implementation 'com.leanplum:leanplum-core:[LEANPLUM_VERSION]'
}

2: Setup and start the Leanplum SDK

Initialize the Leanplum SDK following Leanplum's documentation

...
  
public class MainActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    // Setup Leanplum
    if (BuildConfig.DEBUG) {
      Leanplum.setAppIdForDevelopmentMode("Your App ID", "Your Development Key");
    } else {
      Leanplum.setAppIdForProductionMode("Your App ID", "Your Production Key");
    }
    
    // Start Leanplum
    Leanplum.start(this);
    
    // Setup Engine
    ...
  }
  
...

3: Create a callback to handle circumstance met events

In the below example an event is sent to Leanplum when a circumstance has been met. The track method also includes the circumstance name.

public class LeanplumFactualClientReceiver extends FactualClientReceiver {
  
  @Override
  public void onCircumstancesMet(List<CircumstanceResponse> responses) {
    for (CircumstanceResponse circumstanceResponse : responses) {
      Log.e("engine", "tracking circumstances");
      Leanplum.track(
          "circumstance_met",
          circumstanceResponse.getCircumstance().getName());
    }
  }
}

4: Register your client receiver

Follow the guidance from the Android Docs

...
FactualEngine.initialize(
  this,
  "YOUR_API_KEY",
  LeanplumFactualClientReceiver.class);
...

5: Verify your data

When a circumstance is met the onCircumstancesMet will be called. Once an event has been tracked it is available immediately for use in Leanplum's dashboard.


iOS

Before following the steps below please review:

1: Include the Leanplum SDK

Install the FactualEngineSDK and Leanplum-iOS-SDK SDKs via Cocoapods

source 'https://github.com/Factual/cocoapods.git'
source 'https://github.com/CocoaPods/Specs.git'

use_frameworks!

target 'EngineLeanplumExample' do
  pod 'FactualEngineSDK'
  pod 'Leanplum-iOS-SDK', '2.3.0'
end

2: Setup the SDK

Initialize the Leanplum SDK with proper credentials following Leanplum's documentation

#import "AppDelegate.h"
#import <Leanplum/Leanplum.h>

@interface AppDelegate ()
@property CLLocationManager *manager; // Engine assumes you are managing location permissions

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // for demonstration, we're requesting location permissions here:
    if (_manager == nil) {
        _manager = [[CLLocationManager alloc] init];
    }
    [_manager requestAlwaysAuthorization];
    
    // Start the Engine SDK.
    [FactualEngine startWithApiKey:@"FACTUAL_API_KEY"
                          delegate:self]; // FactualEngineDelegate
    
    // Start the Leanplum SDK
    #ifdef DEBUG
      LEANPLUM_USE_ADVERTISING_ID;
      [Leanplum setAppId:@"APP_ID"
      withDevelopmentKey:@"DEV_KEY"];
    #else
      [Leanplum setAppId:@"APP_ID"
      withProductionKey:@"PROD_KEY"];
    #endif
    [Leanplum start];
    
    
    return YES;
}

 


3: Create a callback to handle circumstance met events

In the circumstancesDidOccur callback of your FactualEngineDelegate, call the track method to send an event to Leanplum

- (void)circumstancesMet:(NSArray<CircumstanceResponse *> *)circumstances{
    for (CircumstanceResponse *myCircumstance in circumstances){
        NSLog(@"Engine circumstance triggered action: %@", [[myCircumstance circumstance] actionId]);
        [Leanplum track:@"circumstance_met" withInfo:[[myCircumstance circumstance] name]];
    }
}

4: Verify your data

Once an event has been tracked it is available for immediate use in Leanplum's dashboard.