react-native-followanalytics v4.0.0
FollowAnalytics React Native SDK
Getting started
Requirements
- React Native >= 0.58.0
- Reac Native cli >= 2.0.1
- Cocoapods (iOS)
- Gradle (Android)
Mostly automatic installation
$ npm install react-native-followanalytics --save
$ react-native link react-native-followanalytics
Manual installation
$ npm install PATH_FOR_THE_SDK --save
$ react-native link react-native-followanalytics
iOS
If you're using Cocoapods add the following to your application target on the Podfile
:
use_frameworks!
pod 'FollowAnalytics', path: '../node_modules/react-native-followanalytics/ios/Frameworks'
Run pod install
to add the required dependencies.
If you use it manually follow the following steps:
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-followanalytics
and addRNFollowanalytics.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNFollowanalytics.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)
You'll still need to integrate the FollowAnalytics iOS SDK. Please follow the Install using Cocoapods and Initialize with your API key from the FollowAnaltyics Dev Portal.
In your AppDelegate.h
add the following lines:
#import <FollowAnalytics/FollowAnalytics.h>
In your AppDelegate.m
add the following lines inside the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method
FollowAnalyticsConfiguration* configuration = [FollowAnalyticsConfiguration
configurationWith:^(FollowAnalyticsMutableConfiguration * _Nonnull c) {
c.apiKey = @"YOUR_API_KEY_HERE";
c.appGroup = @"YOUR_APP_GROUP_HERE";
c.debug = true;
c.isDataWalletEnabled = YES;
c.onDataWalletPolicyChange = ^{
[self policyDidChange];
};
}];
[FollowAnalytics startWithConfiguration:configuration
startupOptions:launchOptions];
[FAFollowApps storeMessagesPush:YES inApp:YES];
[FABadge enable];
[FAFollowApps enableGeoffencing];
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.followanalytics.reactnative.sdk.RNFollowAnalyticsPackage;
to the imports at the top of the file - Add
new RNFollowAnalyticsPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-followanalytics' project(':react-native-followanalytics').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-followanalytics/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-followanalytics')
- Add
new RNFollowanalyticsReactNativeSdkPackage()
to theList<IReactPackage>
returned by thePackages
method
You'll also need to integrate the FollowAnalytics Android SDK to the native part of the application. Please follow the Install using Gradle and Initialize with your API key from the FollowAnaltyics Dev Portal.
Available methods
The FollowAnalytics React Native SDK makes use of callbacks to get results from method calls, where it applies. Here+s a list of the available methods:
// all methods using callbacks follow the pattern:
functionName: function((error, result) => {
if (error) {
... treat error case here ...
} else {
... treat success case here ...
}
});
getOptInAnalytics((error, result) => { ... }});
setOptInAnalytics(isOptIn);
requestNotificationAuthorization(); // iOS only
requestProvisionalNotificationAuthorization(); // iOS only
getUserId(error, result) => { ... }});
setUserId(user_id);
getDeviceId(error, result) => { ... }});
logEvent("anEventName", "anEventDetail");
logError("anErrorName", "anErrorDetail");
logLocationCoordinates(48.8410646, 2.3210844);
logLocationPosition(position); // Takes a Position object provided by the Geolocation API
Gender: {
MALE: 1,
FEMALE: 2,
OTHER: 3
}
UserAttributes: {
setFirstName("aFirstName");
setLastName("aLastName");
setEmail("something@domain.com");
setDateOfBirth("2020-02-28"); // Takes a string (yyyy-MM-dd)
setGender(FollowAnalytics.Gender.MALE); // Also can use FEMALE || OTHER
setCountry("France");
setCity("Paris");
setRegion("Île-de-France");
setProfilePictureUrl("https://picture_url");
setInteger("aKey", 100);
setDouble("aKey", 10.5);
setString("aKey", "aString");
setBoolean("aKey", true); // Or false
setDate("aKey", "2020-02-28"); // Takes a string (yyyy-MM-dd)
setDateTime("aKey", "2020-02-28 18:46:19 +0200"); // Takes a string (yyyy-MM-dd HH:mm:ss Z)
clear("aKey");
addToSet("aKey", ...elements);
removeFromSet("aKey", ...elements);
clearSet("aKey");
}
Push: {
getAll(error, result) => { ... }});
get(id, (error, result) => { ... });
markAsRead(...ids);
markAsUnread(...ids);
delete(...ids);
}
InApp: {
pauseCampaignDisplay();
resumeCampaignDisplay();
getAll((error, result) => { ... });
get(id, (error, result) => { ... });
markAsRead(...ids);
markAsUnread(...ids);
delete(...ids);
}
DataWallet: {
getPolicy((error, result) => { ... });
isRead((error, result) => { ... });
setIsRead(value);
}
GDPR: {
requestToAccessMyData();
requestToDeleteMyData();
}
Usage
At the top of your javascript files add:
import FollowAnalytics from "react-native-followanalytics";
You can now call the methods listed above using FollowAnalytics.method_name(arguments)
. Some examples:
FollowAnalytics.logEvent("Page view", "Homepage);
FollowAnalytics.UserAttributes.setFirstName("Michel");
FollowAnalytics.getDeviceId: function(error, result) => {
if (error) {
console.log("Error fetching deviceId");
console.log(error);
} else {
console.log("Got me a deviceId, and it's: " + result.toString());
}
}