Skip to content

Managing Pulsate Sessions

To start a session, call either startPulsateSession (anonymous) or startPulsateSession(forAlias:) (identified). Both are described below.

Once you start the first session, Pulsate automatically starts and ends sessions for you (sessions begin when the app foregrounds and end when it backgrounds). Sessions are managed automatically until you log the user out.

1. Anonymous session — startPulsateSession

Section titled “1. Anonymous session — startPulsateSession”

An anonymous session uses a Device GUID to identify the user on this device. Whenever the Device GUID changes, a new user is created and the old user’s data can no longer be connected to the new user.

If the user has multiple devices, the same person appears as a different user per device. The Device GUID can also change if the user reinstalls the app, resets their device, or clears app data.

pulsateManager.startPulsateSession { success, error in
if let error = error {
print("Session failed: \(error)")
}
}

2. Identified session — startPulsateSession(forAlias:)

Section titled “2. Identified session — startPulsateSession(forAlias:)”

Deduping sets a unique identifier as the customer’s alias so Pulsate recognizes the same user across multiple devices. This improves data quality by attaching multiple devices to a single profile instead of creating a separate profile per device.

Choose an alias that won’t change for the user — a customer number is a good candidate. An email address is a poor choice because it can change.

Pass the unique identifier to startPulsateSession(forAlias:). An empty alias fails the listener.

pulsateManager.startPulsateSession(forAlias: uniqueIdentifier) { success, error in
if let error = error {
print("Session failed: \(error)")
}
}

You can delay starting the session — for example, until the user logs into your app — so only logged-in users are added to Pulsate and receive content.

import PULPulsate
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
do {
let authData = try PULAuthorizationData(
withAppId: "YOUR_SDK_APP_ID",
andAppKey: "YOUR_SDK_APP_KEY")
let pulsateManager = try PULPulsateFactory.getInstance(
withAuthorizationData: authData,
withLaunchOptions: launchOptions)
if userLoggedIn {
pulsateManager.startPulsateSession { _, _ in }
}
} catch {
print(error)
}
return true
}
}

When a user logs out of your app, call logout to stop sending data and receiving campaigns for that user.

pulsateManager.logout { success, error in
if let error = error {
print("Logout failed: \(error)")
}
}