@mytracker/react-native-mytracker

1.0.4 • Public • Published

myTracker React Native SDK

Platforms License

myTracker — free mobile analytics for iOS and Android platforms. Get connected to know everything about your apps, audience and advertising campaigns.

Integrate

Installation

  • NPM

    Add the following line to your package.json file in a dependencies key:

     	"@mytracker/react-native-mytracker": "1.0.x"
  • Imports

    To use MyTracker in your app import RNMyTracker:

     	import RNMyTracker from '@mytracker/react-native-mytracker';

    If you have to use StoreKit purchases you also have to import special classes:

     	import { StoreKitProduct, StoreKitProductDiscount, StoreKitProductSubscriptionPeriod, StoreKitTransaction } from '@mytracker/react-native-mytracker';

Usage

Initialization

const myTracker = RNMyTracker;
myTracker.setDebugMode(true); // enable/disable debug mode, false by default
myTracker.initTracker('your_sdk_key'); // sdk key that you can get in your myTracker account

Parameters and configuration

const config = myTracker.getTrackerConfig() 

The method returns tracker configuration.

Configuration

config.getTrackingLaunchEnabled() 
// isEnabled: required, bool
config.setTrackingLaunchEnabled(isEnabled) 

App launch tracking. True by default.

config.getLaunchTimeout() 
// seconds: required, number in range
config.setLaunchTimeout(seconds) 

An interval (in seconds) during which a new launch is not tracked and a session is not interrupted while app is in background. 30 seconds by default. Possible value range: 30-7200 seconds.

config.getBufferingPeriod() 
// seconds: required, number in range
config.setBufferingPeriod(seconds) 

The time during which events are accumulated locally on the device before being sent to the MyTracker server. The default value is 900 seconds, allowed values are: 1-86400 seconds (1 day).

config.getForcingPeriod() 
// seconds: required, number in range
config.setForcingPeriod(seconds) 

An interval (in seconds) starting from application install/update during which any new event will be sent to the server immediately, without local buffering. Default value is set to 0 (immediate sending is disabled), allowed values are 0-432000 seconds (5 days).

config.getAutotrackingPurchaseEnabled() 
// isEnabled: required, boolean
config.setAutotrackingPurchaseEnabled(isEnabled)

If inApp purchase events should be tracked automatically. True by default.

config.getTrackingLocation() 
// mode: required, enum from getConstants.LOCATION
config.setTrackingLocation(mode)

Geolocation tracking. False by default. If your application requests location access, you can enable this parameter to improve an accuracy of statistics related to the user geography. In some cases, location tracking also improves attribution and predictive models (Fraud Scanner, Personalize, LTV Predictions, etc.).

config.getRegion() 
// region: required, enum from getConstants.REGION
config.setRegion(region) 

Since March 1, 2023, the region parameter is disabled. Regardless of the selected value, the data will be sent to servers located in the Russian Federation. To select a different region, please contact our support team

Where the data collection server is located.

const configConstants = config.getConstants()

Collection of constants:

configConstants.LOCATION.NONE
configConstants.LOCATION.ACTIVE
configConstants.LOCATION.CACHED

configConstants.REGION.RU
configConstants.REGION.EU
configConstants.REGION.REGION_NOT_SET



Parameters

const params = myTracker.getTrackerParams() 

The method returns tracker parameters.

// gender: required, enum from getConstants().GENDER
params.setGender(gender) 

Sets user's gender.

// age: required, number
params.setAge(age) 

Sets user's age.

// language: required, string
params.setLanguage(language) 

Sets user's language.

// customUserIds: required, array
params.setCustomUserIds(customUserIds) 

Sets user's custom identifier.

const constants = getConstants() 

Returns constants like:

constants.GENDER.UNSPECIFIED
constants.GENDER.UNKNOWN
constants.GENDER.MALE
constants.GENDER.FEMAL

Events

// userId: required, string
myTracker.trackRegistrationEvent(userId) 

Track registration event.

// userId: required, string
myTracker.trackLoginEvent(userId) 

Track login event.

// eventParams: optional, Map<key: string_255, value: string_255>
myTracker.trackInviteEvent(eventParams) 

Track invite event.

// level: optional, number
// eventParams: optional, Map<key: string_255, value: string_255>
myTracker.trackLevelAchieved(level, eventParams) 

The method keeps track level achievement event, in a game for example.

// name: required, string_255
// eventParams: optional, Map<key: string_255, value: string_255>
myTracker.trackEvent(name, eventParams) 

The method can track custom event with name and event parameters.

// product: required, StoreKitProduct
// transaction: required, StoreKitTransaction
// eventParams: optional, Map<key: string_255, value: string_255>
myTracker.trackStoreKitPurchase(product, transaction, eventParams) 

The method iOS only, track purchase event if purchase autotracking disabled.

// skuDetails: required, Map
// purchaseData: required, Map
// dataSignature: required, String
// eventParams: optional, Map<key: string_255, value: string_255>
myTracker.trackGooglePlayPurchase(skuDetails, purchaseData, dataSignature, eventParams) 

The method Android only, track purchase event if purchase autotracking disabled. Only for Google purchases.

// resultCode: required, number
// purchaseData: required, Map
// dataSignature: required, String
myTracker.onActivityResult(resultCode, purchaseData, dataSignature)

If you use you own In-App Billing API implementation or Huawei In-App Purchases API, for automatic purchase events tracking you should call the corresponding MyTracker method from onActivityResult method of activity that started the purchase process.

// responseCode: required, number
// purchaseData: required, Map
// dataSignature: required, String
myTracker.onPurchasesUpdated(responseCode, purchaseData, dataSignature) 

If you use the Google Play Billing Library, for automatic purchase events tracking you should call the corresponding MyTracker method from onPurchasesUpdated method of BillingClient listener.

Other

myTracker.getInstanceId() 

The method returns instance ID.

myTracker.flush() 

The method forcibly sends events.

Package Sidebar

Install

npm i @mytracker/react-native-mytracker

Weekly Downloads

2

Version

1.0.4

License

LGPL-3.0

Unpacked Size

170 kB

Total Files

39

Last publish

Collaborators

  • aleksei.anisimov.vk
  • alexander_vorobyev
  • a.seredkin
  • zaakk
  • skandakov