Multiple Page Integration
To use the NAF feature on mulitple pages, GAHCore.startProfileTransaction is called to obtain visitID the first time it is set up on the first page. This visitID will be used throughout the multiple page sequences that are visited.
Note
Call the
GAHCore.profileTransactionAPI only after visitID is obtained fromGAHCore.startProfileTransaction.
At the end of every page, GAHCore.profileTransaction is called to collect the user's behavioral data on each page.
On the last page, it is recommended to wait for profileTransaction to finish before calling the backend API that will call getDecision. Otherwise, there is a chance that user's data collected on last page is not received yet by the backend when getDecision is called.
After the registration is completed, call GAHCore.finishProfileTransaction to clear the associated visitID in the SDK.
iOS
Setup
The setup in the multiple page integration is very similar to the single page integration except:
-
In the single page integration, after the user has entered the inputs, the data collected will be appended and send in the
requestVisitIDAPI. -
For multiple page integration, as the user will enter the inputs on multiple screens, the
profileTransactionAPI is used to append and send the user’s behavioral data for the current session. -
GAHCore.startProfileTransactionis used instead ofGAHCore.requestVisitIdduring the setup of the first page to obtain visitID.
.
Note
For every registration page, it is recommended to place the setup code in
viewWillAppearand clear the user’s behavioral data code inviewWillDisappear.
The following sample code snippet shows how to set up and clear data code on iOS.
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self setupBehavioSec];
[GAHCore startPrefetchSignals];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self clearBehavioSecData];
}
-(void)setupBehavioSec {
//initialize BehavioSec object
self.bSDK = [BehavioSecIOSSDK sharedIOSSDK];
//Register UI elements
self.bSDK addInformation:@"<page_definition_identifier>" withName:@"viewIdentifier"];
[self.bSDK registerKbdTargetWithID: self.inputTextField andName:@"<id_defined_in_page_definition>" isAnonymous:YES];
//Set BehavioSec Object to GAH SDK
[GAHCore setBehavioSecObject:self.bSDK];
//enable TouchSDK and start motion detects
[self.bSDK enableTouchSDKWithViewController:self];
[self.bSDK startMotionDetect];
}
-(void)clearBehavioSecData{
[self clearTextFieldData];
//Below function will clear all BehavioSec data collected, clear all registrations and stop the motion detects
[GAHCore clearTransactionResources];
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setupBehavioSec()
GAHCore.startPrefetchSignals()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillAppear(animated)
clearBehavioSecData()
}
func setupBehavioSec() {
//initialize BehavioSec object
self.bSDK = BehavioSecIOSSDK.shared()
//Register UI elements
self.bSDK.addInformation("<page_definition_identifier>", withName: "viewIdentifier")
self.bSDK.registerBtnTarget(withID: self.inputTextField, andName: "<id_defined_in_page_definition>", isAnonymous: true)
//Set BehavioSec Object to GAH SDK
GAHCore.setBehavioSecObject(self.bSDK)
//enable TouchSDK and start motion detects
self.bSDK.enableTouch(with: self)
self.bSDK.startMotionDetect()
}
func clearBehavioSecData() {
clearTextFieldData()
//Below function will clear all BehavioSec data collected, clear all registrations and stop the motion detects
GAHCore.clearTransactionResources()
}
Setting your first page
- On the first entry screen of the registration flow, call
GAHCore.startProfileTransactionto obtain visitID before allowing user interaction. You may also obtain visitID earlier before this step. - Call
profileTransactionto send the user's behavioral data when the user has finished entering input fields and about to move to the next screen.
In the following sample code snippet, you can:
- Call the
startProfileTransactionAPI inviewDidLoadto start the session. - Call
profileTransactionwhen the user click next to proceed to the next screen.
Note
Only use the
startProfileTransactionAPI to obtain visitID when you are integrating the New Account Fraud feature on multiple pages. Do not use theGAHCore.requestVisitIDmethod as it may send redundant data to the server which may lead to errors in dashboard entries.
The following sample code snippet shows how to set up the first page on an iOS device:
- (void)viewDidLoad {
[super viewDidLoad];
[GAHCore startPrefetchSignals];
[GAHCore startProfileTransaction:^(NSString *visitID) {
//store visitID to get the fraud decisions when calling registration API;
} failure:^(NSInteger errorCode, NSString *errorMessage) {
}];
}
-(IBAction)nextButtonPressed:(id)sender {
if ([self isValidTextFieldInput]) {
//Do profiling and move to the next screen
[GAHCore profileTransaction:^(NSInteger statusCode, NSString *statusMessage) {
}];
[self moveToTheNextScreen];
}
}
override func viewDidLoad() {
super.viewDidLoad()
//should stop user interaction before getting the visitID
GAHCore.startPrefetchSignals()
GAHCore.startProfileTransaction({ (visitID) in
//store visitID to get the fraud decisions when calling registration API
}) { (errorCode, errorMessage) in
//handle error and retry
}
// Do any additional setup after loading the view.
}
@IBAction func registerButtonPressed(_ sender: UIButton) {
if (isValidTextFieldInput()) {
//Do profiling and move to the next screen
GAHCore.profileTransaction { (statusCode, statusMessage) in
//handle error or just ignore the return
}
}
}
Setting subsequent pages
- Call the
profileTransactionAPI. - Proceed to the next page.
The following sample code snippet shows how to set up subsequent pages on an iOS:
-(IBAction)nextButtonPressed:(id)sender {
if ([self isValidTextFieldInput]) {
//Do profiling and move to the next screen
[GAHCore profileTransaction:^(NSInteger statusCode, NSString *statusMessage) {
}];
[self moveToTheNextScreen];
}
}
@IBAction func registerButtonPressed(_ sender: UIButton) {
if (isValidTextFieldInput()) {
//Do profiling and move to the next screen
GAHCore.profileTransaction { (statusCode, statusMessage) in
//handle error or just ignore the return
}
}
}
Setting your last page
- Call the
profileTransactionAPI. - Wait for the
profileTransactionAPI to complete. - Clear the visitID that is associated with this operation by calling
finishProfileTransaction. - Continue with the application registration process.
The following sample code snippet shows how to set up your last page on an iOS device:
-(IBAction)registerButtonPressed:(id)sender {
if ([self isValidTextFieldInput]) {
[GAHCore profileTransaction:^(NSInteger statusCode, NSString *statusMessage) {
if (statusCode == RESULT_STATUS_CODE_OK) {
//Clear visitID associated with this operation
[GAHCore finishProfileTransaction];
//Call app's API to register for new account.
//The visit Id obtained in the first page will be sent to get fraud decisions
[self registerNewAccountWithVisitId:self.currentVisitID];
} else {
//Handle error
}
}];
}
}
@IBAction func registerButtonPressed(_ sender: UIButton) {
if isValidTextFieldInput() {
//Do profiling and move to the next screen
GAHCore.profileTransaction { (statusCode, statusMessage) in
if statusCode == RESULT_STATUS_CODE_OK {
//Clear visitID associated with this operation
GAHCore.finishProfileTransaction()
//Call app's API to register for new account.
//The visit Id obtained in the first page will be sent to get fraud decisions
self.registerNewAccount(withVisitId: self.currentVisitId)
}
}
}
}
Known issue
On iOS, when TouchSDK is enabled for New Account Fraud, there are intermittent false negative problems for BOT detection (BotDesc15) when integrating for multiple pages. iPhones sometimes record touches with errors in the key timings. This causes BehavioSense to flag sessions with BotDesc15 (https://developer.behaviosec.com/docapi/5.2/#bot-description-codes).
The workaround for this issue is to disable BotDesc15 in the Page definitions for gesture data (type fg - TouchSDK) on all affected pages.
Android
The setup in the multiple page integration is very similar to single page integration (step 1 - 4) except:
GAHCore.startProfileTransactionis used instead ofGAHCore.requestVisitIdduring the setup of the first page to obtain visitID.TouchSDKandDeviceSDKobjects are not passed toGAHCore.setBehavioSecTouchDeviceObject. Instead, these objects will be used at the end of page later during call toGAHCore.profileTransaction.
Setup (Applies to All Pages)
- Extends BehavioSec
BehavioAbstractActivity. BehavioSec also providesBehavioAppCompactActivityandBehavioAbstractFragmentforAppCompatActivityandFragmentuse cases. Refer to be BehavioSec documentation for more details. -
Use these steps to override the
initActivitymethod:- Set the page name by calling
BehavioTimings.setPageName(). - Use
BehavioEditText,BehavioMaskedEditTextorBehavioAnonymousEditTextprovided by BehavioSec and set the ID by callingsetFieldName. - Override
dispatchTouchEventbecauseTouchSDKhas to get information about every interaction with the application. - In
onResume, create theTouchSDKandDeviceSDKobjects to start the data collection.
- Set the page name by calling
Note
You can only do data collection when the application is active by stopping the data collection in
onPause.
The following sample code snippet shows how to set up the first page on an Android device:
// 1. extend activity
public class RegistrationFirstPageActivity extends BehavioAppCompatActivity {
private BehavioEditText mUsernameEditText;
private TouchSDK mTouchSDK;
private DeviceSDK mDeviceSDK;
// 2. override initActivity
@Override
public void initActivity() {
setContentView(R.layout.activity_registration);
// i. set page name
BehavioTimings.setPageName("<page_definition_identifier>");
// ii. set id for textfields
mUsernameEditText = (BehavioEditText)findViewById(R.id.text_username);
mUsernameEditText.setFieldName("<id_defined_in_page_definition>");
}
// 3. override dispatchTouchEvents
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (mTouchSDK != null) {
mTouchSDK.addTouchEvent(ev);
}
return super.dispatchTouchEvent(ev);
}
// 4. create TouchSDK and DeviceSDK
@Override
protected void onResume() {
super.onResume();
if (mTouchSDK == null){
ViewGroup viewGroup = findViewById(R.id.activity_viewgroup);
mTouchSDK = new TouchSDK(getApplicationContext(), viewGroup);
mDeviceSDK = new DeviceSDK(getApplicationContext());
// mTouchSDK and mDeviceSDK will be used later as input to profileTransaction
}
// i. start data collection
mTouchSDK.startDataCollection();
}
// 5. stop data collection in onPause
@Override
protected void onPause() {
super.onPause();
if (mTouchSDK != null){
mTouchSDK.stopDataCollection();
}
}
}
Setting your first page
- On
onStart, callGAHCore.startProfileTransactionto obtain visitID before allowing user interaction. You may also obtain visitID earlier prior to this step.- Call the
GAHCore.startProfileTransactionAPI. - Wait for the callback.
- Call the
Note
Only use the
GAHCore.startProfileTransactionAPI to obtain visitID when you are integrating the New Account Fraud feature on multiple pages. Do not use theGAHCore.requestVisitIDshouldmethod as it may send redundant data to the server which may lead to errors in dashboard entries.
- After the user has finished entering the input fields, call the
GAHCore.profileTransactionAPI. - Clear the input fields and BehavioSec data by calling the
GAHCore.clearTransactionResourcesmethod. - Proceed to the next page.
The following sample code snippet shows how to set up the first page on an Android device:
// 1. obtain visitID
@Override
protected void onStart() {
// i. call startProfileTransaction
GAHCore.startProfileTransaction(new GAHResponseCallback() {
@Override
public void success(String visitId) {
// ii. wait for callback
// proceed with the page setup
}
@Override
public void error(int errCode, final String errorMsg) {
// handle error, do not proceed with next page. Because profileTransaction requires visitID obtained.
}
});
}
public void nextButtonTouched(View view) {
// 2. call profileTransaction
GAHCore.profileTransaction(mTouchSDK, mDeviceSDK, null,
(statusCode, statusString) -> {}
);
// 3. clear the textfields and touchSDK
GAHCore.clearTransactionResources();
mTouchSDK = null;
mDeviceSDK = null;
// 4. go to next page
Intent intent = new Intent(this, RegistrationSecondPageActivity);
startActivity(intent);
}
Setting subsequent pages
- After the user has finished entering the input fields, call the
GAHCore.profileTransactionAPI. - Clear the input fields and BehavioSec data by calling the
GAHCore.clearTransactionResourcesmethod. - Proceed to the next page.
The following sample code snippet shows how to set up the subsequent pages on an Android device:
public void nextButtonTouched(View view) {
// 1. call profileTransaction
GAHCore.profileTransaction(mTouchSDK, mDeviceSDK, null,
(statusCode, statusString) -> {}
);
// 2. clear the textfields and touchSDK
GAHCore.clearTransactionResources();
mTouchSDK = null;
mDeviceSDK = null;
// 3. go to next page
Intent intent = new Intent(this, RegistrationThirdPageActivity);
startActivity(intent);
}
Setting your last page
- After the user has finished entering the input fields, call the
GAHCore.profileTransactionAPI. - Clear the input fields and BehavioSec data by calling the
GAHCore.clearTransactionResourcesmethod. - Wait for the
GAHCore.profileTransactionfunction to complete. - Clear the visitID that is associated with this operation by calling
GAHCore.finishProfileTransaction. - Continue with the application registration process.
The following sample code snippet shows how to set up the last page on an Android device:
public void nextButtonTouched(View view) {
// 1. call profileTransaction
GAHCore.profileTransaction(mTouchSDK, mDeviceSDK, null, (statusCode, statusString) -> {
// 3. wait for completion
// 4. clear visitID
GAHCore.finishProfileTransaction();
if (statusCode == GAHErrorCodes.RESULT_STATUS_CODE_OK) {
// 5. continue with registration process
} else {
// handles error
}
});
// 2. clear the textfields and touchSDK
GAHCore.clearTransactionResources();
mTouchSDK = null;
mDeviceSDK = null;
}