A React Native plugin for Flurry SDK
Flurry Push for messaging is now supported by our plugin!
-
Install Flurry SDK module by
npm
npm install react-native-flurry-sdk --save
-
Link React Native dependency
react-native link react-native-flurry-sdk
-
Add Flurry JS code
import Flurry from 'react-native-flurry-sdk';
-
By default, Flurry adds
INTERNET
andACCESS_NETWORK_STATE
permissions to optimize analytics data. Please see Manual Flurry Android SDK Integration for the other recommended options. -
To improve analytics identities, please see Manual Flurry Android SDK Integration for adding Google Play Services library in your app by including the following in your
build.gradle
file:dependencies { // Recommended to add Google Play Services implementation 'com.google.android.gms:play-services-base:15.0.1' implementation 'com.google.android.gms:play-services-ads:15.0.1' }
-
Flurry Push
In order to use Flurry Push for Android, please follow the additional steps below:-
Flurry Push requires your projects to initialize Flurry from your Application class. Please do the Flurry setup in
MainApplication.onCreate()
. With the same APIs as the JavaScript version.new FlurryModule.Builder() .withCrashReporting(true) .withLogEnabled(true) .withLogLevel(Log.VERBOSE) .withMessaging(true) .build(this, FLURRY_ANDROID_API_KEY);
-
Follow Set up a Firebase Cloud Messaging client app on Android. Complete "Set up Firebase and the FCM SDK" step for adding Firebase to your Android project. There should be a file
google-services.json
in your project'sandroid/app
folder now. You do not need to provide any setup codes here. Yourbuild.gradle
will look like:// android/build.gradle (project-level) buildscript { dependencies { classpath 'com.google.gms:google-services:4.0.1' } }
// android/app/build.gradle apply plugin: 'com.google.gms.google-services' dependencies { implementation 'com.google.firebase:firebase-core:16.0.3' implementation 'com.google.firebase:firebase-messaging:17.3.2' }
-
Set up "Android Authorization" in Flurry Push Authorization.
-
-
Please note that react-native link may add react-native-flurry-sdk podspec to your Podfile. If you are not using CocoaPods or your Podfile looks roughly like the one described here, no further action is needed.
If you are migrating from version<3.0.0 and your Podfile does NOT have any other dependency than Flurry, please deintegrate CocoaPods from your project. You may also need to manually remove Podfile and xcworkspace files.
cd ios pod deintegrate
If you have a Podfile only for native dependencies, please remove
pod 'Flurry-iOS-SDK/FlurrySDK'
from your Podfile, re-runpod install
, removereact-native-flurry-sdk.podspec
, and executereact-native link
again.rm node_modules/react-native-flurry-sdk/react-native-flurry-sdk.podspec react-native unlink react-native-flurry-sdk && react-native link react-native-flurry-sdk
-
Flurry Push
To set up Flurry Push, please take the following steps.- Open your
.xcodeproj
file using Xcode. It is usually located under theios
directory of your React Native app. - Go to "Capabilities" tab and enable Push Notifications.
- Enable Background Modes (Background Fetch and Remote Notifications turned on).
Now your
Info.plist
should contain the following items. For more information, please see Push Setup. - Set up "iOS Authorization" in Flurry Push Authorization.
- Open your
-
index.js
import { AppRegistry } from 'react-native'; import { name as appName } from './app.json'; import App from './App'; import Flurry from 'react-native-flurry-sdk'; // Init Flurry once as early as possible recommended in index.js. // For each platfrom (Android, iOS) where the app runs you need to acquire a unique Flurry API Key. // i.e., you need two API keys if you are going to release the app on both Android and iOS platforms. new Flurry.Builder() .withCrashReporting(true) .withLogEnabled(true) .withLogLevel(Flurry.LogLevel.DEBUG) .build(FLURRY_ANDROID_API_KEY, FLURRY_IOS_API_KEY); AppRegistry.registerComponent(appName, () => App);
-
App.js
import React, { Component } from 'react'; import { Platform, StyleSheet, Text, View } from 'react-native'; import Flurry from 'react-native-flurry-sdk'; type Props = {}; export default class App extends Component<Props> { constructor(props) { super(props); // Example to get Flurry versions. Flurry.getVersions().then((versions) => { console.log("Versions: " + versions.agentVersion + " : " + versions.releaseVersion + " : " + versions.sessionId); }); } render() { // Set users preferences. Flurry.setAge(36); Flurry.setGender(Flurry.Gender.FEMALE); Flurry.setReportLocation(true); // Log Flurry events. Flurry.logEvent("React Native Event"); Flurry.logEvent("React Native Timed Event", {param: 'true'}, true); ... Flurry.endTimedEvent("React Native Timed Event"); Flurry.onPageView(); return ( <View style={styles.container}> ... </View> ); } } ...
-
index.js / Messaging.js
// To enable Flurry Push for Android, please duplicate Builder setup in your MainApplication.java. new Flurry.Builder() .withMessaging(true) ... // Optionally add a listener to receive messaging events, and handle the notification. // Please call required Flurry.willHandleMessage(boolean) when received event types of // 'NotificationReceived' or 'NotificationClicked' as soon as possible to avoid delay. Flurry.addMessagingListener((message) => { if (message.Type === 'NotificationReceived') { Flurry.willHandleMessage(false); } else if (message.Type === 'NotificationClicked') { Flurry.willHandleMessage(false); } Flurry.printMessage(message); });
See Android-(FlurryAgent) / iOS-(Flurry) for the Flurry references.
-
Methods to initialize Flurry
Flurry.Builder.withCrashReporting(crashReporting = true); Flurry.Builder.withContinueSessionMillis(sessionMillis = 10000); Flurry.Builder.withIncludeBackgroundSessionsInMetrics(includeBackgroundSessionsInMetrics = true); Flurry.Builder.withLogEnabled(enableLog = true); Flurry.Builder.withLogLevel(logLevel = Flurry.LogLevel.WARN); // LogLevel = { VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT } Flurry.Builder.withMessaging(enableMessaging = true); Flurry.Builder.build(apiKeyAndroid: string, apiKeyIos: string); // preferred; passing null if not available Flurry.Builder.build(apiKey: string); // use when only single platform is supported, or shared (not recommended)
-
Methods must be called prior to invoking init (Deprecated, please use Flurry.Builder instead)
Flurry.withCrashReporting(crashReporting = true); Flurry.withContinueSessionMillis(sessionMillis = 10000); Flurry.withIncludeBackgroundSessionsInMetrics(includeBackgroundSessionsInMetrics = true); Flurry.withLogEnabled(enableLog = true); Flurry.withLogLevel(logLevel = Flurry.LogLevel.WARN); // LogLevel = { VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT }
Flurry.init(apiKeyAndroid: string, apiKeyIos: string); // preferred; passing null if not available Flurry.init(apiKey: string); // use when only single platform is supported, or shared (not recommended)
-
Methods to set users preferences
Flurry.setAge(age: number); Flurry.setGender(gender: Flurry.Gender); // Gender = { MALE, FEMALE } Flurry.setReportLocation(reportLocation: boolean); Flurry.setSessionOrigin(originName: string, deepLink: string); Flurry.setUserId(userId: string); Flurry.setVersionName(versionName: string); Flurry.addOrigin(originName: string, originVersion: string); Flurry.addOrigin(originName: string, originVersion: string, originParameters: {}); Flurry.addSessionProperty(name: string, value: string);
-
Methods to get Flurry versions
Flurry.getVersions(): Promise<{agentVersion: number, releaseVersion: string, sessionId: string}>; Flurry.getVersions((msg) => errorCallback, (agentVersion, releaseVersion, sessionId) => successCallback);
-
Methods to log Flurry events
Flurry.logEvent(eventId: string); Flurry.logEvent(eventId: string, timed: boolean); Flurry.logEvent(eventId: string, parameters: {}); Flurry.logEvent(eventId: string, parameters: {}, timed: boolean); Flurry.endTimedEvent(eventId: string); Flurry.endTimedEvent(eventId: string, parameters: {}); Flurry.onPageView(); Flurry.onError(errorId: string, message: string, errorClass: string); Flurry.onError(errorId: string, message: string, errorClass: string, errorParams: {}); Flurry.logBreadcrumb(crashBreadcrumb: string); Flurry.logPayment(productName: string, productId: string, quantity: number, price: number, currency: string, transactionId: string, parameters: {}); // Android, see setIAPReportingEnabled for iOS
-
Methods to enable IAP reporting (iOS)
Flurry.setIAPReportingEnabled(enableIAP: boolean);
-
Methods for Messaging (Flurry Push)
// message.Type: { 'NotificationReceived', 'NotificationClicked', // 'NotificationCancelled', 'TokenRefresh' } (Android only) // message.Title: message title // message.Body: message body // message.Data: message data (Map) // message.ClickAction: click action (Android only) Flurry.addMessagingListener((message) => callback); Flurry.removeMessagingListener((message) => callback); Flurry.willHandleMessage(handled: boolean); Flurry.printMessage(message: object);
Copyright 2018 Oath Inc.
This project is licensed under the terms of the Apache 2.0 open source license. Please refer to LICENSE for the full terms.