4.0.0 • Published 2 years ago

react-native-followanalytics v4.0.0

Weekly downloads
30
License
IST
Repository
-
Last release
2 years ago

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:

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-followanalytics and add RNFollowanalytics.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNFollowanalytics.a to your project's Build PhasesLink Binary With Libraries
  4. 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

  1. 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 the getPackages() method
  1. 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')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-followanalytics')
  • Add new RNFollowanalyticsReactNativeSdkPackage() to the List<IReactPackage> returned by the Packages 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());
	}
}
4.0.0

2 years ago

3.3.0

3 years ago

3.2.0

3 years ago

3.1.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.1.1

4 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago