npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gopersonal-react-native-sdk

v0.0.24

Published

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

Downloads

70

Readme

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;