npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-swrve

v0.6.1

Published

## Getting started

Downloads

5

Readme

react-native-swrve

Getting started

$ npm install react-native-swrve --save

Mostly automatic installation

$ react-native link react-native-swrve

After, you must Open up android/app/src/main/java/[...]/MainActivity.java file and follow the steps under the additional configuration section.

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-swrve and add RNSwrve.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNSwrve.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import io.underscope.RNSwrvePackage; to the imports at the top of the file.
  • Add new RNSwrvePackage() to the list returned by the getPackages() method.
  • Follow the steps under the additional configuration section.
  1. Append the following lines to android/settings.gradle:

    include ':react-native-swrve'
    project(':react-native-swrve').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-swrve/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:

    compile project(':react-native-swrve')

Additional configuration

Android

1. Include required libraries

Add the following in your android/app/build.gradle file, so the react-native-swrve dependencies are properly included.

repositories {
    ...
    flatDir {
        dirs project(':react-native-swrve').file('libs')
    }
    jcenter {
        url 'http://dl.bintray.com/swrve-inc/android'
    }
    ...
}
2. Add required configuration

Add to your AndroidManifest.xml the following line into the <application> tag.

<application ...>
  ...
  <meta-data android:name="com.swrve.sdk.appId" android:value="@integer/swrve_app_id"/>
  <meta-data android:name="com.swrve.sdk.apiKey" android:value="@string/swrve_api_key"/>
  ...
</application>

And in your strings.xml file add your swrve configuration:

<integer name="swrve_app_id">YOUR_APP_ID</integer>
<string name="swrve_app_key">YOUR_API_KEY</string>
3. Initialize library

Swrve must be initialized from the onCreate method in the MainApplication.java class.

...
// <-- Add this line
import com.dcpi.swrvemanager.SwrveManager;
// -->
...

@Override
public void onCreate() {
  super.onCreate();

  // <--- Add this block
  try {
    SwrveManager swrveManager = SwrveManager.createInstance(this);
    swrveManager.initWithAnalyticsKeySecret(getResources().getInteger(R.integer.swrve_app_id), getResources().getString(R.string.swrve_api_key));
  } catch (Exception e) {
    Log.e("MyApp", "failed to initialized SwrveManager", e);
  }
  // -->

  SoLoader.init(this, /* native exopackage */ false);
}

iOS

1. Include required libraries (check if it is necessary or react-native link actually does this step)
  1. Select your target
  2. Go to Build Settings
  3. Look for Header Search Paths and add $(SRCROOT)/../node_modules/react-native-swrve/ios as recursive
2. Add required configuration
  1. If you have multiple environments and a .xcconfig file for each one then you should add the following variables per environment
    SWRVE_APP_ID=12345
    SWRVE_API_KEY=abc123xyz1Axxxx
  2. Then in the Info.plist file add those values as keys so can be used on Swrve module init
    <key>SwrveApiKey</key>
    <string>$(SWRVE_API_KEY)</string>
    <key>SwrveAppId</key>
    <string>$(SWRVE_APP_ID)</string>
3. Add pub.pem file to Resources
  1. Go to Resources (if doesn't exist then create a Group with that name)
  2. Do a right click and select Add new file
  3. Navigate to node_modules/react-native-swrve/ios/Resources folder and select pub.pem file

You can verify the file was included correctly selecting your target and going to Build Phases > Copy Bundle Resources. The pub.pem file should be there.

4. Initialize library

Swrve must be initialized from the didFinishLaunchingWithOptions method in the AppDelegate.m file.

IMPORTANT: the appId is a number, not a string.

// <-- Add this line
#import "DcpiSwrveManager.h"
// -->

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // <-- Add this lines
  // Chances are you've the SwrveAppId and SwrveApiKey in the Info.plist file.
  // In that case you should get those values like following
  NSNumber* swrveAppId = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"SwrveAppId"];
  NSString* swrveApiKey = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"SwrveApiKey"];

  SwrveConfig* config = [[SwrveConfig alloc] init];
  config.pushEnabled = YES;
  [[DcpiSwrveManager alloc] init:swrveAppId key:swrveApiKey config:config launchOptions:launchOptions];
  // -->

  return YES;
}

@end

Usage

import RNSwrve from 'react-native-swrve'

Tracking Session Events

In order to keep track the user's session you must add to your main component the following:

class App extends Component {

  ...

  componentWillMount() {
    AppState.addEventListener('change', this.handleAppStateChange)
  }

  componentWillUnmount() {
    AppState.removeEventListener('change', this.handleAppStateChange)
  }

  handleAppStateChange = nextAppState => {
    if (nextAppState === 'active') {
      Swrve.sessionStart()
    } else {
      Swrve.sessionEnd()
    }
  }

  ...

 }

Methods

sessionStart()

Track the users' session started.

sessionEnd()

Track the users' session ended.

userUpdate(Object attributes)

Update user attributes.

  • attributes may include:
    • level (Number)
    • consumable.<consumable_name>_balance (Number)
    • monetization.<currency>_balance (Number)

logIAPAction(String productId, Number productPrice, Number quantity, String currency, String store, String durability, Integer level, Object options)

Tracks purchases done with real money.

  • options may include:
    • context (String)
    • type (String)
    • subtype (String)

[DEPRECATED] iap(Integer quantity, String productId, Number productPrice, String currency)

Tracks purchases done with real money without store verification.

[DEPRECATED] iapPlay(String productId, Double productPrice, String currency, String receipt, String receiptSignature)

Tracks purchases done with real money with store verification.

logFailedReceiptAction(String productId, String error)

Tracks a failure in the store verification.

logPurchaseAction(String item, String currency, Number cost, Number quantity)

Tracks purchases done with any type of currency.

logCurrencyGivenAction(String givenCurrency, Number givenAmount, Object options)

Tracks when a user is given currency.

  • options may include:
    • level (Number)
    • context (String)
    • type (String)
    • subtype (String)
    • subtype2 (String)
    • custom (Object)

logTimingAction(Number elapsedTime, String context, Object options)

Tracks timing events.

  • options may include:
    • stepNumber (Number)
    • stepName (String)
    • custom (Object)

navigation(String buttonPressed, Object options)

Tracks navigation between screens.

  • options may include:
    • fromLocation (String)
    • toLocation (String)
    • module (String)
    • order (Number)
    • custom (Object)

logAction(String tier1, Object options)

Tracks any type of event or user action.

  • options may include:
    • subevent (String)
    • level (Number)
    • tier2 (String)
    • tier3 (String)
    • tier4 (String)
    • context (String)
    • message (String)
    • custom (Object)

logFunnelAction(String type, Number stepNumber, String stepName, Object options)

Tracks funnel events.

  • options may include:
    • message (string)
    • custom (object)

logErrorAction(String reason, Object options)

Tracks error events.

  • options may include:
    • type (string)
    • context (string)
    • custom (object)

Troubleshooting

Android

1. com.android.dex.DexException

If you run into the following error (or similar) when running the app:

> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzbs;

This means that two dependencies in your project are using the com.google.android.gms library (one of them being react-native-swrve).

To solve it, exclude this dependency from on your android/app/build.gradle for react-native-swrve under the dependencies section:

dependencies {
  ...
  compile(project(':react-native-swrve')) {
    exclude group: 'com.google.android.gms'
  }
  ...
}