0.0.6 • Published 10 months ago

expo-persona-click v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

PersonaClick SDK for Expo

This SDK provides integration with PersonaClick services for Expo applications, offering features like push notifications, user tracking, recommendations, and more.

Features

  • Push notifications (Firebase Cloud Messaging)
  • User profile management
  • Event tracking
  • Product recommendations
  • Search functionality
  • Cart management
  • User segments
  • Subscription triggers

Installation

  1. Install the SDK package:
npm install expo-persona-click
# or
yarn add expo-persona-click
  1. Install required dependencies:
npx expo install @react-native-firebase/app @react-native-firebase/messaging @react-native-async-storage/async-storage expo-device expo-application

Firebase Setup

  1. Create a new Firebase project or use an existing one at Firebase Console

  2. Add your iOS and Android apps to the Firebase project:

    • For iOS: Use your app's Bundle Identifier from app.json
    • For Android: Use your app's Package name from app.json
  3. Download the configuration files:

    • iOS: Download GoogleService-Info.plist
    • Android: Download google-services.json
  4. Place these files in your project's root directory

Configuration

app.config.js / app.json

Add the following configuration to your app.config.js or app.json:

{
  "expo": {
    // ... other config
    "android": {
      "googleServicesFile": "./google-services.json",
      "package": "your.package.name",
      "permissions": ["POST_NOTIFICATIONS"]
    },
    "ios": {
      "googleServicesFile": "./GoogleService-Info.plist",
      "bundleIdentifier": "your.bundle.identifier"
    },
    "plugins": [
      "@react-native-firebase/app",
      "@react-native-firebase/messaging"
    ]
  }
}

Usage

Initialize the SDK

import ExpoPersonaClick from 'expo-persona-click';

const sdk = new ExpoPersonaClick({
  shop_id: 'YOUR_SHOP_ID',
  stream: 'YOUR_STREAM', // optional
  debug: true, // optional
  autoSendPushToken: true // optional
});

// Initialize the SDK
await sdk.init();

Push Notifications

// Initialize push notifications
await sdk.initPush(
  (notification) => {
    // Handle notification click
    console.log('Notification clicked:', notification);
  },
  (notification) => {
    // Handle notification received in foreground
    console.log('Notification received:', notification);
  },
  (notification) => {
    // Handle notification received in background
    console.log('Background notification:', notification);
  }
);

// Use Firebase only (Android)
sdk.firebase_only(true);

User Profile Management

// Set user profile
await sdk.setProfile({
  user_id: 'user123',
  email: 'user@example.com',
  phone: '+1234567890',
  first_name: 'John',
  last_name: 'Doe',
  gender: 'M',
  birthday: '1990-01-01', // YYYY-MM-DD format
  city: 'New York',
  country: 'US'
});

// Get user profile
const profile = await sdk.getProfile('user123');

Event Tracking

// Track custom event
sdk.trackEvent('add_to_wishlist', {
  item_id: 'product123',
  price: 99.99
});

// Track predefined event
sdk.track('view_item', {
  item_id: 'product123',
  price: 99.99
});

Product Recommendations

// Get recommendations
const recommendations = await sdk.recommend('recently_viewed', {
  limit: 10,
  user_id: 'user123'
});

Search

// Search products
const searchResults = await sdk.search({
  query: 'shoes',
  limit: 20,
  page: 1
});

// Blank search
const blankResults = await sdk.searchBlank();

Cart Management

// Get cart information
const cartInfo = await sdk.cart();

User Segments

// Add user to segment
sdk.segments('add', {
  user_id: 'user123',
  segment_id: 'premium_users'
});

// Remove user from segment
sdk.segments('remove', {
  user_id: 'user123',
  segment_id: 'premium_users'
});

Subscription Triggers

// Subscribe to price drop
sdk.triggers('subscribe_for_product_price', {
  email: 'user@example.com',
  item: 'product123',
  price: 199.99
});

// Subscribe to stock availability
sdk.triggers('subscribe_for_product_available', {
  email: 'user@example.com',
  item: 'product123'
});

Troubleshooting

Common Issues

  1. Push notifications not working:

    • Verify Firebase configuration files are correctly placed
    • Check app.json/app.config.js configuration
    • Ensure proper permissions are set
    • Check if Firebase token is successfully generated
  2. SDK initialization fails:

    • Verify shop_id is correct
    • Check internet connectivity
    • Enable debug mode for detailed logs

Debug Mode

Enable debug mode during initialization to see detailed logs:

const sdk = new ExpoPersonaClick({
  shop_id: 'YOUR_SHOP_ID',
  debug: true
});

License

MIT License. See LICENSE file for details.