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-plugin-zhugeio

v2.0.4

Published

React-native Plugin For Zhugeio Mobile Analytics

Downloads

259

Readme

react-native-zhugeio

诸葛移动统计的react-native插件

1. 环境需求

  • iOS 8.0

    部分代码运行于8.0的系统

  • Android SDK 11+

    zhuge SDK本身代码支持Android 11+的系统,但React-native仅运行于Android 16+

  • react-native 0.50+

  • react-native-cli 2.0+

    项目本身基于以上版本的react-native开发。因此目前不确定是否支持低版本的react-native。若集成不成功,请联系Zhuge

  • pod 1.0+

    iOS系统的集成依赖于cocoaPod工具

2. 集成方法

在你的React-native项目目录下

yarn add react-native-plugin-zhugeio

  $ npm install  react-native-plugin-zhugeio --save

  $ react-native link

2.1 iOS

  • 若在你的react-native项目的ios文件夹下,没有Podfile文件,那么初始化Pod

    $ pod init
    

以上命令将在ios目录下创建Podfile文件。

  • 编辑Podfile文件

    platform :ios, '8.0'
    
    target 'yourApp' do
        pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
        pod 'React', path: '../node_modules/react-native',:subspecs => ['DevSupport']
        pod 'react-native-plugin-zhugeio', path: '../node_modules/react-native-plugin-zhugeio'
    end
    
  • 执行pod install

  • ios/youProjectName/AppDelegate.m文件中,找到application didFinishLaunchingWithOptions 方法,在其中加入如下代码

    #import <ZhugeioAnalytics/Zhuge.h>

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        [[Zhuge sharedInstance] startWithAppKey:@"Your App Key" launchOptions:launchOptions];
    }
  • 若是私有部署的用户,需要更改数据上传地址,那么请将上述代码更改为:
    #import <ZhugeioAnalytics/Zhuge.h>

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        //设置上传地址,一般用户无需更改
        [[Zhuge sharedInstance] setUploadURL:@"https://www.zhugeio.com" andBackupUrl:nil];
        [[Zhuge sharedInstance] startWithAppKey:@"Your App Key" launchOptions:launchOptions];
    }

2.2 Android

  • 检查android/setting.gradle配置有没有包含以下内容:

       include ':react-native-plugin-zhugeio'
       project(':react-native-plugin-zhugeio').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-plugin-zhugeio/android')
    
  • 检查android/app/build.gradledependencies是否包含如下内容

      implementation project(':react-native-plugin-zhugeio')
    
  • 找到 android/youApp/src/main/java.../MainApplication.java 文件,添加如下代码

      import com.zhuge.analysis.stat.ZhugeSDK;// <--导入SDK
      import com.zhuge.reactnativezhuge.RNZhugeioPackage;//<--导入react-native接口
    
      public class MainApplication extends Application implements ReactApplication {
          @Override
          public void onCreate(){
             Super.onCreate();
             ...
             //ZhugeSDK初始化
             ZhugeSDK.getInstance().init(this,"yourAppKey","youAppChannel");   
             ...
       
          }
    
          private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    
            @Override
            protected List<ReactPackage> getPackages() {
              return Arrays.<ReactPackage>asList(
                 new MainReactPackage(),
                 //注册Zhugeio
                 new RNZhugeioPackage()
              );
            }
          };
      }
    
  • 若您是私有部署的用户,需要更改数据上传地址,那么请将上述onCreate()里的代码更改为:

        @Override
        public void onCreate(){
           Super.onCreate();
           ...
           //设置上传地址,普通用户请勿更改。必须在调用init之前设置
           ZhugeSDK.getInstance().setUploadURL("https://www.zhugeio.com",null)
           //ZhugeSDK初始化
           ZhugeSDK.getInstance().init(this,"yourAppKey","youAppChannel");   
           ...
     
        }
    

3. 使用说明

  • 导入Zhugeio

    import Zhugeio from 'react-native-plugin-zhugeio'
    
  • track 追踪事件

    Zhugeio.track('事件名称',{'属性1':'值1','属性2':'值2'});
      
  • 自定义时长事件

    使用startTrack()开始事件

    Zhugeio.startTrack('事件名称');
    

    使用相同的事件名称结束事件

    Zhugeio.endTrack('事件名称',{'属性1':'值1'});
    

    startTrack()endTrack()需成对出现,单独使用没有效果。

  • 标记用户

    使用identify()标记用户

    Zhugeio.identify('用户ID',{'用户属性':'用户值'})
      
  • 开启实时调试

    Zhugeio.openDebug();
    
  • 开始日志输出

    该方法仅对Android平台可用,iOS平台请参阅 iOS集成文档

    Zhugeio.openLog();