Version: 4.6.0
You’ll find a sample app using the PingOne Fraud for Android SDK
To integrate the PingOne Fraud for Android SDK on your client:
Add the mavenCentral repository to your root build.gradle
file:
allprojects {
repositories {
mavenCentral()
}
}
Add the PingOne Fraud for Android SDK to your application dependencies.
Add the following to your application-level build.gradle
file:
implementation "com.pingidentity.pingonefraud:android-sdk:${LATEST_VERSION}"
Initialize the SDK. Extend the Application class and add the following inside the onCreate
method:
public class MyApplication extends Application {
@Override
public <span class="hljs-keyword">void</span> onCreate() {
<span class="hljs-keyword">super</span>.onCreate();
<span class="hljs-comment">// optional</span>
SecuredTouchSDK.setEventListener(<span class="hljs-keyword">new</span> StatusEventListener() {
@Override
public <span class="hljs-keyword">void</span> onError(@NonNull <span class="hljs-built_in">String</span> uuid, @NonNull <span class="hljs-built_in">String</span> message, int code) {
Log.i(<span class="hljs-string">"SecuredTouchSDK"</span>, <span class="hljs-string">"onError "</span> + message + <span class="hljs-string">" code: "</span> + code + <span class="hljs-string">" uuid: "</span> + uuid);
}
@Override
public <span class="hljs-keyword">void</span> onInitialized(@NonNull <span class="hljs-built_in">String</span> uuid) {
Log.i(<span class="hljs-string">"SecuredTouchSDK "</span>, <span class="hljs-string">"onInitialized "</span> + uuid);
}
});
STInitParams initParams = <span class="hljs-keyword">new</span> STInitParams(<appId>, <appSecret>, <serverHost>)
.setUserId(<currentUserId>)
.setSessionId(<sessionId>)
.setDebugMode(BuildConfig.DEBUG)
.setConsoleLogEnabled(BuildConfig.DEBUG);
SecuredTouchSDK.init(this, initParams);
}
}
Parameter | Description |
---|---|
appId |
The PingOne application ID. See the PingOne Fraud admin documentation for instructions on getting the PingOne Fraud SDK access credentials. |
appSecret |
The PingOne application secret. See the PingOne Fraud admin documentation for instructions on getting the PingOne Fraud SDK access credentials. |
serverHost |
The Fraud service host. See the PingOne Fraud admin documentation for instructions on getting this information. |
userId |
If the user is already identified (signed on) when initializing the Fraud SDK, their user ID should be set here. If the user ID originates from PingOne, use the user ID for the PingOne environment. For all other cases, use a non-personal user identifier. |
sessionId |
The user’s session ID. To query the Fraud service for the trust scores through the backend system, the Fraud service and the backend system must have a shared identifier for each session. The session ID usually serves as this shared identifier. |
consoleLogEnabled |
(Optional) Set this to true to enable console logging by the SDK. Defaults to false . |
externalLogsEnabled |
(Optional) Set this to false to prevent the SDK from sending error logs to an external logging service. Defaults to true . |
Set an event listener to get calls on successful SDK initialization, or for when something goes wrong in the SDK.
Parameter | Description |
---|---|
uuid |
Unique identifier for the entire lifetime of the SDK. This value stays the same as long as the app’s process is alive. Also available through SecuredTouchSDK.getInstanceUUID(); . |
message |
The nature of the failure. |
code |
Internal error code. |
Fetch a Fraud token. The SDK generates a token that’s used for Fraud BOT detection capabilities. You’ll need to share the token with your application backend so a call with the fetched token can be sent from this backend to the Fraud Evaluation API to retrieve the risk assessment for a session.
To get the token from the Fraud SDK, add a call to:
SecuredTouchSDK.getToken();
An event is fired every time the token changes. For example:
SecuredTouchSDK.setTokenReadyListener(new TokenReadyListener() {
@Override
public void onTokenReady() {
Log.i("com.securedtouch", "token ready: " + SecuredTouchSDK.getToken());
}
});
Don’t use your application to store the token, and instead share the token stored by the SDK.
User log in and log out. You can do this differently, depending on the following:
When the application receives the user ID, or any other unique identifier of the user (for example, after sign on), add the call:
SecuredTouchSDK.login(<user-id>);
If you have a session ID, you can use:
SecuredTouchSDK.login(<user-id>, <session-id>);
If the application loses the unique identifier of the user (for example, after sign off), add a call to:
SecuredTouchSDK.logout();
On sign off, the Fraud SDK clears the session ID by default. If you have a session ID after the user has signed off, use the following call instead of the call above:
SecuredTouchSDK.logout(<session-id>);
Set the session ID. To query the Fraud service for the trust scores through the backend system, the Fraud service and the backend system must have a shared identifier for each session. The session ID usually serves as this shared identifier. To set the session ID after the application has it, call:
SecuredTouchSDK.setSessionId(<session-id>);
Add meaningful IDs to input fields and buttons. Meaningful IDs are required to ensure proper identification of the UI element for detection purposes. Here’s an example for a meaningful ID that can be added to a Login button:
android:id="@+id/button_login"
Add tags. You can tag specific points in time during a session that will be saved by the Fraud service. Tags can be added remotely by the PingOne Fraud platform (using CSS selectors), or programmatically using JavaScript or HTML attributes.
To add a single tag, use:
SecuredTouchSDK.addTag(<tag-name>);
To add a tag with additional information, use:
SecuredTouchSDK.addTag(<tag-name>, <value>);
To add multiple tags:
SecuredTouchSDK.addTag(<tag-name>, <value>). addTag(<tag-name>);
Flush the buffer. Flushing the buffer forces the SDK to send buffered data to directly to the PingOne Fraud backend platform. Usually the built-in automatic flush should be sufficient, so this function should not be used unless instructed to do so by Ping Identity Professional Services.
SecuredTouchSDK.flush();
Pause or resume the PingOne Fraud SDK activity, networking, and data collection:
Option | Command | Description |
---|---|---|
Pause the SDK | SecuredTouchSDK.pause(); |
Causes the current state and session ID to be saved, and used on resuming SDK operations. |
Resume the SDK | SecuredTouchSDK.resume(); |
Resumes normal SDK operations. |
Pause or resume behavioral data collection:
Option | Command | Description |
---|---|---|
Pause behavioral data collection | SecuredTouch.pauseBehavioralData() |
The SDK stops collecting events related to physical interaction (such as, touchscreen, device sensors, and keyboard). All other SDK activity continues as normal. |
Resume behavioral data collection | SecuredTouch.resumeBehavioralData() |
Resumes SDK operations related to physical events. |
SecuredTouchSDK.getInstanceUUID();
.PingOne Fraud does not collect email addresses or phone numbers, but their anonymized features instead (such as, email domain, length, phone number, and country code).
On every sign-on attempt, call the loginAttempt
method with the login type. For example:
// For email login. This doesn't collect the email address itself, only anonymized features (such as, length, and email domain).
SecuredTouchSDK.LOGIN.loginAttemptEmail("email@example.com");
// For social login
SecuredTouchSDK.LOGIN.loginAttempt(SocialType.GOOGLE);
The SocialType
value can be: FACEBOOK
, GOOGLE
, APPLE
, TWITTER
, LINKEDIN
, or a custom string. For example: SecuredTouchSDK.LOGIN.loginAttempt("custom_provider");
.
On a successful sign-on attempt, call the accountCreationTime
method with the UNIX epoch timestamp (in seconds) of the account creation time. For example: SecuredTouchSDK.LOGIN.accountCreationTime(EPOCH_TIME_IN_SECONDS);
.
On failed sign-on attempt, call the loginFailed
method. For example: SecuredTouchSDK.LOGIN.loginFailed();
.
When the user starts a forgot password flow, call the forgotPassword
method.
On every registration attempt, call the registrationAttempt
method with the registration type. For example:
// for email registration
SecuredTouchSDK.REGISTRATION.registrationAttemptEmail("email@example.com");
// for social registration
SecuredTouchSDK.REGISTRATION.registrationAttempt(SocialType.GOOGLE);
The SocialType
value can be: FACEBOOK
, GOOGLE
, APPLE
, TWITTER
, LINKEDIN
, or a custom string. For example: SecuredTouchSDK.REGISTRATION.registrationAttempt("custom_provider");
.
On a successful registration, call the registrationSuccess
method. For example: SecuredTouchSDK.REGISTRATION.registrationSuccess();
.
On a failed registration, call the registrationFailed method
. For example: SecuredTouchSDK.REGISTRATION.registrationFailed();
.
When a referral was applied on a certain registration, call the referralApply
method.
On every shipping address change, call the shippingAddressChanged
method with the new shipping address. For example: SecuredTouchSDK.ACCOUNT.shippingAddressChanged("new address");
.
On every account’s email change, call the emailAddressChanged
method with the new email address. For example: SecuredTouchSDK.ACCOUNT.emailAddressChanged("new_email@example.com");
On every notification settings change, call the notificationChanged
method with the updated notification state (on/off) and the notification information. For example:
// the user turned on promotion notifications
SecuredTouchSDK.ACCOUNT.notificationChanged(true, "promotions");
// the user turned off new coupons notifications
SecuredTouchSDK.ACCOUNT.notificationChanged(false, “coupons”);
When the user tries to delete an account, call the deleteAccount
method.
When the user tries to see payment methods available in the account, call the paymentMethodDisplay
method.
When the user clears account history, call the clearHistory
method.
When the user buys a gift card, shares a gift card, or redeems a gift card, call the useGiftCard
method.
On every purchase attempt, call purchaseAttempt
with the payment method. For example: SecuredTouchSDK.CHECKOUT.purchaseAttempt(PaymentMethod.CREDIT_CARD);
. The available PaymentMethod values can be: PAYPAL
, CREDIT_CARD
, or a custom payment method. For example: SecuredTouchSDK.CHECKOUT.purchaseAttempt("other payment method");
. Only the payment method type is specified. Do not specify any payment identifiers (such as, credit card number).
On a successful purchase, call the purchaseSuccess
method. For example: SecuredTouchSDK.CHECKOUT.purchaseSuccess();
.
On a failed purchase, call the purchaseFailed
method. For example: SecuredTouchSDK.CHECKOUT.purchaseFailed();
.
On coupon usage, call the applyCoupon
method. For example: SecuredTouch.CHECKOUT.applyCoupon();
.
When a user adds an item to the cart, call the addToCart
method. For example: SecuredTouchSDK.PRODUCT.addToCart();
.
When a user saves an item for later, or adds an item to their wishlist, call the saveItem
method. For example: SecuredTouchSDK.PRODUCT.saveItem();
.
When the user views catalog details, call the viewDetail
method.
When the user follows a channel, call the followChannel
method.
When the user unfollows a channel, call the unfollowChannel
method.
When the application challenges the user, call the challengeInvoked
method with the challenge type. Some examples: SecuredTouchSDK.CHALLENGE.challengeInvoked("security questions");
or SecuredTouchSDK.CHALLENGE.challengeInvoked(ChallengeType.HIDE_BILLING);
. The available ChallengeType values are: RECAPTCHA
, HIDE_BILLING
.
If the user successfully completes the challenge, call the challengeSuccess
method. For example: SecuredTouchSDK.CHALLENGE.challengeSuccess();
.
If the user didn’t pass the challenge, call the challengeFailed
method. For example: SecuredTouchSDK.CHALLENGE.challengeFailed();
.
When the user clears the cart, call the clearCart
method.
When the user deletes an item from the cart, call the deleteItem
method.
When the user goes to the checkout page, call the goToCheckout
method.
When the user opens a dispute, call the openDispute
method.
When the user views a dispute, call the viewDispute
method.
When the user views an order’s details, call the viewOrderDetails
method.
addMessage
method.When the user starts a stream, call the startStream
method.
When the user ends a stream, call the endStream
method.
reportFraud
method.