{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","settings":"","results":{"codes":[]},"params":[]},"next":{"description":"","pages":[]},"title":"Managing Pulsate Sessions","type":"basic","slug":"managing-pulsate-sessions","excerpt":"","body":"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.\n\nPulsate 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.\n[block:api-header]\n{\n  \"title\": \"1. Simple Session - startPulsateSession\"\n}\n[/block]\nSimple 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. \nIf 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.\n\nIn order to start a simple session use the *startPulsateSession:* method.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"NSError* error;\\n\\nPULAuthorizationData* authData = [[PULAuthorizationData alloc] initWithAppId::::at:::\\\"YOUR_SDK_APP_ID\\\" andAppKey:@\\\"YOUR_SDK_APP_KEY\\\" validationError:&error];\\n    \\nPULPulsateManageer* pulsateManager = [PULPulsateFactory getInstanceWithAuthorizationData:authData andLocationEnabled:YES withPushEnabled:YES withLaunchOptions:launchOptions error:&error];\\n\\n[pulsateManager startPulsateSession:^(BOOL success, NSError* error) {}];\\n    \",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let authData: PULAuthorizationData = try PULAuthorizationData(appId: \\\"SDK_APP_ID\\\", andAppKey: \\\"SDK_APP_KEY\\\");\\n\\nlet pulsateManager = try PULPulsateFactory.getInstanceWith(authData, withLocationEnabled: true, withPushEnabled: true, withLaunchOptions: launchOptions, withPulsateAppDelegate: true);\\n        \\npulsateManager.startPulsateSession()\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"2. Deduping Session - startPulsateSessionForAlias\"\n}\n[/block]\nDeduping 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. \n\nThe 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.\n\nIn 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.\n\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"NSError* error;\\n\\nPULAuthorizationData* authData = [[PULAuthorizationData alloc] initWithAppId:@\\\"YOUR_SDK_APP_ID\\\" andAppKey:@\\\"YOUR_SDK_APP_KEY\\\" validationError:&error];\\n    \\nPULPulsateManageer* pulsateManager = [PULPulsateFactory getInstanceWithAuthorizationData:authData andLocationEnabled:YES withPushEnabled:YES withLaunchOptions:launchOptions error:&error];\\n\\n[pulsateManager startPulsateSessionForAlias:uniqueIdentifier withListener:^(BOOL success, NSError* error) {}];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let authData: PULAuthorizationData = try PULAuthorizationData(appId: \\\"SDK_APP_ID\\\", andAppKey: \\\"SDK_APP_KEY\\\");\\n\\nlet pulsateManager = try PULPulsateFactory.getInstanceWith(authData, withLocationEnabled: true, withPushEnabled: true, withLaunchOptions: launchOptions, withPulsateAppDelegate: true);\\n        \\npulsateManager.startPulsateSessionForAlias(uniqueIdentifier)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"3. Delaying Sessions\"\n}\n[/block]\nYou 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:\n\nThe *startPulsateSession* method starts the session lifecycle and remote notifications, location if passed in parameters as *YES*. \n\nIf you delay the Pulsate Session make sure that *\"startPulsateSession\"* is still called in your *application:didFinishLaunchingWithOptions* method after the first session delay. \n\nIn 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.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#import <PULPulsate/PULPulsate.h>\\n\\[email protected] AppDelegate\\n\\n- (BOOL)application:(UIApplication *)application\\n  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\\n    NSError* error;\\n\\n\\t\\tPULAuthorizationData* authData = [[PULAuthorizationData alloc] initWithAppId:@\\\"YOUR_SDK_APP_ID\\\" andAppKey:@\\\"YOUR_SDK_APP_KEY\\\" validationError:&error];\\n    \\n    PULPulsateManager* pulsateManager = [PULPulsateFactory getInstanceWithAuthorizationData:authData withLocationEnabled:YES withPushEnabled:YES withLaunchOptions:launchOptions error:&error];\\n\\n    if (userLoggedIn == YES)\\n\\t\\t\\t[_pulsateManager startPulsateSession:^(BOOL success, NSError* error) {}];\\n   \\n    return YES;\\n}\\n\\n\\[email protected]\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import PULPulsate\\n\\nclass AppDelegate {\\n\\n\\t  func application(_ application: UIApplication, \\n    didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool\\n    {\\n        do\\n        {\\n            let authData: PULAuthorizationData = try PULAuthorizationData(appId: \\\"SDK_APP_ID\\\", andAppKey: \\\"SDK_APP_KEY\\\");\\n      \\n            let pulsateManager = try PULPulsateFactory.getInstanceWith(authData,\\n            withLocationEnabled: true, withPushEnabled: true, \\n            withLaunchOptions: launchOptions, withPulsateAppDelegate: true);\\n      \\n            if (userLoggedIn)\\n                pulsateManager.startPulsateSession();\\n        } catch {\\n    \\t      print(error);\\n        }\\n        return true;\\n    }\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"4. Logout\"\n}\n[/block]\nIf your user logs out, in order for him to stop sending data and getting new campaigns you need to call the *logoutCurrentAlias* method.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[pulsateManager logout:^(BOOL success, NSError* error) {}];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"pulsateManager?.logout({(success, error) in });\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]","updates":[],"order":2,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5f46379f2955060f4ab2e566","createdAt":"2020-08-26T10:21:19.542Z","user":"57bc3654b9c7f0220009c77b","category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"SDK Quick Start","slug":"sdk-quick-start","order":1,"from_sync":false,"reference":false,"_id":"5f44d1fbd1c58d040fdf03ba","createdAt":"2020-08-25T08:55:23.033Z","version":"5e5013741b3b20006532951d","project":"54aa7f773b56130b0056c86e","__v":0},"version":{"version":"2.7","version_clean":"2.7.0","codename":"iOS SDK","is_stable":false,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["5e5013741b3b200065329486","55781fe35129590d003ff4f9","55781fe35129590d003ff4fa","5e5013741b3b200065329487","5e5013741b3b200065329488","5e5013741b3b200065329489","5e5013741b3b20006532948a","5e5013741b3b20006532948b","565b66c446118c0d00dcb0bb","56898269f8dc340d00308c13","5e5013741b3b20006532948c","5e5013741b3b20006532948d","5c73dd27e8fdc000572a206a","5e5013741b3b20006532948e","5e53d9a2f75c0b0020de8935","5f44d1fbd1c58d040fdf03ba","5f44d202a2e3eb02b1c4c806","5f44d209703f05006a2a4fa9","5f44d210b1ba9f004200b689"],"_id":"5e5013741b3b20006532951d","project":"54aa7f773b56130b0056c86e","forked_from":"5e4fbbbda8fb41028f1861fe","__v":5,"createdAt":"2015-06-10T11:30:42.700Z","releaseDate":"2015-06-10T11:30:42.700Z"},"project":"54aa7f773b56130b0056c86e","__v":0,"parentDoc":null}

Managing Pulsate Sessions


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. [block:api-header] { "title": "1. Simple Session - startPulsateSession" } [/block] 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. [block:code] { "codes": [ { "code": "NSError* error;\n\nPULAuthorizationData* authData = [[PULAuthorizationData alloc] initWithAppId:@\"YOUR_SDK_APP_ID\" andAppKey:@\"YOUR_SDK_APP_KEY\" validationError:&error];\n \nPULPulsateManageer* pulsateManager = [PULPulsateFactory getInstanceWithAuthorizationData:authData andLocationEnabled:YES withPushEnabled:YES withLaunchOptions:launchOptions error:&error];\n\n[pulsateManager startPulsateSession:^(BOOL success, NSError* error) {}];\n ", "language": "objectivec" } ] } [/block] [block:code] { "codes": [ { "code": "let authData: PULAuthorizationData = try PULAuthorizationData(appId: \"SDK_APP_ID\", andAppKey: \"SDK_APP_KEY\");\n\nlet pulsateManager = try PULPulsateFactory.getInstanceWith(authData, withLocationEnabled: true, withPushEnabled: true, withLaunchOptions: launchOptions, withPulsateAppDelegate: true);\n \npulsateManager.startPulsateSession()", "language": "swift" } ] } [/block] [block:api-header] { "title": "2. Deduping Session - startPulsateSessionForAlias" } [/block] 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. [block:code] { "codes": [ { "code": "NSError* error;\n\nPULAuthorizationData* authData = [[PULAuthorizationData alloc] initWithAppId:@\"YOUR_SDK_APP_ID\" andAppKey:@\"YOUR_SDK_APP_KEY\" validationError:&error];\n \nPULPulsateManageer* pulsateManager = [PULPulsateFactory getInstanceWithAuthorizationData:authData andLocationEnabled:YES withPushEnabled:YES withLaunchOptions:launchOptions error:&error];\n\n[pulsateManager startPulsateSessionForAlias:uniqueIdentifier withListener:^(BOOL success, NSError* error) {}];", "language": "objectivec" } ] } [/block] [block:code] { "codes": [ { "code": "let authData: PULAuthorizationData = try PULAuthorizationData(appId: \"SDK_APP_ID\", andAppKey: \"SDK_APP_KEY\");\n\nlet pulsateManager = try PULPulsateFactory.getInstanceWith(authData, withLocationEnabled: true, withPushEnabled: true, withLaunchOptions: launchOptions, withPulsateAppDelegate: true);\n \npulsateManager.startPulsateSessionForAlias(uniqueIdentifier)", "language": "swift" } ] } [/block] [block:api-header] { "title": "3. Delaying Sessions" } [/block] 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. [block:code] { "codes": [ { "code": "#import <PULPulsate/PULPulsate.h>\n\[email protected] AppDelegate\n\n- (BOOL)application:(UIApplication *)application\n didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n NSError* error;\n\n\t\tPULAuthorizationData* authData = [[PULAuthorizationData alloc] initWithAppId:@\"YOUR_SDK_APP_ID\" andAppKey:@\"YOUR_SDK_APP_KEY\" validationError:&error];\n \n PULPulsateManager* pulsateManager = [PULPulsateFactory getInstanceWithAuthorizationData:authData withLocationEnabled:YES withPushEnabled:YES withLaunchOptions:launchOptions error:&error];\n\n if (userLoggedIn == YES)\n\t\t\t[_pulsateManager startPulsateSession:^(BOOL success, NSError* error) {}];\n \n return YES;\n}\n\n\[email protected]", "language": "objectivec" } ] } [/block] [block:code] { "codes": [ { "code": "import PULPulsate\n\nclass AppDelegate {\n\n\t func application(_ application: UIApplication, \n didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool\n {\n do\n {\n let authData: PULAuthorizationData = try PULAuthorizationData(appId: \"SDK_APP_ID\", andAppKey: \"SDK_APP_KEY\");\n \n let pulsateManager = try PULPulsateFactory.getInstanceWith(authData,\n withLocationEnabled: true, withPushEnabled: true, \n withLaunchOptions: launchOptions, withPulsateAppDelegate: true);\n \n if (userLoggedIn)\n pulsateManager.startPulsateSession();\n } catch {\n \t print(error);\n }\n return true;\n }\n}", "language": "swift" } ] } [/block] [block:api-header] { "title": "4. Logout" } [/block] If your user logs out, in order for him to stop sending data and getting new campaigns you need to call the *logoutCurrentAlias* method. [block:code] { "codes": [ { "code": "[pulsateManager logout:^(BOOL success, NSError* error) {}];", "language": "objectivec" } ] } [/block] [block:code] { "codes": [ { "code": "pulsateManager?.logout({(success, error) in });", "language": "swift" } ] } [/block]