Single Page Integration
TouchSDK collects user’s touch interaction with the app on a page (ViewController, Activity, Fragment), such as swipe, tap, and press to provide a more accurate information for population profiling.
Besides TouchSDK, the integration steps are similar to the existing BehavioSec integration , that is, setting page name, and ID for each of UI component and so on.
Enabling TouchSDK will increase the BehavioSec payload size. It is recommended to stop the detection as soon as the registration has completed, the screen is dismissed or you may optimize this operation in the background by calling GAHCore.clearTransactionResources. GAHCore.clearTransactionResources will clear all the BehavioSec data collected, and clear all the registrations and stop the motion detects.
Caution
Enabling
TouchSDKwill also increase signal collection time. Default timeout is set to 2000 ms. When BehavioSec signal collection exceeds this timeout, the signal will contain error code 524 (Signal Timeout). On older Android device, if the page is expected to contain a lot of touches, the timeout should be increased by callingGAHCoreConfig.setSignalCollectionGlobalTimeout(). The following table provides signal collection time for some devices.
Device 10 touches 20 touches 30 touches 60 touches 120 touches Android Nexus 7 (2012) 715 ms 1277 ms 1621 ms 3206 ms 5919 ms Xperia Z5 512 ms 826 ms 1255 ms 2107 ms 4492 ms Blackberry Priv 328 ms 541 ms 693 ms 1745 ms 3594 ms OnePlus 5T 73 ms 99 ms 138 ms 274 ms 516 ms iOS iPhone 5s 25 ms 35 ms 45 ms 77 ms 142 ms iPhone 7 Plus 12 ms 15 ms 19 ms 33 ms 58 ms iPad 6th gen (2018) 8 ms 12 ms 14 ms 25 ms 43 ms
iOS
It is recommended to place the setup code in viewWillAppear and clear the data code in viewWillDisappear.
After the user has finished entering the input fields and is ready to submit the data:
-
Obtain visitID by calling the
requestVisitIDAPI. All the data collection will be passed in therequestVisitIDAPI. -
In cases where an error occurs, it may require the user to re-enter all the inputs, then you have to call the 'clear data' function and 'set up' function again. Otherwise, the data from the old session will be appended along with the new session.
The following sample code snippet shows how to integrate the NAF feature 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];
[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];
}
-(IBAction)registerButtonPressed:(id)sender {
if ([self isValidTextFieldInput]) {
//The user's interaction and risks data are sent via requestVisitID
[GAHCore requestVisitID:^(NSString *visitID) {
//call backend to register new account and get decisions
[self registerNewAccountWithVisitId:visitID];
} failure:^(NSInteger errorCode, NSString *errorMessage) {
//handle error
//clear current data and do set up again if needed
}];
}
}
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()
}
@IBAction func registerButtonPressed(_ sender: UIButton) {
if (isValidTextFieldInput()) {
GAHCore.requestVisitID({ (visitID) in
//call backend to register new account and get decisions
self.registerNewAccount(withVisitId: visitID!)
}) { (errorCode, errorMessage) in
//handle error
//clear current data and do set up again if needed
}
}
}
Android
Besides enabling TouchSDK, it is also recommended to enable DeviceSDK. DeviceSDK collects the device data. Refer to BehavioSec documentation for more details.
Perform the following steps to integrate the NAF feature:
- Extends BehavioSec
BehavioAbstractActivity. BehavioSec also providesBehavioAppCompactActivityandBehavioAbstractFragmentfor theAppCompatActivityandFragmentuse cases. Refer to 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. - Pass both
TouchSDKandDeviceSDKobjects toGAHCore.setBehavioSecTouchDeviceObject. - Start the data collection by calling
TouchSDK.startDataCollection.
- 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.
-
After the user has finished entering the input fields and is ready to submit the data:
- Obtain visitID by calling the
requestVisitIDAPI. - Clear the text fields and BehavioSec data by calling
GAHCore.clearTransactionResources().
- Obtain visitID by calling the
The following sample code snippet shows how to set up a single page integration in Android:
// 1. extend activity
public class RegistrationActivity 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());
// i. set TouchSDK and DeviceSDK to GAHCore
GAHCore.setBehavioSecTouchDeviceObject(mTouchSDK, mDeviceSDK);
}
// ii. start data collecetion
mTouchSDK.startDataCollection();
}
// 5. stop data collection in onPause and start data collection in onResume
@Override
protected void onPause() {
super.onPause();
if (mTouchSDK != null){
mTouchSDK.stopDataCollection();
}
}
@Override
protected void onResume() {
super.onResume();
if (mTouchSDK != null){
mTouchSDK.startDataCollection();
}
}
// 6. after user has entered data
public void nextButtonTouched(View view) {
// i. obtain visitID
GAHCore.requestVisitID(new GAHResponseCallback() {
@Override
public void success(String visitId) {
// ii. clear the textfields and timing data
GAHCore.clearTransactionResources();
mTouchSDK = null;
mDeviceSDK = null;
}
@Override
public void error(int errCode, final String errorMsg) {}
});
}
}