Code Monkey home page Code Monkey logo

react-native-leanplum's Introduction

React Native Leanplum

npm version

Supported React Native Versions

This library was updated to support React Native autolinking in version 5.0; therefore it is not recommended to upgrade to version 5 unless you are running React Native 0.60 or above.

React Native React Native Leanplum
0.60.0+ >= 4.0.0
0.40.0 - 0.59.x <= 3.0.0

Install

yarn add @brandingbrand/react-native-leanplum

Usage

You may need https://github.com/brandingbrand/react-native-push-notification-leanplum too

JS

import Leanplum from '@brandingbrand/react-native-leanplum';
...
const leanPlumKeys = {
  appId: '',
  development: '',
  production: '',
}
...
const start = async () => {
  if (__DEV__) {
    Leanplum.setAppIdForDevelopmentMode(
      leanPlumKeys.appId,
      leanPlumKeys.development,
    );
  } else {
    Leanplum.setAppIdForProductionMode(
      leanPlumKeys.appId,
      leanPlumKeys.production,
    );
  }

  const started = await Leanplum.hasStarted();
  if (!started) Leanplum.start();
};

Leanplum API

  • setApiConnectionSettings:
    Optional
    Sets the API server. The API path is of the form http[s]://hostname/servletName
    @param hostName The name of the API host, such as api.leanplum.com
    @param servletName The name of the API servlet, such as api
    @param ssl Whether to use SSL

  • setNetworkTimeout:
    Optional
    Adjusts the network timeouts. The default timeout is 10 seconds for requests, and 15 seconds for file downloads.

  • setNetworkActivityIndicatorEnabled:
    iOS Only
    Sets whether to show the network activity indicator in the status bar when making requests. Default: YES.

  • setCanDownloadContentMidSessionInProductionMode:
    Advanced
    Whether new variables can be downloaded mid-session. By default, this is disabled. Currently, if this is enabled, new variables can only be downloaded if a push notification is sent while the app is running, and the notification's metadata hasn't be downloaded yet.

  • setFileHashingEnabledInDevelopmentMode:
    Modifies the file hashing setting in development mode. By default, Leanplum will hash file variables to determine if they're modified and need to be uploaded to the server if we're running in the simulator. Setting this to NO will reduce startup latency in development mode, but it's possible that Leanplum will not always have the most up-to-date versions of your resources.

  • setVerboseLoggingInDevelopmentMode:
    iOS Only
    Sets whether to enable verbose logging in development mode. Default: NO.

  • setInAppPurchaseEventName:
    iOS Only
    Sets a custom event name for in-app purchase tracking. Default: Purchase.

  • setAppIdForDevelopmentMode:
    Must call either this or {@link setAppIdForProductionMode} before issuing any calls to the API, including start.
    @param appId Your app ID.
    @param accessKey Your development key.

  • setAppIdForProductionMode:
    Must call either this or {@link setAppIdForDevelopmentMode} before issuing any calls to the API, including start.
    @param appId Your app ID.
    @param accessKey Your production key.

  • setDeviceId:
    Sets a custom device ID. For example, you may want to pass the advertising ID to do attribution. By default, the device ID is the identifier for vendor.

  • setAppVersion:
    iOS Only
    By default, Leanplum reports the version of your app using CFBundleVersion, which can be used for reporting and targeting on the Leanplum dashboard. If you wish to use CFBundleShortVersionString or any other string as the version, you can call this before your call to Leanplum.start()

  • start:
    Call this when your application starts. This will initiate a call to Leanplum's servers to get the values of the variables used in your app.

  • hasStarted:
    Returns whether or not Leanplum has finished starting.

  • hasStartedAndRegisteredAsDeveloper:
    Returns whether or not Leanplum has finished starting and the device is registered as a developer.

  • onStartResponse:
    Function to call when the start call finishes, and variables are returned back from the server. Calling this multiple times will call each function in succession.

  • onVariablesChanged:
    Function to call when the variables receive new values from the server. This will be called on start, and also later on if the user is in an experiment that can update in realtime.

  • onInterfaceChanged:
    iOS Only
    Function to call when the interface receive new values from the server. This will be called on start, and also later on if the user is in an experiment that can update in realtime.

  • onVariablesChangedAndNoDownloadsPending:
    Function to call when no more file downloads are pending (either when no files needed to be downloaded or all downloads have been completed).

  • onceVariablesChangedAndNoDownloadsPending:
    Function to call ONCE when no more file downloads are pending (either when no files needed to be downloaded or all downloads have been completed).

  • setUserId:
    Updates a user ID after session start.

  • setUserAttributes:
    Updates a user ID after session start with a dictionary of user attributes.

  • setTrafficSourceInfo:
    Sets the traffic source info for the current user. Keys in info must be one of:

    • publisherId
    • publisherName
    • publisherSubPublishe
    • publisherSubSite
    • publisherSubCampaign
    • publisherSubAdGroup
    • publisherSubAd
  • advanceTo:
    Advances to a particular state in your application. The string can be any value of your choosing, and will show up in the dashboard. A state is a section of your app that the user is currently in. You can specify up to 200 types of parameters per app across all events and state. The parameter keys must be strings, and values either strings or numbers.
    @param state The name of the state. (nullable)
    @param info Anything else you want to log with the state. For example, if the state is watchVideo, info could be the video ID.
    @param params A dictionary with custom parameters.

  • pauseState:
    Pauses the current state. You can use this if your game has a "pause" mode. You shouldn't call it when someone switches out of your app because that's done automatically.

  • resumeState:
    Resumes the current state.

  • trackAllAppScreens:
    Automatically tracks all of the screens in the app as states. You should not use this in conjunction with advanceTo as the user can only be in 1 state at a time. This method requires LeanplumUIEditor module.

  • trackPurchase:
    Manually track purchase event with currency code in your application. It is advised to use trackInAppPurchases to automatically track IAPs.

  • trackInAppPurchases:
    iOS Only
    Automatically tracks InApp purchase and does server side receipt validation.

  • track:
    Logs a particular event in your application. The string can be any value of your choosing, and will show up in the dashboard. To track a purchase, use trackPurchase().

  • variants:
    Gets a list of variants that are currently active for this user. Each variant is a dictionary containing an id.

  • forceContentUpdate:
    Forces content to update from the server. If variables have changed, the appropriate callbacks will fire. Use sparingly as if the app is updated, you'll have to deal with potentially inconsistent state or user experience. The provided callback will always fire regardless of whether the variables have changed.

  • enableTestMode:
    This should be your first statement in a unit test. This prevents Leanplum from communicating with the server.

  • setTestModeEnabled:
    Used to enable or disable test mode. Test mode prevents Leanplum from communicating with the server. This is useful for unit tests.

  • setPushSetup:
    iOS Only
    Customize push setup. If this API should be called before [Leanplum start]. If this API is not used the default push setup from the docs will be used for "Push Ask to Ask" and "Register For Push".

  • isPreLeanplumInstall:
    iOS Only
    Returns YES if the app existed on the device more than a day previous to a version built with Leanplum was installed.

  • deviceId:
    Returns the deviceId in the current Leanplum session. This should only be called after Leanplum.start().

  • userId:
    Returns the userId in the current Leanplum session. This should only be called after [Leanplum start].

  • inbox:
    Returns an instance to the singleton LPInbox object.

LPInbox

LPInboxMessage

react-native-leanplum's People

Contributors

alexrisch avatar bweissbart avatar cauldrath avatar deemaabdallah avatar dependabot[bot] avatar maksymdeminbbc avatar nathan-sankbeil avatar pavlemilicevicbb avatar rdanishk avatar sandergols-tomtom avatar semantic-release-bot avatar sidferreira avatar skyeckstrom avatar vancehu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-leanplum's Issues

Android autolinking not working

RN 0.60.5
@brandingbrand/react-native-leanplum 4.0.0

I get the following error when building for dev on Android:

/Users/me/myapp/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:89: error: constructor RNLeanplumPackage in class RNLeanplumPackage cannot be applied to given types;
      new RNLeanplumPackage(),
      ^
  required: Application
  found: no arguments
  reason: actual and formal argument lists differ in length
1 error

FAILURE: Build failed with an exception.

I figured out a workaround by updating my react-native.config.js as the following:

module.exports = {
  dependencies: {
    '@brandingbrand/react-native-leanplum': {
      platforms: {
        android: {
          packageInstance: 'new RNLeanplumPackage(getApplication())'
        },
      },
    },
  },
};

Then the app builds on Android fine.

NullPointer Exception

I am facing below exception which is crashing the application in production, can anyone help please.

java.lang.NullPointerException:
at com.reactnativeleanplum.RNLeanplum.start (RNLeanplum.java:70)
at java.lang.reflect.Method.invoke (Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:371)
at com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:150)
at com.facebook.react.bridge.queue.NativeRunnable.run (Native Method)
at android.os.Handler.handleCallback (Handler.java:789)
at android.os.Handler.dispatchMessage (Handler.java:98)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:26)
at android.os.Looper.loop (Looper.java:164)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:225)
at java.lang.Thread.run (Thread.java:764)

Android: Cannot invoke method get() on null object

"react-native": "0.60.5",
"@brandingbrand/react-native-leanplum": "^4.0.0",

Android build fails with:

Could not determine the dependencies of task ':@brandingbrand_react-native-leanplum:mergeReleaseResources'.
> Failed to notify dependency resolution listener.
   > Cannot invoke method get() on null object
   > Cannot invoke method get() on null object

I can get it to build by commenting out the lines shown below.

/node_modules/@brandingbrand/react-native-leanplum/android/build.gradle

dependencies {
    compile "com.facebook.react:react-native:+"
    compile 'com.leanplum:leanplum-fcm:5.2.3'
    // compile 'com.google.firebase:firebase-messaging:17.5.0'
    
    compile 'com.leanplum:leanplum-location:5.2.3'
    // compile "com.google.android.gms:play-services-location:17.0.0"
}

This problem does not exist in version 3.0.1

Leanplum/Leanplum.h' file not found

Hi there,

Any idea if I am missing any installation step?

screen shot 2018-10-31 at 2 58 28 pm

Seems to be fine on AppDelegate

screen shot 2018-10-31 at 3 01 57 pm

And it is normally happening when I add libRNLeanplum.a oto "Link Binary With Libraries" section

Thanks for your help.

Cheers

Missing docs

Is there a plan to add some docs?

Is it a "drop-in" replacement?

Using Leanplum variables example

Hi,
Can you please provide a short example of how to properly use your package to implement Leanplums A/B test variables?
I couldn't figure out how to do so as AFAIK the variables fetching is done in the native modules and all the variables-related callbacks have no parameters attached to them.
Thanks!

Compilation error when adding module to project

I am seeing the following error when attempting to add this module to my project. Any tips on resolving this?

Build target react-native-leanplum

CompileC /.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/react-native-leanplum.build/Objects-normal/x86_64/RNLeanplum.o /.../Development/devops/src/.../node_modules/@brandingbrand/react-native-leanplum/ios/RNLeanplum.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    cd /.../Development/devops/src/.../ios/Pods
    export LANG=en_US.US-ASCII
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu11 -fobjc-arc -fobjc-weak -fmodules -gmodules -fmodules-cache-path=/.../Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/.../Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -fmodule-name=react_native_leanplum -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wdocumentation -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wdeprecated-implementations -DPOD_CONFIGURATION_DEBUG=1 -DDEBUG=1 -DCOCOAPODS=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.4.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -mios-simulator-version-min=9.0 -g -Wno-sign-conversion -Winfinite-recursion -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wunguarded-availability -fobjc-abi-version=2 -fobjc-legacy-dispatch -index-store-path /.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Index/DataStore -iquote /.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/react-native-leanplum.build/react_native_leanplum-generated-files.hmap -I/.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/react-native-leanplum.build/react_native_leanplum-own-target-headers.hmap -I/.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/react-native-leanplum.build/react_native_leanplum-all-non-framework-target-headers.hmap -ivfsoverlay /.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Intermediates.noindex/Pods.build/all-product-headers.yaml -iquote /.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/react-native-leanplum.build/react_native_leanplum-project-headers.hmap -I/.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Products/Debug-iphonesimulator/react-native-leanplum/include -I/.../Development/devops/src/.../ios/Pods/Headers/Private -I/.../Development/devops/src/.../ios/Pods/Headers/Public -I/.../Development/devops/src/.../ios/Pods/Headers/Public/Intercom -I/.../Development/devops/src/.../ios/Pods/Headers/Public/Leanplum-iOS-SDK -I/.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/react-native-leanplum.build/DerivedSources/x86_64 -I/.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/react-native-leanplum.build/DerivedSources -F/.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Products/Debug-iphonesimulator/react-native-leanplum -F/.../Development/devops/src/.../ios/Pods/Leanplum-iOS-SDK -F/.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Products/Debug-iphonesimulator/React -include /.../Development/devops/src/.../ios/Pods/Target\ Support\ Files/react-native-leanplum/react-native-leanplum-prefix.pch -MMD -MT dependencies -MF /.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/react-native-leanplum.build/Objects-normal/x86_64/RNLeanplum.d --serialize-diagnostics /.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/react-native-leanplum.build/Objects-normal/x86_64/RNLeanplum.dia -c /.../Development/devops/src/.../node_modules/@brandingbrand/react-native-leanplum/ios/RNLeanplum.m -o /.../Library/Developer/Xcode/DerivedData/Alfred-fmrgapmofydrikbxsopumlpgjtnu/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/react-native-leanplum.build/Objects-normal/x86_64/RNLeanplum.o

/.../node_modules/@brandingbrand/react-native-leanplum/ios/RNLeanplum.m:135:36: error: too many arguments to block call, expected 1, have 3
            reject(@"no_messages", @"There were no messages", error);
            ~~~~~~                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.