Initialization & Usage
1) Initialize
envrionment can be test or prod. Please use test envrionment for avoiding create unneccessary transaction.
debugMode will let you the skip security scan process. You can use this for your development envrionment.
If you enable showDebugScreen, small FAB button will appear on the right, bottom corner. You can track all logged events, api request and SSE conditions with this feature.
Once SDK initialized, setUser method needs to be called if there is user logged in.
import { KLP } from "@kaizen-dev-team/rn-sdk";
await KLP.initialize({
environment: __DEV__ ? "test" : "prod",
debugMode: __DEV__,
showDebugScreen: false
})
.then(() => KLP.setUser(..args))
.catch((error) => {
console.error("[KLP] initialize failed:", error);
});2) Set User After Login
After successful login, pass the KLP user id as first parameter. Second parameter should be the authentication token.
If user already logged in, this method needs to be called after initialize like above.
await KLP.setUser("user-123", "access-token");3) Launch Loyalty Screen
You can open the gamification screen directly using the launch method. It takes an optional parameter for opening specific screen directly.
await KLP.launch();
// or
await KLP.launch("rewards");4) Log Business Events
In order to log event from the Frontend, you need to call logEvent method. First parameter is the event name. Second parameter is the object for attributes and its optional.
await KLP.logEvent("MoneyTransfer", {
amount: 500,
currency: "TRY"
});5) Redirecting on host application.
In order to redirect in host application, you need to set a listener method to onDeeplink. url will be the screen name that you assign from the KLP Admin.
const removeDeepLink = KLP.onDeepLink(({ url }) => {
console.log("Deep link:", url);
});
removeReward.remove();5) Listening Campaign Progress Events / Disable KLP Progress popup
By default, KLP SDK listens event progress and shows user via popup. In order to show a custom design or disable the event progress popup, you need to set a listener method like below.
Once you set the listener, KLP SDK popup will not be shown.
const removeReward = KLP.onRewardEarned((reward) => {
console.log("Reward earned:", reward.name);
});
// Later
removeDeepLink.remove();UI Component
You can use the KLP components for redirecting gamification screen directly.
import { KLPWidget } from "@kaizen-dev-team/rn-sdk";
<KLPWidget />Notes
- Call
initializebefore any other SDK method. - Set
environmentas one ofdev,test,prod. - Call
setUserafter host app authentication. - Call
logoutwhen user signs out. - Prefer
debugMode: falseandshowDebugScreen: falsein production builds.
Updated about 1 month ago
