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.14

Published

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

Downloads

555

Readme

Gopersonal React Native SDK

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

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');

Usage

Once the SDK is initialized, you can use its methods to capture user behavior and fetch personalized content.

User Login

Log in a user to the SDK:

await SDK.login('customer-id');

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');

Add Interaction

Capture user interactions to enhance personalization:

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

Example

Here is a complete 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');

        // Log in the user
        await SDK.login('customer-id');

        // 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' });
      } catch (error) {
        console.error('Error initializing SDK:', error);
      }
    };

    initializeSDK();
  }, []);

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

export default App;

This documentation provides a comprehensive guide to installing, importing, initializing, and using the GoPersonal SDK for React Native, along with a practical example to help you get started.

Enabling Push Notifications

To enable push notifications in your React Native app using the GoPersonal SDK, follow these steps:

1. Firebase Project Setup

  1. Create a new Firebase project or use an existing one at Firebase Console.
  2. Add your Android and iOS apps to the Firebase project.

2. Configure Android

  1. Download the google-services.json file from Firebase Console.

  2. Place it in your project at android/app/google-services.json.

  3. Modify android/build.gradle:

    buildscript {
      dependencies {
        // ... other dependencies
        classpath 'com.google.gms:google-services:4.3.15'
      }
    }
  4. Modify android/app/build.gradle:

    apply plugin: 'com.android.application'
    apply plugin: 'com.google.gms.google-services'

3. Configure iOS

  1. Download the GoogleService-Info.plist file from Firebase Console.

  2. Place it in your project at ios/GoogleService-Info.plist.

  3. In the ios directory, run:

    cd ios && pod install

4. Initialize Firebase in Your App

In your main app file (e.g., App.js), add the following:

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

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

        // Initialize Firebase
        await SDK.initializeFirebase();

        // Request permission (iOS only)
        const permissionGranted = await SDK.requestNotificationPermission();
        if (!permissionGranted) {
          console.log('Notification permission not granted');
          return;
        }

        // Get the Firebase token
        const token = await SDK.getFirebaseToken();

        // Send the token to your backend
        await SDK.sendTokenToBackend(token);

        // Handle incoming messages when the app is in the foreground
        const unsubscribe = SDK.onMessage(async remoteMessage => {
          console.log('Received foreground message:', remoteMessage);
          // Handle the message (e.g., show a local notification)
        });

        // Handle notification opened app
        SDK.onNotificationOpenedApp(remoteMessage => {
          console.log('Notification caused app to open from background state:', remoteMessage);
          // Handle the notification (e.g., navigate to a specific screen)
        });

        // Check whether an initial notification is available
        const initialNotification = await SDK.getInitialNotification();
        if (initialNotification) {
          console.log('Notification caused app to open from quit state:', initialNotification);
          // Handle the initial notification (e.g., navigate to a specific screen)
        }

        return unsubscribe;
      } catch (error) {
        console.error('Error setting up push notifications:', error);
      }
    };

    setupPushNotifications();
  }, []);

  return (
    // Your app components
  );
};

export default App;

5. Testing Push Notifications

To test push notifications:

  1. Run your app on a physical device or emulator.
  2. Use the Firebase Console to send a test message to your app.
  3. Verify that the notification is received and handled correctly.

Remember to handle the received notifications appropriately in your app, such as displaying them to the user or updating the app's state.

For more advanced usage and customization options, refer to the @react-native-firebase/messaging documentation.