"@mytracker/react-native-mytracker": "1.0.3"
Minimum supported Android version — 5.0 (API Level 21).
Minimum supported iOS version — 12.4.
Add the following line to the package.json file in a dependencies
key:
"@mytracker/react-native-mytracker": "1.0.3"
RNMyTracker
:
import RNMyTracker from '@mytracker/react-native-mytracker';
If you need to use StoreKit purchases, import special classes:
import { StoreKitProduct, StoreKitProductDiscount, StoreKitProductSubscriptionPeriod, StoreKitTransaction } from '@mytracker/react-native-mytracker';
To initialize SDK, you have to enter your SDK_KEY
.
And before that, you may set different settings for the
tracker (configurations, parameters, deep links, etc.).
App activity such as launches and sessions are tracked automatically.
SDK_KEY
is generated automatically after you added your application to MyTracker.
To get the key, go to the Application list page, select the required application, and copy the key from the Overview tab.
Please note that if you build an app for different platforms, you need individual SDK_KEY
for each of them.
const myTracker = RNMyTracker;
myTracker.initTracker('SDK_KEY');
Configuration can be set up by the myTracker.getTrackerConfig()
method.
All parameters can be set up by the
myTracker.getTrackerParams()
method.
const config = myTracker.getTrackerConfig()
const params = myTracker.getTrackerParams()
TrackingLaunchEnabled: app launch tracking. True by default.
config.getTrackingLaunchEnabled()
// isEnabled: required, bool
config.setTrackingLaunchEnabled(isEnabled)
LaunchTimeout: 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.getLaunchTimeout()
// seconds: required, number in range
config.setLaunchTimeout(seconds)
BufferingPeriod: 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.getBufferingPeriod()
// seconds: required, number in range
config.setBufferingPeriod(seconds)
ForcingPeriod: an interval (in seconds) starting from application install/update during which any new event will be send 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.getForcingPeriod()
// seconds: required, number in range
config.setForcingPeriod(seconds)
AutotrackingPurchaseEnabled: automatic payment tracking. True by default.
config.getAutotrackingPurchaseEnabled()
// isEnabled: required, boolean
config.setAutotrackingPurchaseEnabled(isEnabled)
TrackingLocation: geolocation tracking. By default, it is Active for iOS and None for Android.
Available values:
config.getTrackingLocation()
// mode: required, enum from getConstants.LOCATION
config.setTrackingLocation(mode)
If your application requests access to location, you can enable this option to improve the accuracy of statistics related to the user geography. In some cases, location tracking also improves attribution and prediction models of Fraud Scanner, Personalize, and LTV Predictions.
Region, where the data collection server is located.
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
Choose a region based, for example, on current legislation. Available values:
RegionEnum.RU — server on the territory of Russian Federation
RegionEnum.EU — server on the territory of Europe
config.getRegion()
// region: required, enum from getConstants.REGION
config.setRegion(region)
Enabling and disabling debug mode can be done via myTracker
class static methods.
False by default.
myTracker.setDebugMode(true); // enable/disable debug mode, false by default
Set the customUserId
parameter to track user stats, not only device.
It's a unique user identifier in the project, that you specify at the time of registration.
The identifier should remain unchanged even when user switch devices.
The parameter allows you to estimate the size and activity of user base, regardless of the number of user devices.
Also, you can keep your customer data consistent if a user changes a device.
For details, see the User tracking section.
It's essential to set the parameter before tracking events to pass user identifier with every event.
const params = myTracker.getTrackerParams()
// customUserIds: required, array
params.setCustomUserIds(customUserIds)
If customUserId
was set to the application with an existing registered users, MyTracker cannot calculate exact Lifetime metrics without registration time.
For pre-registered users, Lifetime statistic will be count on the date of the first tracked event with customUserId
.
To turn off user tracking, pass an empty value in the customUserId
parameter.
Events can be sent via myTracker
class static methods.
Before you call methods, set the customUserId parameter
to pass user identifier with every tracked event.
The following methods for event tracking are available:
Registration event.
You should call the method right after user registered in the app.
Pass the user identifier in the required userId
parameter.
// userId: required, string
myTracker.trackRegistrationEvent(userId)
Login event.
You should call the method right after user successfully authorized in the app.
Pass the user identifier in the required userId
parameter.
// userId: required, string
myTracker.trackLoginEvent(userId)
Invite sent event. The extra eventParams
parameter allows for any key-value parameters to be
added for the event. Max. length of key and value — 255 chars.
// eventParams: optional, Map<key: string_255, value: string_255>
myTracker.trackInviteEvent(eventParams)
Level up event. The level
parameter is optional. Any optional parameters can be passed
with event as "key-value" by the optional eventParams
parameter. Max key or value length — 255
chars.
// level: optional, number
// eventParams: optional, Map<key: string_255, value: string_255>
myTracker.trackLevelAchieved(level, eventParams)
Any user defined event with a custom name. Any optional parameters can be passed with event
as "key-value" by the optional eventParams
parameter. Max name, key or value length — 255 chars.
// name: required, string_255
// eventParams: optional, Map<key: string_255, value: string_255>
myTracker.trackEvent(name, eventParams)
Force sending events from local buffer to server and reset buffering timers.
The SDK, which reduces channel load and lowers impact on app performance, collects all data
on the device before sending it off to the server and regularly does so in a compressed
format. By default, data is sent every 15 minutes. The interval can be changed to anywhere
from 1 second to 1 day through the bufferingPeriod
property.
If the user has quit the app, the events will be sent during next launch.
It's extremely important to analyse certain events as soon as possible, especially in the
first sessions since installing the app. The flush()
method will help.
myTracker.flush()
MyTracker collects data about in-app payments and subscriptions.
Track payment events if automatic payment tracking is disabled (AutotrackingPurchaseEnabled = false
).
// product: required, StoreKitProduct
// transaction: required, StoreKitTransaction
// eventParams: optional, Map<key: string_255, value: string_255>
myTracker.trackStoreKitPurchase(product, transaction, eventParams)
Track payment events if automatic payment tracking is disabled (AutotrackingPurchaseEnabled = false
). Only for Google purchases.
// skuDetails: required, Map
// purchaseData: required, Map
// dataSignature: required, String
// eventParams: optional, Map<key: string_255, value: string_255>
myTracker.trackGooglePlayPurchase(skuDetails, purchaseData, dataSignature, eventParams)
If you use your own In-App Billing API implementation
to automatically track payment events, you should call the corresponding MyTracker method from the onActivityResult
action method that triggered the payment process.
// resultCode: required, number
// purchaseData: required, Map
// dataSignature: required, String
myTracker.onActivityResult(resultCode, purchaseData, dataSignature)
If you use the Google Play Billing Library, for automatic payment events tracking you must call the corresponding MyTracker method from onPurchasesUpdated method of BillingClient listener.
// responseCode: required, number
// purchaseData: required, Map
// dataSignature: required, String
myTracker.onPurchasesUpdated(responseCode, purchaseData, dataSignature)
To send data from your server to MyTracker (for example, untracked data, offline events, etc.), you might need a special device identifier — instanceId
.
The instanceId
is a device identifier (UUID v4), that generated at the first app launch
and unchanged until a user delete the app (or app data) from device.
The instanceId
can get via myTracker
class static method.
myTracker.getInstanceId()
It's essential to collect instanceId
as soon as possible and send the identifier to your server
if you use this ID for work with S2S API.
Instead of instanceId
you can use any other device ID:
gaid
, androidId
, appSetId
,
idfa
, iosVendorId
,
and/or the user identifier customUserID
(in this case, S2S data will generate stats on users).
Learn more
Currently, React Native SDK does not support deep links