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-hero/umeng-analytics

v0.3.1

Published

react native umeng analytics

Downloads

45

Readme

@react-native-hero/umeng-analytics

Getting started

Install the library using either Yarn:

yarn add @react-native-hero/umeng-analytics

or npm:

npm install --save @react-native-hero/umeng-analytics

Link

  • React Native v0.60+

For iOS, use cocoapods to link the package.

run the following command:

$ cd ios && pod install

For android, the package will be linked automatically on build.

  • React Native <= 0.59

run the following command to link the package:

$ react-native link @react-native-hero/umeng-analytics

Setup

image

打开应用信息页面,安卓推送有 AppkeyUmeng Message Secret 两个字段,iOS 只有 Appkey 字段,后面将用这些字段初始化友盟。

iOS

修改 AppDelegate.m,如下

#import <RNTUmengAnalytics.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ...
  // 初始化友盟基础库
  // channel 一般填 App Store,如果有测试环境,可按需填写
  // debug 表示是否打印调试信息
  [RNTUmengAnalytics init:@"appKey" channel:@"App Store" debug:false];
  return YES;
}

Android

修改 android/build.gradle,如下:

allprojects {
    repositories {
        // 确保添加了友盟仓库
        maven { url 'https://repo1.maven.org/maven2/' }
    }
}

android/app/build.gradle 根据不同的包填写不同的配置,如下:

buildTypes {
    debug {
        manifestPlaceholders = [
            UMENG_APP_KEY: '',
            UMENG_PUSH_SECRET: '',
            UMENG_CHANNEL: '',
        ]
    }
    release {
        manifestPlaceholders = [
            UMENG_APP_KEY: '',
            UMENG_PUSH_SECRET: '',
            UMENG_CHANNEL: '',
        ]
    }
}

MainApplicationonCreate 方法进行初始化,如下:

Kotlin 版本

override fun onCreate() {
    val metaData = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA).metaData

    // 初始化友盟基础库
    // 第三个参数表示是否显示调试信息
    RNTUmengAnalyticsModule.init(this, metaData, false)
}

Java 版本

// onCreate 方法体换成下面这段
Bundle metaData  = this.getPackageManager().getApplicationInfo(
  this.getPackageName(), PackageManager.GET_META_DATA
).metaData;
RNTUmengAnalyticsModule.init(this, metaData, false);

配置混淆规则

android/app/proguard-rules.pro 添加以下混淆规则,注意替换自己的包名,并且删掉 []

-keep public class [您的应用包名].R$*{
public static final int *;
}

Usage

import {
  // 初始化友盟时传入的 channel 参数
  CHANNEL,

  init,
  getDeviceInfo,
  getPhoneNumber,
  signIn,
  signOut,
  exitApp,
  enterPage,
  leavePage,
  sendEvent,
  sendEventLabel,
  sendEventData,
  sendEventCounter,
} from '@react-native-hero/umeng-analytics'

// 对于安卓来说,需要等用户同意隐私政策后,再调用 init,js 的 init 才是真正的初始化
// https://developer.umeng.com/docs/119267/detail/182050
init().then(() => {
  // 初始化完成
})

// 提供一个退出 app 的方法
// 好像 RN 官方也没提供此方法,单个方法不好写一个库,就放在这个库了
exitApp()

// 以下方法必须等 init() 调用结束后才能调用,否则会抛出错误

getDeviceInfo().then(data => {
  data.deviceId
  data.deviceType
  data.brand
  data.bundleId
})

getUserAgent().then(data => {
  data.userAgent
})

getPhoneNumber().then(data => {
  // 只有安卓有希望读取出本机的手机号码,前提是已获得 READ_PHONE_STATE 权限
  data.phoneNumber
})

// 帐号统计
signIn('userId')
// provider 不能以下划线开头,使用大写字母和数字标识
// 如果是上市公司,建议使用股票代码,比如 WB
signIn('userId', 'provider')
signOut()

// 页面统计,注意要配对调用
// 不能连续调用 enterPage,也不能连续调用 leavePage
enterPage('pageName')
leavePage('pageName')

// 自定义事件,eventId 需先在友盟后台注册之后才可以统计
sendEvent('eventId')
sendEventLabel('eventId', 'label')
sendEventData('eventId', { key1: 'value1', key2: 'value2' })
sendEventCounter('eventId', { key1: 'value1', key2: 'value2' }, 1)