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

@yyyyu/react-native-mta

v2.1.0

Published

react native for tencent mta.

Downloads

6

Readme

react-native-mta

  • iOS SDK VERSION 2.4.3
  • Android SDK VERSION 3.4.7

安装

yarn add @yyyyu/react-native-mta

or

npm install --save @yyyyu/react-native-mta

配置

ios

1. 自动配置(推荐)

react-native link @yyyyu/react-native-mta

如果项目使用 Pods 管理依赖需要在 Podfile 中添加

pod 'React', :path => '../node_modules/react-native', :subspecs => ['Dependency']

2. 手动配置

  1. 使用 Xcode 打开项目,在项目依赖目录(Libraries)下添加 node_modules 中的 react-native-mta 项目
  2. 在 Linked Frameworks and Libraries 添加 libRNMta.a

额外配置(使用 Pods 管理依赖不需要进行此操作)

在 Linked Frameworks and Libraries 添加 libsqlite3.tbd

android

1. 自动配置(如果 IOS 已经运行过,不需要重复运行)

react-native link @yyyyu/react-native-mta

由于有 npm scope 存在,导致自动 link 会添加 scope 包含 '@' 字符,导致 gradle 同步出错,所以在 link 后会自动化修改去除 scope 使 gradle 正常运行,如果多次 link 请手动删除重复的配置。

2. 手动配置

  1. 在 android/settings.gradle 文件中添加

    include ':react-native-mta'
    project(':react-native-mta').projectDir = new File(rootProject.projectDir, '../node_modules/@yyyyu/react-native-mta/android')
  2. 在 android/app/build.gradle 文件中依赖部分添加

    dependencies {
        // other dependencies
        compile project(':react-native-mta')
    }
  3. 在 MainApplication.java 文件中添加

    import com.rnlib.mta.RNMtaPackage;
    
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
          // other packages
            new RNMtaPackage()
        );
    }

额外配置

在 android/app/build.gradle 文件默认配置部分添加如下参数,此部分可以通过代码动态覆盖,gradle 同步时不添加则会出错无法编译

android {
    defaultConfig {
    	// add this
        manifestPlaceholders = [
            MTA_APPKEY: "",
            MTA_CHANNEL: ""
        ]
    }
}

JS API

import mta from '@yyyyu/react-native-mta'

mta.startWithAppkey({ appKey: 'appKey' })
  .then(res => { console.log(res) })
  .catch(err => { console.error(err) })

参数说明

  1. 参数注释带有 optional 字样为可选参数,括号内为默认值,e.g. optional('default')
  2. iosOnly androidOnly 表示只有在相应平台才会生效
  3. 事件类型接口参数值只支持字符串(sdk 限制: 目前单个参数值最长支持64位,请您控制参数值长度,不建议上传URL;支持类型为字符串类型,暂不支持其他类型。)

返回值说明

  1. 所有函数均以 es7 async 形式创建
  2. 如果库未初始化,调用函数会抛出初始化失败异常错误
  3. 除 CustomEvent 系列函数有精确错误描述(原生 SDK 提供错误信息)外,其余函数均以返回 boolean 表示调用成功或失败,由于上报与业务逻辑联系不紧密,所以即便调用失败情况下也不会抛出异常,避免未处理错误导致应用不必要的闪退
  4. 返回类型
    • Boolean

    • Object

      { errCode: 0, errMsg: '' }
      { errCode: -1, errMsg: 'MTA初始化未成功' }
      { errCode: -2, errMsg: 'MTA传入参数错误' }
      { errCode: -3, errMsg: 'MTA传入参数过长' }
      { errCode: -9, errMsg: '未知错误' }

startWithAppkey 初始化 MTA 模块

mta.startWithAppkey({
  appKey: 'you app key', // mta 管理后台中拿到的 appKey(*ios android 不同*)
  channel: 'channel',    // androidOnly optional('')
  isDebug: false,        // androidOnly optional(false)
})

trackPageBegin 跟踪页面打开

mta.trackPageBegin({
  page: 'page_id',      // 页面标识
  appKey: 'you app key' // iosOnly optional(初始化 appKey)
})

trackPageEnd 跟踪页面关闭

mta.trackPageEnd({
  page: 'page_id',       // 跟踪页面标识
  appKey: 'you app key', // iosOnly optional(初始化 appKey)
  isRealTime: false      // iosOnly optional(false) 是否实时上报数据
})

trackCustomEvent 自定义事件

mta.trackCustomEvent({
  event: 'event_id',     // 事件标识
  params: {},            // optional({}) 事件参数
  appKey: 'you app key', // iosOnly optional(初始化 appKey)
  isRealTime: false      // iosOnly optional(false) 是否实时上报数据
})

trackCustomEventBegin 自定义事件开始

mta.trackCustomEventBegin({
  event: 'event_id',     // 事件标识
  params: {},            // optional({}) 事件参数
  appKey: 'you app key', // iosOnly optional(初始化 appKey)
  isRealTime: false      // iosOnly optional(false) 是否实时上报数据
})

trackCustomEventEnd 自定义事件结束

mta.trackCustomEventEnd({
  event: 'event_id',     // 事件标识
  params: {},            // optional({}) 事件参数
  appKey: 'you app key', // iosOnly optional(初始化 appKey)
  isRealTime: false      // iosOnly optional(false) 是否实时上报数据
})

trackCustomEventDuration 持续一段时间的自定义事件

mta.trackCustomEventDuration({
  event: 'event_id',     // 事件标识
  duration: 1000,        // 事件持续时间
  params: {},            // optional({}) 事件参数
  appKey: 'you app key', // iosOnly optional(初始化 appKey)
  isRealTime: false      // iosOnly optional(false) 是否实时上报数据
})

trackActiveBegin 跟踪应用进入前台

mta.trackActiveBegin() // iosOnly

trackActiveEnd 跟踪应用进入后台

mta.trackActiveEnd() // iosOnly

setUserProperty 设置自定义参数

mta.setUserProperty({ customKey: 'customValue' })