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

Latest version **0.0.52** (published 2026-11-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install gopersonal-react-native-sdk
pnpm add gopersonal-react-native-sdk
yarn add gopersonal-react-native-sdk
bun add gopersonal-react-native-sdk
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.52 |
| Published | 2026-11-19 |
| First published | 2024-08-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 70.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | gopersonal |

## Links

- npm: https://www.npmjs.com/package/gopersonal-react-native-sdk
- npm.io page: https://npm.io/package/gopersonal-react-native-sdk

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^10.0.0
- [axios](https://npm.io/package/axios.md) ^1.7.3
- [react-native-get-random-values](https://npm.io/package/react-native-get-random-values.md) ^1.11.0

## Recent versions

- 0.0.52 (latest) — 2026-11-19
- 0.0.50 — 2026-03-16
- 0.0.49 — 2026-03-16
- 0.0.48 — 2026-03-16
- 0.0.47 — 2026-02-19
- 0.0.46 — 2025-11-25
- 0.0.45 — 2025-08-21
- 0.0.44 — 2025-08-07
- 0.0.43 — 2025-07-10
- 0.0.42 — 2025-06-25
- 0.0.41 — 2025-05-15
- 0.0.40 — 2025-04-29
- 0.0.39 — 2025-04-24
- 0.0.38 — 2025-04-24
- 0.0.37 — 2025-04-24
- … 34 more at https://npm.io/package/gopersonal-react-native-sdk/versions

## 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:

```bash
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.

### JavaScript Usage

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

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

### TypeScript Usage

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

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

// TypeScript will provide autocomplete and type checking
const searchResults = await SDK.search('query', { jsonFilter: { category: 'electronics' } });
```

## Core Functionality

### User Login

Log in a user to the SDK:

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

### User Logout

Log out the current user:

```javascript
await SDK.logout();
```

### Search

Perform a search query and get results:

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

### Search V2 (Semantic Search with AI)

Use the new AI-powered semantic search with reranking:

```javascript
// Basic search
const results = await SDK.searchV2('wireless headphones');

// With options
const results = await SDK.searchV2('wireless headphones', {
  limit: 50,
  embedding_mode: 'gemma_bm25',
  reranker: 'qwen',
  filters: { brand: ['Sony', 'Bose'], color: ['black'] }
});

// Response structure
// {
//   hits: [{ id, score, payload: { name, price, url, imgs, ... } }],
//   hits_count: 50,
//   search_id: 'abc123',
//   total_results: 150,
//   facets: { brand: { display_name: 'Marca', values: [...] } },
//   is_occasion_search: false
// }
```

### Autocomplete V2

Get search suggestions while typing:

```javascript
const suggestions = await SDK.autocompleteV2('headph');
```

### Search Page V2 (Pagination)

Paginate through search results using the search_id from a previous search:

```javascript
const page2 = await SDK.searchPageV2('search-id-from-previous-search', 2, {
  page_size: 50,
  filters: { brand: ['Sony'] },
  sort_by: 'price-low-high'
});
```

### Get Facets V2

Get available facets/filters for the project:

```javascript
const facets = await SDK.getFacetsV2();
```

### Get Similar Products V2

Get products similar to a specific product:

```javascript
const similarProducts = await SDK.getSimilarProductsV2('product-id');
```

### Get Product by ID V2

Get a single product by its ID:

```javascript
const product = await SDK.getProductByIdV2('product-id');
```

### Search by Image

Perform a search query using an image file:

```javascript
const imageSearchResults = await SDK.imageSearch(file);
```

### Get Content

Retrieve personalized content by content ID:

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

### Personalization impressions and clicks

After initializing the SDK, fetch with explicit options and register the impression
when the personalization becomes visible:

```javascript
const content = await SDK.getContent('app-popup', {
  itemAttributes: '*',
  impressionStatus: 'pending',
});

// On display, for a matched variant:
await SDK.createContentImpression(content.impressionId, {
  content: content.experienceId,
  target: content.targetId,
  variantId: content.variantId,
});

// On its action, after creation completes:
await SDK.clickContentImpression(
  await SDK.getContentImpressionId(content.experienceId),
  { content: content.experienceId },
);
```

Impressions are deduplicated by project, session and content; the returned server
ID is persisted. Closing a personalization should not call the click method.
`getContent` options replace its defaults, so include `itemAttributes` explicitly.
`openImpression` keeps its existing `/personal/impression` route.

### Get NPS

Retrieve Net Promoter Score content:

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

### Addon Methods

Interact with addon endpoints.

```javascript
const addonData = await SDK.requestAddonData('endpoint');

const addonDataWithParams = await SDK.requestAddonData('endpoint', {
  params: { id: 123, filter: 'active' }
});

const postResponse = await SDK.requestAddonData('endpoint', {
  method: 'post',
  data: { name: 'Nuevo item', status: 'active' }
});

const putResponse = await SDK.requestAddonData('endpoint', {
  method: 'put',
  data: { id: 123, status: 'completed' }
});

const deleteResponse = await SDK.requestAddonData('endpoint', {
  method: 'delete',
  params: { id: 123 }
});

const responseWithOptions = await SDK.requestAddonData('endpoint', {
  method: 'get',
  timeout: 5000,
  debug: true
});
```

### Add Interaction

Capture user interactions to enhance personalization:

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

### Add Interaction State

Add a state to the interaction flow:

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

### Open Impression

Mark an impression as opened:

```javascript
await SDK.openImpression('impressionId');
```

## Push Notifications

> Note for Expo Go users: Expo Go does not include the native Firebase Messaging module. As of this SDK version, Firebase messaging is loaded lazily and guarded, so importing the SDK features will work in Expo Go without crashing. Push-related methods will no-op if the native module is unavailable. To test or use push notifications, build a custom development client.

### Initialize Firebase

Set up Firebase for push notifications:

```javascript
await SDK.initializeFirebase();
```

### Request Notification Permission

Request permission to send notifications (required for iOS):

```javascript
const permissionGranted = await SDK.requestNotificationPermission();
```

### Get Firebase Token

Retrieve the Firebase token for the device:

```javascript
const token = await SDK.getFirebaseToken();
```

### Send Token to Backend

Send the Firebase token to your backend:

```javascript
await SDK.sendTokenToBackend(token);
```

### Handle Incoming Messages

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

```javascript
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:

```javascript
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:

```javascript
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:

```javascript
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;
```

---
_Source: https://npm.io/package/gopersonal-react-native-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
