Skip to content

hyquang/agrid-react-native

Repository files navigation

Agrid React Native Analytics

Thư viện analytics cho React Native, cung cấp capture event, identify user và track screen cho ứng dụng mobile.

Cài Đặt

  • npm install agrid-react-native hoặc yarn add agrid-react-native
  • Yêu cầu React Native ≥ 0.60 (autolinking)

iOS Setup

  • Podfile trong ios/Podfile:
    • Thêm: require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
    • Trong target 'YourApp' do thêm: use_native_modules!
    • Nếu autolinking không nhận, thêm: pod 'RNAgridAnalytics', :path => '../node_modules/agrid-react-native'
  • Chạy cd ios && pod install
  • Nếu lỗi glog/C compiler:
    • Cài Command Line Tools: xcode-select --install
    • Mở Xcode và chấp nhận SDK
    • Xóa cache rồi cài lại: rm -rf ~/Library/Caches/CocoaPods Pods *.xcworkspace *.xcodeproj/xcuserdata && pod repo update && pod install

Android Setup

  • Autolinking: không thêm thủ công vào settings.gradle
  • Đảm bảo môi trường Android (JDK 11/17, Android SDK/ADB, emulator/device)
  • Làm sạch và chạy: cd android && ./gradlew clean sau đó react-native run-android

Sử Dụng

import analytics from 'agrid-react-native'

await analytics.setup('YOUR_API_KEY', {
  host: 'https://stg-gw.track-asia.vn',
  captureApplicationLifecycleEvents: true,
  recordScreenViews: true,
  flushInterval: 30,
  flushAt: 20,
})

await analytics.capture('User Signed Up', { plan: 'premium' })
await analytics.identify('user123', { email: 'user@example.com' })
await analytics.screen('Home Screen', { ref: 'login' })
await analytics.alias('legacy-id')
await analytics.flush()

API

  • setup(apiKey, config)
  • capture(event, properties?)
  • screen(title, properties?)
  • identify(distinctId|null, properties?)
  • alias(alias)
  • reset()
  • flush()
  • enable() / disable()
  • getAnonymousId(): Promise<string>
  • catch(handler: (err: Error) => void) để bắt lỗi bridge
  • middleware(fn) để can thiệp payload trước khi gọi native

Configuration

  • Chung: host, debug, flushAt (mặc định 20), flushInterval (mặc định 30s), recordScreenViews, captureApplicationLifecycleEvents, captureDeepLinks
  • iOS: capturePushNotifications, captureInAppPurchases, shouldUseBluetooth, shouldUseLocationServices, maxQueueSize (mặc định 1000)
  • Android: collectDeviceId (mặc định true)

Troubleshooting

  • “Failed to load RNAgridAnalytics native module”:
    • iOS: đảm bảo pod install thành công và Podfile đã bật autolinking hoặc thêm pod thủ công
    • Android: đảm bảo môi trường SDK/JDK/ADB, autolinking không bị override, chạy ./gradlew clean
    • Reset Metro cache: npm start -- --reset-cache
  • “Failed to load PostHog native module”: đang dùng phiên bản cũ hoặc gói posthog-react-native. Cập nhật lên agrid-react-native@latest.

Góp Ý & Hỗ Trợ

  • Tạo issue trên repository khi cần hỗ trợ.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7