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-amplitude-analytics

v0.3.0

Published

React Native iOS and Android wrapper for Amplitude

Downloads

3,740

Readme

react-native-amplitude-analytics

npm version

Dependencies

react-native version >0.40

Installation

npm i react-native-amplitude-analytics --save

For react-native > 0.60 the installation should be automated, for older versions expand and read the Manual installation section below.

Manual iOS installation

  1. react-native link react-native-amplitude-analytics After you do that make sure that:
  • RNAmplitudeSDK.xcodeproj from node_modules/react-native-amplitude-analytics/ios is found within your Xcode Project as a subproject (if it's not add it manually with drag and drop).
  • libRNAmplitudeSDK.a is found within Linked Frameworks and Libraries under General tab (if it's not add it with the plus button) - (you don't need to add libAmplitude-iOS.a as that will be dealt with by Cocoapods in the next step).
  1. Either
  • add the following line to your "Podfile": pod 'Amplitude-iOS', '~> 4.3.1' and run pod install

    or

  • download the Amplitude-iOS sdk from here and add it to your project manually. Make sure the Amplitude-iOS directory of the SDK is included in the root of your app's ios folder.

  1. Run your project (Cmd+R)

Android Manual installation

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add

    import com.sudoplz.reactnativeamplitudeanalytics.RNAmplitudeSDKPackage;

    to the imports at the top of the file.

  • Add

    new RNAmplitudeSDKPackage(MainApplication.this),

    to the list returned by the getPackages() method

  1. Append the following lines to android/settings.gradle:

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

      compile 'com.amplitude:android-sdk:2.19.1' // native sdk of amplitude
    compile project(':react-native-amplitude-analytics') // our react-native module
  3. Add permissions. If you haven't already, add the INTERNET permission to your manifest file:

    <uses-permission android:name="android.permission.INTERNET" />

Usage


import RNAmplitude from 'react-native-amplitude-analytics';

Example

class testApp extends Component {
  constructor() {
    super();
    const amplitude = new RNAmplitude('Your Amplitude key');

    // set event upload threshold
    amplitude.setEventUploadThreshold(30);
	 
    // log an event
    amplitude.logEvent(eventName);
	 
    // log an event with data
    amplitude.logEvent(eventName, { foo: bar });
	 
    // log an event with a custom timestamp (data is optional)
    // timestamp should be the number of milliseconds since Unix epoch
    amplitude.logEventWithTimestamp(eventName, timestamp, { foo: bar });
	 
    // set the user id
    amplitude.setUserId('1D32FS45');
	 
    // get user id that you set with `setUserId` method (null by default)
    amplitude.getUserId();
	 
    // set user props
    amplitude.setUserProperties({ hairColor: 'brown' });

    // sets whether or not to opt a user out logging
    amplitude.setOptOut(true);
	 
    // log revenue
    amplitude.logRevenue(productIdentifier, quantity, amount)

    /**
      *  RevenueProperties {
      *    productId?: string;
      *    quantity?: number; //default = 1
      *    price: number;
      *    revenueType?: string;
      *    receipt?: string;
      *    receiptSignature?: string;
      *    eventProperties?: {[key: string]: any},
      *  }
      */
    amplitude.logRevenueV2(revenueProperties)

    // add to user property
    amplitude.addToUserProperty(property, amount)

    // append to user property
    amplitude.appendToUserProperty(property, 'stringValue')

    // prepend to user property
    amplitude.prependToUserProperty(property, 'stringValue')

    // set user property once
    amplitude.setUserPropertyOnce(property, 'stringValue')

    // get device id as logged in Amplitude
    amplitude.getDeviceId().then(deviceId => ...)

    // get the current session ID as logged in Amplitude
    amplitude.getSessionId().then(sessionId => ...)
  }
  ...
}

there's also an example project here.