Overview
The Nudge React Native Package allows you to integrate the core analytics and experience triggering nudge package provided by Nudge into your React Native application. With this package, you can engage your users with interactive games and promotions. Nudge Core is the required repository which you would need to integrate with
To integrate with Nudge Core, you need to first install thenudgecore_v2
package into your React Native project. Find the latest version of nudgecore_v2
Usage
After adding the Nudge Core package to your project's dependencies in the package.json file, you need to run npm install
command to fetch the package and make it accessible in your React Native project. This command will download the package and its dependencies, allowing you to import and utilize the Nudge package in your code.
To initialize the NudgeCore class with a reusable variable name and access all its functions through it, follow these steps:
Import the NudgeCore package into your Dart file:
import Nudge from 'nudgecore_v2';
Create an instance of the Nudge class with your desired variable name and add:
token
(required): The secret key obtained from the Nudge website, used for authentication.
var nudge = Nudge(<YOUR_API_KEY>,debugMode:bool);
Step 1: Adding NudgeProvider
Nudge Provider enables integration with the Nudge packages and by default requires instance of Nudge
class and the lists of the plugins that you want to integrate.
Example
function YourApp() {
const nudgeProvider = useNudgeProvider(
plugins: [NudgeQuizUi(),...],
instance: {nudge}
);
return (
<SafeAreaView style={backgroundStyle} ref={nudgeProvider.navigatorRef} >
</SafeAreaView>
)
}
Step 2: Initializing session
Whenever a distinct user ID which is used to identify users at the client's end is defined, call the initSession function to initialize the user session.
await nudge.userIdentifier(externalId: "EXTERNAL_ID");
You can also send more user attributes along with the user ID for making segments of audiences.
await nudge.userIdentifier(externalId: "EXTERNAL_ID",name: "NAME",email: "EMAIL",phoneNumber: "PHONE_NUMBER",properties:
{
"age": 27,
"gender": "M",
"country":"US",
});
Step 3: Start Tracking Events
Make sure you have initialized the session before tracking
To track an event, simply call
await nudge.track(event:'EVENT_NAME');
You can also add event properties for analytics and .making segments of users based on the properties of their events performed for custom audience experiences.
Important:
- Your event name should be one word and it cannot have any special characters except underscore ("_")
For example : An event name "app-open" is not acceptable, but an event name "app_open" is.- Event name can only start with an alphabet.
For example : An event name "1event" is not acceptable, but an event name "event1" is.- Event name cannot have more than 100 characters
await nudge.track(event:'EVENT_NAME',
properties: <String, dynamic>{
"product": "Fortune Cookies",
"quantity": 5,
"countryOfExport":"US",
});