The Connecthings React Native plugin allows you to access to the GDPR methods and In-App actions methods from the js code.

Nevertheless, the configuration of the SDK must still must done at the ios and android app level.

A react-native demo application is available on github to shows you a concrete implementation.

You just have to clone the https://github.com/Connecthings/react-app-demo repo

Initialize the SDK

Follow the iOS and Android minutes quickstart to initialize the SDK at the native app level.

Add the plugin to your project

  • Add the plugin to your npm dependecies:
npm install react-native-connecthings@^4.6.8 --save
  • Link the plugin with your project_open
react-native link react-native-connecthings

Being compliant with GDPR

The following methods allow your application to be compliant to GDPR.

You can find out more about this by reading our GDPR tutorial.

import RNConnecthings from 'react-native-connecthings';

RNConnecthings.optinsNeverAsked(function(error, optinsNeverAsked) {
  if (optinsNeverAsked) {
    //Ask optins for GRPD
  }
});
//give the optin to the SDK
//USER_DATA is mandatory
RNConnecthings.updateOptin("USER_DATA", true);
RNConnecthings.updateOptin("STATUS", true);
//Notify the SDK that all optins has been given - must be called each time you update optin
RNConnecthings.allOptinsAreUpdated()

RNConnecthings.isOptinAuthorized("USER_DATA", function(error, optinAuthorized) {
  if (optinAuthorized) {
    //Actions if optin has been given
  }
});

The In-App actions

The following methods allow your application to use the in-app actions.

In-app Actions are actions/messages triggered on a user's phone when the application is active in the foreground.

You can find out more about this by reading our In-App actions tutorial.

1- To listen the in-App actions, your application must have initialized a connecthings event emitter:

const connecthingsManagerEmitter = Platform.select({
  ios: new NativeEventEmitter(RNConnecthings),
  android: DeviceEventEmitter,
});

2- From the connecthings event emitter, your application can subscribe to receive:

  • the CreateInAppAction event: event which indicates that there is a place with a in-App action available
  • the RemoveInAppAction event: event which indicates that the place is no more detected, so it is time to remove the in-AppAction
this.subscriptionCreate = connecthingsManagerEmitter.addListener(
	'CreateInAppAction',
	(inAppAction) => console.log("in AppAction tag:", inAppAction.tag)) // can access inAppAction.id or inAppAction.tag
);

this.subscriptionRemove = connecthingsManagerEmitter.addListener(
	'RemoveInAppAction',
	(inAppAction) => console.log("in AppAction tag:", inAppAction.id)
);

3- Your application must ask the SDK to start listening for the In-App Actions:

RNConnecthings.startListeningInAppAction()

4- Think to unsubcribe from the emmitter

this.subscriptionCreate.remove()
this.subscriptionRemove.remove()

5- Think to stop listening the In-App actions:

RNConnecthings.stopListeningInAppAction()