React SDK API Reference

Behavioral Events

Sign up event

When a user signs up on the app, the client app shall call the Hydra SDK API to sign up the user on the Hydra platform as well.

Example 1:

import {pushUserSignUp} from './HydraModule';
pushUserSignUp({
         customerId: '12345',
         email: '[email protected]',
         phone: '1234567890',
         firstName: 'Rakesh',
         lastName: 'Kumar',
         customData: {
           age: '25',
           gender: 'MALE',
           address: 'Pune',
         },
       })
         .then(resp => {console.log('pushUserSignUp success', resp);})
         .catch(error => {});

Example 2: You can sign up without optional data as well -

pushUserSignUp({
         customerId: '12345',
         email: '',
         phone: '',
         firstName: '',
         lastName: '',
         customData: null,
       })
         .then(resp => {console.log('pushUserSignUp success', resp);})
         .catch(error => {});

Sign in event

Similar to sign up event, when the user logs into the client mobile app, the client mobile app shall call the sign in Hydra SDK API with required details -

import {pushUserSignIn} from './HydraModule';


pushUserSignIn({
     customerId: userName,
     firstName,
     lastName,
     email,
     phone: phoneNumber,
     customData: JSON.parse(customAttributes),
   })
     .then((res: any) => {console.log('pushUserSignIn success', res)})
     .catch((err: any) => {Alert.alert('Error', 'Failed to sign in')});

Update User info event

When user updates the user information, the app shall call push user update api -

import {pushUserUpdate} from './HydraModule';


   let customAttributesObj = customAttributes
     ? JSON.parse(customAttributes)
     : null;
   let subscriptionsObj = subscriptions ? JSON.parse(subscriptions) : null;
   console.log("calling pushUserSignUp");
   pushUserUpdate({
     customerId: userName,
     firstName,
     lastName,
     email,
     phone: phoneNumber,
     customData: customAttributesObj,
     subscriptions: subscriptionsObj,
   })
     .then((res: any) => {
       console.log("pushUserSignUp", res);
       navigation.goBack();
     })
     .catch((err: any) => {
       console.log("pushUserSignUp", err);
       Alert.alert("Error", "Failed to sign up");
     });
 };

Sign out event

When user signs out from the app, user shall call the sign out function -

import {pushUserSignOut} from './HydraModule';  
pushUserSignOut(customerID)  
     .then(() => {  
       navigation.reset({  
         index: 0,  
         routes: [{ name: 'Welcome' }],  
       });  
     })  
     .catch((err: any) => {  
       console.log('pushUserSignOut', err);  
       Alert.alert('Error', 'Failed to sign out');  
     });

Sending custom event

If your application want to register any custom event for example, the new user created or user added the new items or user does some action and app want to trigger the event then please use pushEvent API -

pushEvent(eventName, customData)
   .then((res: any) => {console.log('pushEvent success', res)}
   ).catch((err: any) => {console.log('pushEvent error', err)}