@bitespeed/react-native-sdk
v0.0.16
Published
Bitespeed React Native SDK - Supports user identification, product events, notification event webhooks and more...
Downloads
859
Readme
Bitespeed React Native SDK
© Bitespeed
This SDK is designed for React Native applications to facilitate tracking of user events, product interactions, and notifications. It ensures accurate identification of users and provides seamless integration with the Bitespeed API.
Features
- User Identification: Identify users with contact details (email/phone).
- Notification Tracking: Track notification events like delivery and clicks.
- Product Event Tracking: Track events such as product views and add-to-cart.
Setup Instructions
Install the Bitespeed SDK
To integrate the Bitespeed SDK into your React Native project:
npm install @bitespeed/react-native-sdk
Set Up Firebase for FCM (Push Notifications)
To setup firebase for react-native, follow the instructions here for both Android and iOS.
Set up Firebase Cloud Messaging (FCM) for Push Notifications
To set up FCM, follow the official Firebase documentation here.
Add FCM Receiving Message Handlers
Add the following code to your
App.js
file to receive FCM messages:import messaging from '@react-native-firebase/messaging' messaging().onMessage(async (remoteMessage) => { // call the trackNotification method here }) messaging().setBackgroundMessageHandler(async (remoteMessage) => { // call the trackNotification method here })
Refer to the official Firebase documentation here for more details.
Important Notes:
- Make sure to add the
google-services.json
file to your android project andGoogleService-Info.plist
to your iOS project. - Both Android and iOS require additional setup for FCM. Refer to the official Firebase documentation for more details.
- Ask the user for permission to receive push notifications.
- Make sure to call the
trackNotification
method in theonMessage
andsetBackgroundMessageHandler
handlers to track notification events.
Usage
Initialize the SDK
Initialize the SDK with your API key and shop URL:
import BitespeedSDK from 'bitespeed-sdk' const sdk = BitespeedSDK.getInstance('<SHOP_URL>.myshopify.com', 'your-api-key')
Identify User
Identify the user with their details and FCM token:
await sdk.identify( { email: '[email protected]', phone: '1234567890', firstName: 'John', lastName: 'Doe', }, 'fcm-token' // Here you can pass the FCM token )
Track Product Events
Track product-related events such as viewing or adding to the cart:
await sdk.trackProductEvent('productView', { event: { id: 'prod-123', name: 'Sample Product', price: 100, handle: 'sample-product', }, })
Track Notification Events
Track notification events like clicks or delivery:
await sdk.trackNotification('clicked', 'notif-123')
Supported Events
Product Events:
productView
- when the user views a product.addToCart
- when the user adds a product to the cart.
Notification Events:
delivered
- when the notification is delivered to the user.clicked
- when the user clicks on a notification.
Error Handling
The SDK will throw errors if:
API key
orshop URL
is missing during initialization.- User is not identified before tracking events.
- Unsupported events are passed to tracking methods.
Contact
For further assistance, reach out to Bitespeed Support at [email protected].