0.6.0 • Published 1 year ago

datasenses-react-native-sdk v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

datasenses-react-native-sdk

SDK

Installation

npm install datasenses-react-native-sdk

Android Integration

1: Add the following to your dependencies section in project/build.gradle:

classpath('com.google.gms:google-services:4.4.1')

2: Add the end of the app/build.gradle file, add the following:

apply plugin: "com.google.gms.google-services"

3: Add google-services.json downloaded from DataSenses's dashboard to the app folder

img.png

4: Add Deeplink Listener. Add the following section in app/AndroidManifest.xml

<intent-filter>
  <action android:name="android.intent.action.VIEW"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <category android:name="android.intent.category.BROWSABLE"/>
  <data android:scheme="<your host>"/>
</intent-filter>

Test deeplink with your App.jsx

adb shell am start -W -a android.intent.action.VIEW -d "https://example.com/details/123?utm_source=google" com.datasensesreactnativesdk

img_1.png

SDK integration in app

1: You should use the following import statement on top of your .js file:

import DataSensesSDK from "datasenses-react-native-sdk";

In your App.js file, add the following code to initialize the DataSenses SDK:

export default function App(): React.JSX.Element {
  const token =
    '3g0PGOAdW9LW3LFiipOh1zdlrLXwuPsb9qirhxd3yy97DHKsJh-RzEGdstvQkYbuU2BkjgcVOEPYfID7BOE';
  DataSensesSDK.initialize(token)
}
  1. Add DataSenses deeplink listener to your react-native app
    DataSensesSDK.listenDeeplink(url);

Example code

import { Linking } from 'react-native';

function App(): React.JSX.Element {
  useEffect(() => {
    const handleDeepLink = (event: any) => {
      const url = event.url;
      if (url) {
        console.log('Received deep link:', url);
        DataSensesSDK.listenDeeplink(url);
        console.log('Send event');
      }
    };
    const subscription = Linking.addEventListener('url', handleDeepLink);
    Linking.getInitialURL().then((url) => {
      if (url) {
        handleDeepLink({ url });
      }
    });
    return () => {
      subscription.remove();
    };
  }, []);

  return (
    <NavigationContainer linking={linking}>
      <Stack.Navigator initialRouteName={"Home"}>
        <Stack.Screen name="Home" component={HomeScreen} />
        <Stack.Screen name="Details" component={DetailsScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

Send events

const eventName = 'login';
const attributes = {
  customer_id: '123456',
  email: 'your_email@dev.xyz',
  phone: '84999999999',
};
DataSensesSDK.trackEvent(eventName, attributes);

License

MIT

0.6.0

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.1.0

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago