0.0.33 • Published 5 months ago

gopersonal-react-native-sdk v0.0.33

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

Gopersonal React Native SDK

The GoPersonal SDK for React Native allows you to capture user behavior, display personalized content based on their interactions, and implement push notifications.

Installation

First, install the GoPersonal SDK for React Native:

npm install gopersonal-react-native-sdk

Importing and Initializing the SDK

To start using the SDK, import it into your project and initialize it with your client ID and client secret.

import SDK from 'gopersonal-react-native-sdk';

// Initialize the SDK
await SDK.init('BR-your-client-id', 'your-client-secret', { debug: true });

Core Functionality

User Login

Log in a user to the SDK:

await SDK.login('customer-id', { additionalData: 'value' });

User Logout

Log out the current user:

await SDK.logout();

Search

Perform a search query and get results:

const searchResults = await SDK.search('search query');

Get Content

Retrieve personalized content by content ID:

const content = await SDK.getContent('content-id');

Get NPS

Retrieve Net Promoter Score content:

const npsContent = await SDK.getNPS();

Add Interaction

Capture user interactions to enhance personalization:

await SDK.addInteraction('view', { someData: 'value' });

Add Interaction State

Add a state to the interaction flow:

await SDK.addInteractionState('stateKey', { transactionId: 'uniqueId' });

Open Impression

Mark an impression as opened:

await SDK.openImpression('impressionId');

Push Notifications

Initialize Firebase

Set up Firebase for push notifications:

await SDK.initializeFirebase();

Request Notification Permission

Request permission to send notifications (required for iOS):

const permissionGranted = await SDK.requestNotificationPermission();

Get Firebase Token

Retrieve the Firebase token for the device:

const token = await SDK.getFirebaseToken();

Send Token to Backend

Send the Firebase token to your backend:

await SDK.sendTokenToBackend(token);

Handle Incoming Messages

Set up a listener for incoming messages when the app is in the foreground:

const unsubscribe = SDK.onMessage(async remoteMessage => {
  console.log('Received foreground message:', remoteMessage);
  // Handle the message
});

Handle Notification Opened App

Set up a listener for when a notification opens the app from the background:

SDK.onNotificationOpenedApp(remoteMessage => {
  console.log('Notification opened app from background state:', remoteMessage);
  // Handle the notification
});

Check Initial Notification

Check if the app was opened from a notification when it was in a quit state:

const initialNotification = await SDK.getInitialNotification();
if (initialNotification) {
  console.log('App opened from quit state by notification:', initialNotification);
  // Handle the initial notification
}

Complete Example

Here's a comprehensive example of how to use the GoPersonal SDK in a React Native application:

import SDK from 'gopersonal-react-native-sdk';
import { useEffect } from 'react';

const App = () => {
  useEffect(() => {
    const initializeSDK = async () => {
      try {
        // Initialize the SDK
        await SDK.init('BR-your-client-id', 'your-client-secret', { debug: true });

        // Log in the user
        await SDK.login('customer-id', { additionalData: 'value' });

        // Perform a search query
        const searchResults = await SDK.search('search query');
        console.log('Search Results:', searchResults);

        // Retrieve personalized content
        const content = await SDK.getContent('content-id');
        console.log('Content:', content);

        // Capture a user interaction
        await SDK.addInteraction('view', { someData: 'value' });

        // Set up push notifications
        await SDK.initializeFirebase();
        const permissionGranted = await SDK.requestNotificationPermission();
        if (permissionGranted) {
          const token = await SDK.getFirebaseToken();
          await SDK.sendTokenToBackend(token);

          SDK.onMessage(async remoteMessage => {
            console.log('Received foreground message:', remoteMessage);
          });

          SDK.onNotificationOpenedApp(remoteMessage => {
            console.log('Notification opened app from background state:', remoteMessage);
          });

          const initialNotification = await SDK.getInitialNotification();
          if (initialNotification) {
            console.log('App opened from quit state by notification:', initialNotification);
          }
        }
      } catch (error) {
        console.error('Error initializing SDK:', error);
      }
    };

    initializeSDK();
  }, []);

  return (
    // Your React Native components go here
    <></>
  );
};

export default App;
0.0.25

6 months ago

0.0.30

5 months ago

0.0.31

5 months ago

0.0.32

5 months ago

0.0.33

5 months ago

0.0.26

6 months ago

0.0.27

6 months ago

0.0.28

5 months ago

0.0.29

5 months ago

0.0.20

10 months ago

0.0.21

10 months ago

0.0.10

10 months ago

0.0.22

10 months ago

0.0.11

10 months ago

0.0.23

10 months ago

0.0.12

10 months ago

0.0.24

9 months ago

0.0.13

10 months ago

0.0.14

10 months ago

0.0.15

10 months ago

0.0.9

10 months ago

0.0.16

10 months ago

0.0.8

10 months ago

0.0.17

10 months ago

0.0.18

10 months ago

0.0.19

10 months ago

0.0.7

11 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.1

12 months ago