To start a session all that you need to do is call "startPulsateSession" or "startPulsateSessionForAlias". Below we will explain both methods and what is different.

Pulsate automatically starts and ends sessions for you after you start the first session. The sessions will be automatically managed for you until you logout the user from Pulsate. If you do not need to logout the user don't do it.

1. Simple Session - startPulsateSession

Simple Sessions use a "Device Guid" to identify this user on this device. Everytime "Device Guid" changes a new user is created and the old user data can no longer be connected to the new user.
If the user has multiple devices or updates his current device each device will have a different "Device Guid" and will be a different user in our system. "Device Guid" can also change if the user reinstalls the App, formats his device or clears App Data.

In order to start a simple session use the startPulsateSession: method.

NSError* error;

PULAuthorizationData* authData = [[PULAuthorizationData alloc] initWithAppId:@"YOUR_SDK_APP_ID" andAppKey:@"YOUR_SDK_APP_KEY" validationError:&error];
    
PULPulsateManageer* pulsateManager = [PULPulsateFactory getInstanceWithAuthorizationData:authData andLocationEnabled:YES withPushEnabled:YES withLaunchOptions:launchOptions error:&error];

[pulsateManager startPulsateSession:^(BOOL success, NSError* error) {}];
let authData: PULAuthorizationData = try PULAuthorizationData(appId: "SDK_APP_ID", andAppKey: "SDK_APP_KEY");

let pulsateManager = try PULPulsateFactory.getInstanceWith(authData, withLocationEnabled: true, withPushEnabled: true, withLaunchOptions: launchOptions, withPulsateAppDelegate: true);
        
pulsateManager.startPulsateSession()

2. Deduping Session - startPulsateSessionForAlias

Deduping is the process of setting a unique identifier for a user as their customer alias so that we can recognise when that user uses your app on multiple devices. Deduping helps to improve data quality by ensuring that the same user can have multiple devices added to their profile instead of different Pulsate profiles being created for each device.

The customer alias can be any identifier that you choose that will not change for that user. Customer Number is an example of a suitable identifier that would make a good alias because customer number is a parameter that is unlikely to change. Conversely, an email address is not a good choice as an identifier because there is a strong possibility that a user could change their email in the future.

In order to use the deduping feature, you need to use the startPulsateSessionForAlias: method, instead of startPulsateSession on the PulsateManager. You need to pass the unique client identifier as the parameter.

NSError* error;

PULAuthorizationData* authData = [[PULAuthorizationData alloc] initWithAppId:@"YOUR_SDK_APP_ID" andAppKey:@"YOUR_SDK_APP_KEY" validationError:&error];
    
PULPulsateManageer* pulsateManager = [PULPulsateFactory getInstanceWithAuthorizationData:authData andLocationEnabled:YES withPushEnabled:YES withLaunchOptions:launchOptions error:&error];

[pulsateManager startPulsateSessionForAlias:uniqueIdentifier withListener:^(BOOL success, NSError* error) {}];
let authData: PULAuthorizationData = try PULAuthorizationData(appId: "SDK_APP_ID", andAppKey: "SDK_APP_KEY");

let pulsateManager = try PULPulsateFactory.getInstanceWith(authData, withLocationEnabled: true, withPushEnabled: true, withLaunchOptions: launchOptions, withPulsateAppDelegate: true);
        
pulsateManager.startPulsateSessionForAlias(uniqueIdentifier)

3. Delaying Sessions

You can delay the startPulsateSession method call. For example, you can call it after the user successfully logins into your app so that only users that successfully log into your app are added to Pulsate and receive content from Pulsate. Here is an example of how to delay startPulsateSession until after the user has logged in:

The startPulsateSession method starts the session lifecycle and remote notifications, location if passed in parameters as YES.

If you delay the Pulsate Session make sure that "startPulsateSession" is still called in your application:didFinishLaunchingWithOptions method after the first session delay.

In the example below we delay the first session until the user logs in, after the first log the "startPulsateSession" will be called every time the application:didFinishLaunchingWithOptions method gets called by the system.

#import <PULPulsate/PULPulsate.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSError* error;

		PULAuthorizationData* authData = [[PULAuthorizationData alloc] initWithAppId:@"YOUR_SDK_APP_ID" andAppKey:@"YOUR_SDK_APP_KEY" validationError:&error];
    
    PULPulsateManager* pulsateManager = [PULPulsateFactory getInstanceWithAuthorizationData:authData withLocationEnabled:YES withPushEnabled:YES withLaunchOptions:launchOptions error:&error];

    if (userLoggedIn == YES)
			[_pulsateManager startPulsateSession:^(BOOL success, NSError* error) {}];
   
    return YES;
}


@end
import PULPulsate

class AppDelegate {

	  func application(_ application: UIApplication, 
    didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
    {
        do
        {
            let authData: PULAuthorizationData = try PULAuthorizationData(appId: "SDK_APP_ID", andAppKey: "SDK_APP_KEY");
      
            let pulsateManager = try PULPulsateFactory.getInstanceWith(authData,
            withLocationEnabled: true, withPushEnabled: true, 
            withLaunchOptions: launchOptions, withPulsateAppDelegate: true);
      
            if (userLoggedIn)
                pulsateManager.startPulsateSession();
        } catch {
    	      print(error);
        }
        return true;
    }
}

4. Logout

If your user logs out, in order for him to stop sending data and getting new campaigns you need to call the logoutCurrentAlias method.

Pulsate automatically starts and ends sessions for you after you start the first session. The sessions will be automatically managed for you until you logout the user from Pulsate. If you do not need to logout the user don't do it.

❗️

Logout prevents users from receiving Pulsate Campaigns

If you use the Pulsate Logout functionality, the User will no longer receive any Pulsate Campaigns or Journeys to their device, including Push Notifications. Logging a User out will also prevent the Pulsate SDK from sending other Events to Pulsate that may trigger a Campaign or Journey, such as GeoFence or Beacon events. If you wish for your User's to continue receiving Campaigns or Journeys to their device, do not call Logout.

[pulsateManager logout:^(BOOL success, NSError* error) {}];
pulsateManager?.logout({(success, error) in });