diff --git a/CHANGELOG.md b/CHANGELOG.md index 59ef33c..a1345d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Change Log +## v3.1.0 (2019-03-25) + +#### Features + +* Provide Enum for LogLevel and Gender +* Improve and support more JSDoc for code completion +* Upgrade Flurry Android SDK version to 11.6.0 + +#### Bug Fixes + +* Do not include Firebase libraries for Android platform + # v3.0.0 (2019-03-11) #### Features diff --git a/Code-of-Conduct.md b/Code-of-Conduct.md new file mode 100644 index 0000000..b60c91b --- /dev/null +++ b/Code-of-Conduct.md @@ -0,0 +1,54 @@ +# Verizon Media Open Source Code of Conduct + +## Summary +This Code of Conduct is our way to encourage good behavior and discourage bad behavior in our open source community. We invite participation from many people to bring different perspectives to support this project. We pledge to do our part to foster a welcoming and professional environment free of harassment. We expect participants to communicate professionally and thoughtfully during their involvement with this project. + +Participants may lose their good standing by engaging in misconduct. For example: insulting, threatening, or conveying unwelcome sexual content. We ask participants who observe conduct issues to report the incident directly to the project's Response Team at opensource-conduct@verizonmedia.com. Verizon Media will assign a respondent to address the issue. We may remove harassers from this project. + +This code does not replace the terms of service or acceptable use policies of the websites used to support this project. We acknowledge that participants may be subject to additional conduct terms based on their employment which may govern their online expressions. + +## Details +This Code of Conduct makes our expectations of participants in this community explicit. +* We forbid harassment and abusive speech within this community. +* We request participants to report misconduct to the project’s Response Team. +* We urge participants to refrain from using discussion forums to play out a fight. + +### Expected Behaviors +We expect participants in this community to conduct themselves professionally. Since our primary mode of communication is text on an online forum (e.g. issues, pull requests, comments, emails, or chats) devoid of vocal tone, gestures, or other context that is often vital to understanding, it is important that participants are attentive to their interaction style. + +* **Assume positive intent.** We ask community members to assume positive intent on the part of other people’s communications. We may disagree on details, but we expect all suggestions to be supportive of the community goals. +* **Respect participants.** We expect participants will occasionally disagree. Even if we reject an idea, we welcome everyone’s participation. Open Source projects are learning experiences. Ask, explore, challenge, and then respectfully assert if you agree or disagree. If your idea is rejected, be more persuasive not bitter. +* **Welcoming to new members.** New members bring new perspectives. Some may raise questions that have been addressed before. Kindly point them to existing discussions. Everyone is new to every project once. +* **Be kind to beginners.** Beginners use open source projects to get experience. They might not be talented coders yet, and projects should not accept poor quality code. But we were all beginners once, and we need to engage kindly. +* **Consider your impact on others.** Your work will be used by others, and you depend on the work of others. We expect community members to be considerate and establish a balance their self-interest with communal interest. +* **Use words carefully.** We may not understand intent when you say something ironic. Poe’s Law suggests that without an emoticon people will misinterpret sarcasm. We ask community members to communicate plainly. +* **Leave with class.** When you wish to resign from participating in this project for any reason, you are free to fork the code and create a competitive project. Open Source explicitly allows this. Your exit should not be dramatic or bitter. + +### Unacceptable Behaviors +Participants remain in good standing when they do not engage in misconduct or harassment. To elaborate: +* **Don't be a bigot.** Calling out project members by their identity or background in a negative or insulting manner. This includes, but is not limited to, slurs or insinuations related to protected or suspect classes e.g. race, color, citizenship, national origin, political belief, religion, sexual orientation, gender identity and expression, age, size, culture, ethnicity, genetic features, language, profession, national minority statue, mental or physical ability. +* **Don't insult.** Insulting remarks about a person’s lifestyle practices. +* **Don't dox.** Revealing private information about other participants without explicit permission. +* **Don't intimidate.** Threats of violence or intimidation of any project member. +* **Don't creep.** Unwanted sexual attention or content unsuited for the subject of this project. +* **Don't disrupt.** Sustained disruptions in a discussion. +* **Let us help.** Refusal to assist the Response Team to resolve an issue in the community. + +We do not list all forms of harassment, nor imply some forms of harassment are not worthy of action. Any participant who *feels* harassed or *observes* harassment, should report the incident. Victim of harassment should not address grievances in the public forum, as this often intensifies the problem. Report it, and let us address it off-line. + +### Reporting Issues +If you experience or witness misconduct, or have any other concerns about the conduct of members of this project, please report it by contacting our Response Team at opensource-conduct@verizonmedia.com who will handle your report with discretion. Your report should include: +* Your preferred contact information. We cannot process anonymous reports. +* Names (real or usernames) of those involved in the incident. +* Your account of what occurred, and if the incident is ongoing. Please provide links to or transcripts of the publicly available records (e.g. a mailing list archive or a public IRC logger), so that we can review it. +* Any additional information that may be helpful to achieve resolution. + +After filing a report, a representative will contact you directly to review the incident and ask additional questions. If a member of the Verizon Media Response Team is named in an incident report, that member will be recused from handling your incident. If the complaint originates from a member of the Response Team, it will be addressed by a different member of the Response Team. We will consider reports to be confidential for the purpose of protecting victims of abuse. + +### Scope +Verizon Media will assign a Response Team member with admin rights on the project and legal rights on the project copyright. The Response Team is empowered to restrict some privileges to the project as needed. Since this project is governed by an open source license, any participant may fork the code under the terms of the project license. The Response Team’s goal is to preserve the project if possible, and will restrict or remove participation from those who disrupt the project. + +This code does not replace the terms of service or acceptable use policies that are provided by the websites used to support this community. Nor does this code apply to communications or actions that take place outside of the context of this community. Many participants in this project are also subject to codes of conduct based on their employment. This code is a social-contract that informs participants of our social expectations. It is not a terms of service or legal contract. + +## License and Acknowledgment. +This text is shared under the [CC-BY-4.0 license](https://creativecommons.org/licenses/by/4.0/). This code is based on a study conducted by the [TODO Group](https://todogroup.org/) of many codes used in the open source community. If you have feedback about this code, contact our Response Team at the address listed above. \ No newline at end of file diff --git a/README.md b/README.md index 464c09d..913e836 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,16 @@ A React Native plugin for Flurry SDK 1. Install Flurry SDK module by `npm` - ``` + ```bash npm install react-native-flurry-sdk --save ``` + 2. Link React Native dependency - ``` + ```bash react-native link react-native-flurry-sdk ``` + 3. Add Flurry JS code ```javascript @@ -39,18 +41,18 @@ A React Native plugin for Flurry SDK - By default, Flurry adds `INTERNET` and `ACCESS_NETWORK_STATE` permissions to optimize analytics data. Please see [Manual Flurry Android SDK Integration](https://developer.yahoo.com/flurry/docs/integrateflurry/android-manual/) for the other recommended options. - To improve analytics identities, please see [Manual Flurry Android SDK Integration](https://developer.yahoo.com/flurry/docs/integrateflurry/android-manual/) for adding Google Play Services library in your app by including the following in your `build.gradle` file: - ``` + ```groovy 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' - ... + implementation 'com.google.android.gms:play-services-ads:15.0.1' } ``` + - **Flurry Push**
In order to use [Flurry Push](https://developer.yahoo.com/flurry/docs/push/) for [Android](https://developer.yahoo.com/flurry/docs/push/integration/android/), please follow the additional steps below: 1. 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. - + ```java new FlurryModule.Builder() .withCrashReporting(true) @@ -59,9 +61,10 @@ A React Native plugin for Flurry SDK .withMessaging(true) .build(this, FLURRY_ANDROID_API_KEY); ``` + 2. Follow [Set up a Firebase Cloud Messaging client app on Android](https://firebase.google.com/docs/cloud-messaging/android/client). 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's `android/app` folder now. You do not need to provide any setup codes here. Your `build.gradle` will look like: - ``` + ```groovy // android/build.gradle (project-level) buildscript { dependencies { @@ -69,11 +72,17 @@ A React Native plugin for Flurry SDK } } ``` - - ``` + + ```groovy // 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' + } ``` + 3. Set up "Android Authorization" in Flurry [Push Authorization](https://developer.yahoo.com/flurry/docs/push/authorization/). ### iOS @@ -82,17 +91,18 @@ A React Native plugin for Flurry SDK 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. - ``` + ```bash cd ios pod deintegrate ``` If you have a Podfile only for native dependencies, please remove `pod 'Flurry-iOS-SDK/FlurrySDK'` from your Podfile, re-run `pod install`, remove `react-native-flurry-sdk.podspec`, and execute `react-native link` again. - ``` + ```bash 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. 1. Open your `.xcodeproj` file using Xcode. It is usually located under the `ios` directory of your React Native app. @@ -108,98 +118,97 @@ A React Native plugin for Flurry SDK - `index.js` -```javascript -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(2) - .build(FLURRY_ANDROID_API_KEY, FLURRY_IOS_API_KEY); - -AppRegistry.registerComponent(appName, () => App); -``` + ```javascript + 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` -```javascript -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 { - 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('m'); - 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 ( - - ... - - ); - } -} -... -``` + ```javascript + 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 { + 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 ( + + ... + + ); + } + } + ... + ``` - `index.js / Messaging.js` -```javascript -// 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); -}); -``` + ```javascript + // 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); + }); + ``` ## API Reference See [Android](http://flurry.github.io/flurry-android-sdk/)-[(FlurryAgent)](http://flurry.github.io/flurry-android-sdk/com/flurry/android/FlurryAgent.html) / -[iOS](http://flurry.github.io/flurry-ios-sdk/)-[(Flurry)](http://flurry.github.io/flurry-ios-sdk/interface_flurry.html) for -the Flurry references. +[iOS](http://flurry.github.io/flurry-ios-sdk/)-[(Flurry)](http://flurry.github.io/flurry-ios-sdk/interface_flurry.html) for the Flurry references. - **Methods to initialize Flurry** @@ -208,12 +217,13 @@ the Flurry references. Flurry.Builder.withContinueSessionMillis(sessionMillis = 10000); Flurry.Builder.withIncludeBackgroundSessionsInMetrics(includeBackgroundSessionsInMetrics = true); Flurry.Builder.withLogEnabled(enableLog = true); - Flurry.Builder.withLogLevel(logLevel = 5); // Android (2:VERBOSE, 3:DEBUG, 4:INFO, 5:WARN, 6:ERROR, 7:ASSERT), iOS (2:All, 3-5:Debug, 6-7:Critical) + 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)* ```javascript @@ -221,34 +231,37 @@ the Flurry references. Flurry.withContinueSessionMillis(sessionMillis = 10000); Flurry.withIncludeBackgroundSessionsInMetrics(includeBackgroundSessionsInMetrics = true); Flurry.withLogEnabled(enableLog = true); - Flurry.withLogLevel(logLevel = 5); // Android (2:VERBOSE, 3:DEBUG, 4:INFO, 5:WARN, 6:ERROR, 7:ASSERT), iOS (2:All, 3-5:Debug, 6-7:Critical) + Flurry.withLogLevel(logLevel = Flurry.LogLevel.WARN); // LogLevel = { VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT } ``` - + ```javascript 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** ```javascript Flurry.setAge(age: number); - Flurry.setGender(gender = ['m', 'f']); + 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** ```javascript - Flurry.getVersions(): Promise; + Flurry.getVersions(): Promise<{agentVersion: number, releaseVersion: string, sessionId: string}>; Flurry.getVersions((msg) => errorCallback, (agentVersion, releaseVersion, sessionId) => successCallback); ``` + - **Methods to log Flurry events** ```javascript @@ -256,24 +269,26 @@ the Flurry references. 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)** ```javascript Flurry.setIAPReportingEnabled(enableIAP: boolean); ``` + - **Methods for Messaging (Flurry Push)** ```javascript @@ -285,10 +300,10 @@ the Flurry references. // message.ClickAction: click action (Android only) Flurry.addMessagingListener((message) => callback); Flurry.removeMessagingListener((message) => callback); - Flurry.willHandleMessage(handled: boolean); // Android only + Flurry.willHandleMessage(handled: boolean); Flurry.printMessage(message: object); ``` - + ## Support - [Flurry Developer Support Site](https://developer.yahoo.com/flurry/docs/) @@ -297,14 +312,4 @@ the Flurry references. Copyright 2018 Oath Inc. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +This project is licensed under the terms of the [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0) open source license. Please refer to [LICENSE](LICENSE) for the full terms. diff --git a/android/build.gradle b/android/build.gradle index 874e589..a9edd66 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -16,7 +16,7 @@ android { defaultConfig { minSdkVersion 16 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 1 versionName "1.0" } @@ -38,9 +38,7 @@ repositories { dependencies { implementation 'com.facebook.react:react-native:+' - implementation 'com.flurry.android:analytics:11.5.0@aar' - implementation 'com.flurry.android:marketing:11.5.0@aar' - implementation 'com.google.firebase:firebase-core:16.0.3' - implementation 'com.google.firebase:firebase-messaging:17.3.2' + implementation 'com.flurry.android:analytics:11.6.0@aar' + implementation 'com.flurry.android:marketing:11.6.0@aar' } diff --git a/android/src/main/java/com/flurry/android/reactnative/FlurryModule.java b/android/src/main/java/com/flurry/android/reactnative/FlurryModule.java index f47ab64..79882cd 100644 --- a/android/src/main/java/com/flurry/android/reactnative/FlurryModule.java +++ b/android/src/main/java/com/flurry/android/reactnative/FlurryModule.java @@ -50,7 +50,7 @@ public class FlurryModule extends ReactContextBaseJavaModule { private static final String FLURRY_MESSAGING_EVENT = "FlurryMessagingEvent"; private static final String ORIGIN_NAME = "react-native-flurry-sdk"; - private static final String ORIGIN_VERSION = "3.0.0"; + private static final String ORIGIN_VERSION = "3.1.0"; private FlurryAgent.Builder mFlurryAgentBuilder; diff --git a/index.d.ts b/index.d.ts index 62481c3..f9eebbc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,7 +7,27 @@ declare module 'react-native-flurry-sdk' { * Set of methods that allow developers to capture detailed, aggregate information * regarding the use of their app by end users. */ - interface FlurryStatic { + export class Flurry { + + /** + * Constants for setting log level in analytics SDK. + */ + static LogLevel: { + VERBOSE: number, + DEBUG: number, + INFO: number, + WARN: number, + ERROR: number, + ASSERT: number + } + + /** + * Constants for setting gender in analytics SDK. + */ + static Gender: { + MALE: string, + FEMALE: string + } /** * Initialize the Flurry SDK. @@ -21,7 +41,7 @@ declare module 'react-native-flurry-sdk' { * @param apiKey2 iOS User API Key. * @deprecated Please use Flurry.Builder instead. */ - init(apiKey1: string, apiKey2?: string): void; + static init(apiKey1: string, apiKey2?: string): void; /** * True to enable or false to disable the ability to catch all uncaught exceptions @@ -32,7 +52,7 @@ declare module 'react-native-flurry-sdk' { * Method must be called prior to invoking init, e.g. Flurry.withCrashReporting(true); * @deprecated Please use Flurry.Builder instead. */ - withCrashReporting(crashReporting?: boolean): void; + static withCrashReporting(crashReporting?: boolean): void; /** * Set the timeout for expiring a Flurry session. @@ -42,7 +62,7 @@ declare module 'react-native-flurry-sdk' { * Method must be called prior to invoking init, e.g. Flurry.withContinueSessionMillis(6000); * @deprecated Please use Flurry.Builder instead. */ - withContinueSessionMillis(sessionMillis?: number): void; + static withContinueSessionMillis(sessionMillis?: number): void; /** * True if this session should be added to total sessions/DAUs when applicationstate is inactive or background. @@ -52,28 +72,27 @@ declare module 'react-native-flurry-sdk' { * Method must be called prior to invoking init, e.g. Flurry.withIncludeBackgroundSessionsInMetrics(true); * @deprecated Please use Flurry.Builder instead. */ - withIncludeBackgroundSessionsInMetrics(includeBackgroundSessionsInMetrics?: boolean): void; + static withIncludeBackgroundSessionsInMetrics(includeBackgroundSessionsInMetrics?: boolean): void; /** * True to enable or false to disable the internal logging for the Flurry SDK. * - * @param enableLog true to enable logging, false to disable it. + * @param enableLog true to enable logging, false to disable it. * * Method must be called prior to invoking init, e.g. Flurry.withLogEnabled(true); * @deprecated Please use Flurry.Builder instead. */ - withLogEnabled(enableLog?: boolean): void; + static withLogEnabled(enableLog?: boolean): void; /** * Set the log level of the internal Flurry SDK logging. - * Android (2:VERBOSE, 3:DEBUG, 4:INFO, 5:WARN, 6:ERROR, 7:ASSERT), iOS (2:All, 3-5:Debug, 6-7:Critical) * - * @param logLevel The level to set it to. + * @param logLevel The level to set it to { VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT }. * - * Method must be called prior to invoking init, e.g. Flurry.withLogLevel(5); + * Method must be called prior to invoking init, e.g. Flurry.withLogLevel(Flurry.LogLevel.WARN); * @deprecated Please use Flurry.Builder instead. */ - withLogLevel(logLevel?: number): void; + static withLogLevel(logLevel?: number): void; /** * Sets the age of the user at the time of this session. @@ -82,16 +101,16 @@ declare module 'react-native-flurry-sdk' { * * @param age valid values are 0-110 */ - setAge(age: number): void; + static setAge(age: number): void; /** * Sets the gender of the user. * - * e.g. Flurry.setGender('f'); + * e.g. Flurry.setGender(Flurry.Gender.FEMALE); * - * @param gender one of 'f' or 'm' + * @param gender type of Flurry.Gender */ - setGender(gender: string): void; + static setGender(gender: string): void; /** * Set whether Flurry should record location via GPS. @@ -100,7 +119,7 @@ declare module 'react-native-flurry-sdk' { * * @param reportLocation True to allow Flurry to record location via GPS, false otherwise */ - setReportLocation(reportLocation: boolean): void; + static setReportLocation(reportLocation: boolean): void; /** * This method allows you to specify session origin and deep link for each session. @@ -110,7 +129,7 @@ declare module 'react-native-flurry-sdk' { * @param originName Name of the origin. * @param deepLink Url of the deep Link. */ - setSessionOrigin(originName: string, deepLink: string): void; + static setSessionOrigin(originName: string, deepLink: string): void; /** * Sets the Flurry userId for this session. @@ -119,7 +138,7 @@ declare module 'react-native-flurry-sdk' { * * @param userId Unique user id for session. */ - setUserId(userId: string): void; + static setUserId(userId: string): void; /** * Set the version name of the app. @@ -128,7 +147,7 @@ declare module 'react-native-flurry-sdk' { * * @param versionName The version of the app. */ - setVersionName(versionName?: string): void; + static setVersionName(versionName?: string): void; /** * Sets the iOS In-App Purchase reporting enabled. @@ -137,7 +156,7 @@ declare module 'react-native-flurry-sdk' { * * @param enableIAP True to enable iOS In-App Purchase reporting, false otherwise */ - setIAPReportingEnabled(enableIAP?: boolean): void; + static setIAPReportingEnabled(enableIAP?: boolean): void; /** * Add origin attribution. @@ -150,7 +169,7 @@ declare module 'react-native-flurry-sdk' { * @param originName The name/id of the origin you wish to attribute. * @param originVersion The version of the origin you wish to attribute. */ - addOrigin(originName: string, originVersion: string, originParameters?: any): void; + static addOrigin(originName: string, originVersion: string, originParameters?: any): void; /** * This method allows you to associate parameters with an session. @@ -160,7 +179,7 @@ declare module 'react-native-flurry-sdk' { * @param name Property name. * @param value Property value. */ - addSessionProperty(name: string, value: string): void; + static addSessionProperty(name: string, value: string): void; /** * Get the version of the Flurry SDK. @@ -199,7 +218,7 @@ declare module 'react-native-flurry-sdk' { * @param successCallback success callback. * @return the Promise object if called without callbacks specified. */ - getVersions(errorCallback?: any, successCallback?: any): Promise; + static getVersions(errorCallback?: any, successCallback?: any): Promise<{agentVersion: number, releaseVersion: string, sessionId: string}>; /** * Logs the breadcrumb. @@ -208,7 +227,7 @@ declare module 'react-native-flurry-sdk' { * * @param crashBreadcrumb crash breadcrumb */ - logBreadcrumb(crashBreadcrumb: string): void; + static logBreadcrumb(crashBreadcrumb: string): void; /** * Log an event. @@ -224,7 +243,7 @@ declare module 'react-native-flurry-sdk' { * @param parameters A {@code Map} of parameters to log with this event. * @param timed True if this event is timed, false otherwise. */ - logEvent(eventId: string, parameters?: any, timed?: boolean): void; + static logEvent(eventId: string, parameters?: any, timed?: boolean): void; /** * Log a payment. @@ -240,7 +259,7 @@ declare module 'react-native-flurry-sdk' { * @param parameters A {@code Map} of the parameters which should be submitted * with this event. */ - logPayment(productName: string, productId: string, quantity: number, price: number, + static logPayment(productName: string, productId: string, quantity: number, price: number, currency: string, transactionId: string, parameters: any): void; /** @@ -254,7 +273,7 @@ declare module 'react-native-flurry-sdk' { * @param eventId The name/id of the event. * @param parameters A {@code Map} of parameters to log with this event. */ - endTimedEvent(eventId: string, parameters?: any): void; + static endTimedEvent(eventId: string, parameters?: any): void; /** * Report errors that your app catches. @@ -269,14 +288,14 @@ declare module 'react-native-flurry-sdk' { * @param errorClass Class in which the error is reported. * @param errorParams A {@code Map} of parameters to log with this report. */ - onError(errorId: string, message: string, errorClass: string, errorParams?: any): void; + static onError(errorId: string, message: string, errorClass: string, errorParams?: any): void; /** * Log a page view. * * e.g. Flurry.onPageView(); */ - onPageView(): void; + static onPageView(): void; /** * Add a listener to receive messaging events, and handle the notification. @@ -308,14 +327,14 @@ declare module 'react-native-flurry-sdk' { * * @param callback messaging event callback. */ - addMessagingListener(callback: any):void; + static addMessagingListener(callback: any):void; /** * Remove a messaging events listener. * * @param callback messaging event callback. */ - removeMessagingListener(callback: any): void; + static removeMessagingListener(callback: any): void; /** * If you would like to handle the notification yourself, return true to notify Flurry @@ -330,17 +349,102 @@ declare module 'react-native-flurry-sdk' { * @param handled True if you've handled the notification. * False if you haven't and want Flurry to handle it. */ - willHandleMessage(handled: boolean): void; + static willHandleMessage(handled: boolean): void; /** * A helper function to print the message. * * @param message the message received. */ - printMessage(message: any): void; + static printMessage(message: any): void; + + } + + export module Flurry { + + /** + * Builder pattern for Flurry. + * + * Initialize the Flurry SDK. + * build(apiKey1: string, apiKey2?: string): void; + * + * Enable the ability to catch all uncaught exceptions and have them reported back to Flurry. + * withCrashReporting(crashReporting?: boolean): object; + * + * Set the timeout for expiring a Flurry session. + * withContinueSessionMillis(sessionMillis?: number): object; + * + * Enable if this session should be added to total sessions/DAUs when applicationstate is inactive or background. + * withIncludeBackgroundSessionsInMetrics(includeBackgroundSessionsInMetrics?: boolean): object; + * + * Enable the internal logging for the Flurry SDK. + * withLogEnabled(enableLog?: boolean): object; + * + * Set the log level of the internal Flurry SDK logging. + * withLogLevel(logLevel?: number): object; + * + * Enable the Flurry Push for messaging. + * withMessaging(enableMessaging?: boolean): object; + */ + class Builder { + + /** + * Initialize the Flurry SDK. + * + * There are two overloads, + * e.g. build('FLURRY_API_KEY'); build('FLURRY_ANDROID_API_KEY', 'FLURRY_IOS_API_KEY'); + * - build(apikey) + * - build(apikeyAndroid, apikeyIos) + * + * @param apiKey1 Android User API Key. + * @param apiKey2 iOS User API Key. + */ + build(apiKey1: string, apiKey2?: string): void; + /** + * True to enable or false to disable the ability to catch all uncaught exceptions + * and have them reported back to Flurry. + * + * @param crashReporting true to enable, false to disable. + */ + withCrashReporting(crashReporting?: boolean): object; + + /** + * Set the timeout for expiring a Flurry session. + * + * @param sessionMillis The time in milliseconds to set the session timeout to. Minimum value of 5000. + */ + withContinueSessionMillis(sessionMillis?: number): object; + + /** + * True if this session should be added to total sessions/DAUs when applicationstate is inactive or background. + * + * @param includeBackgroundSessionsInMetrics if background and inactive session should be counted toward dau + */ + withIncludeBackgroundSessionsInMetrics(includeBackgroundSessionsInMetrics?: boolean): object; + + /** + * True to enable or false to disable the internal logging for the Flurry SDK. + * + * @param enableLog true to enable logging, false to disable it. + */ + withLogEnabled(enableLog?: boolean): object; + + /** + * Set the log level of the internal Flurry SDK logging. + * + * @param logLevel The level to set it to { VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT }. + */ + withLogLevel(logLevel?: number): object; + + /** + * True to enable or false to disable the Flurry Push for messaging. + * + * @param enableMessaging true to enable messaging, false to disable it. + */ + withMessaging(enableMessaging?: boolean): object; + } } - const Flurry: FlurryStatic; export default Flurry; } diff --git a/index.js b/index.js index d2acb2b..4650e4b 100644 --- a/index.js +++ b/index.js @@ -22,6 +22,23 @@ function priorInit(wrapped) { export default class Flurry { + /** + * Android (2:VERBOSE, 3:DEBUG, 4:INFO, 5:WARN, 6:ERROR, 7:ASSERT), iOS (2:All, 3-5:Debug, 6-7:Critical) + */ + static LogLevel = Object.freeze({ + VERBOSE: 2, + DEBUG: 3, + INFO: 4, + WARN: 5, + ERROR: 6, + ASSERT: 7 + }); + + static Gender = Object.freeze({ + MALE: 'm', + FEMALE: 'f' + }); + static Builder = class { constructor() { ReactNativeFlurry.initBuilder(); @@ -59,11 +76,6 @@ export default class Flurry { return this; } - withCrashReporting(crashReporting = true) { - ReactNativeFlurry.withCrashReporting(crashReporting); - return this; - } - withContinueSessionMillis(sessionMillis = 10000) { if (sessionMillis < 5000) { console.error('Flurry.Builder.withContinueSessionMillis: the minimum timeout for a session is 5,000 ms.'); @@ -82,7 +94,7 @@ export default class Flurry { return this; } - withLogLevel(logLevel = 5) { + withLogLevel(logLevel = LogLevel.WARN) { ReactNativeFlurry.withLogLevel(logLevel); return this; } @@ -166,7 +178,7 @@ export default class Flurry { /** * @deprecated Please use Flurry.Builder instead. */ - static withLogLevel(logLevel = 5) { + static withLogLevel(logLevel = LogLevel.WARN) { priorInit(ReactNativeFlurry.withLogLevel)(logLevel); } @@ -181,7 +193,7 @@ export default class Flurry { static setGender(gender) { if (typeof gender !== 'string' || !['m', 'f'].includes(gender)) { - console.error(`Flurry.setGender: gender must be one of ['m', 'f']. Got ${gender}`); + console.error(`Flurry.setGender: gender must be type of Flurry.Gender. Got ${gender}`); return; } diff --git a/ios/ReactNativeFlurry/ReactNativeFlurry.m b/ios/ReactNativeFlurry/ReactNativeFlurry.m index 6e0d2c5..9f69a6d 100755 --- a/ios/ReactNativeFlurry/ReactNativeFlurry.m +++ b/ios/ReactNativeFlurry/ReactNativeFlurry.m @@ -31,7 +31,7 @@ #endif static NSString * const originName = @"react-native-flurry-sdk"; -static NSString * const originVersion = @"3.0.0"; +static NSString * const originVersion = @"3.1.0"; static NSString * const kMessagingEvent = @"FlurryMessagingEvent"; static NSString * const kNotificationReceived = @"NotificationReceived"; static NSString * const kNotificationClicked = @"NotificationClicked"; diff --git a/package.json b/package.json index 28eaa6e..964cf22 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-flurry-sdk", - "version": "3.0.0", + "version": "3.1.0", "description": "React Native wrapper for Flurry SDK", "main": "index.js", "types" : "index.d.ts",