Merge pull request #16 from hssrrw/activation-config
Add activation config
This commit is contained in:
commit
83386897be
@ -33,6 +33,12 @@ import AppMetrica from 'react-native-appmetrica';
|
|||||||
|
|
||||||
// Starts the statistics collection process.
|
// Starts the statistics collection process.
|
||||||
AppMetrica.activateWithApiKey('...KEY...');
|
AppMetrica.activateWithApiKey('...KEY...');
|
||||||
|
// OR
|
||||||
|
AppMetrica.activateWithConfig({
|
||||||
|
apiKey: '...KEY...',
|
||||||
|
sessionTimeout: 120,
|
||||||
|
firstActivationAsUpdate: true,
|
||||||
|
});
|
||||||
|
|
||||||
// Sends a custom event message and additional parameters (optional).
|
// Sends a custom event message and additional parameters (optional).
|
||||||
AppMetrica.reportEvent('My event');
|
AppMetrica.reportEvent('My event');
|
||||||
|
@ -42,6 +42,23 @@ public class AppMetricaModule extends ReactContextBaseJavaModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void activateWithConfig(ReadableMap params) {
|
||||||
|
YandexMetricaConfig.Builder configBuilder = YandexMetricaConfig.newConfigBuilder(params.getString("apiKey"));
|
||||||
|
if (params.hasKey("sessionTimeout")) {
|
||||||
|
configBuilder.withSessionTimeout(params.getInt("sessionTimeout"));
|
||||||
|
}
|
||||||
|
if (params.hasKey("firstActivationAsUpdate")) {
|
||||||
|
configBuilder.handleFirstActivationAsUpdate(params.getBoolean("firstActivationAsUpdate"));
|
||||||
|
}
|
||||||
|
YandexMetrica.activate(getReactApplicationContext().getApplicationContext(), configBuilder.build());
|
||||||
|
Activity activity = getCurrentActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
Application application = activity.getApplication();
|
||||||
|
YandexMetrica.enableActivityAutoTracking(application);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void reportError(String message) {
|
public void reportError(String message) {
|
||||||
try {
|
try {
|
||||||
|
14
index.js
14
index.js
@ -3,6 +3,12 @@
|
|||||||
import { NativeModules } from 'react-native';
|
import { NativeModules } from 'react-native';
|
||||||
const { AppMetrica } = NativeModules;
|
const { AppMetrica } = NativeModules;
|
||||||
|
|
||||||
|
type ActivationConfig = {
|
||||||
|
apiKey: string,
|
||||||
|
sessionTimeout?: number,
|
||||||
|
firstActivationAsUpdate?: boolean,
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,6 +19,14 @@ export default {
|
|||||||
AppMetrica.activateWithApiKey(apiKey);
|
AppMetrica.activateWithApiKey(apiKey);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the statistics collection process using config.
|
||||||
|
* @param {object} params
|
||||||
|
*/
|
||||||
|
activateWithConfig(params: ActivationConfig) {
|
||||||
|
AppMetrica.activateWithConfig(params);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a custom event message and additional parameters (optional).
|
* Sends a custom event message and additional parameters (optional).
|
||||||
* @param {string} message
|
* @param {string} message
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#import <YandexMobileMetrica/YandexMobileMetrica.h>
|
#import <YandexMobileMetrica/YandexMobileMetrica.h>
|
||||||
|
|
||||||
@implementation RCTAppMetrica {
|
@implementation RCTAppMetrica {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_MODULE();
|
RCT_EXPORT_MODULE();
|
||||||
@ -13,6 +13,17 @@ RCT_EXPORT_METHOD(activateWithApiKey:(NSString *)apiKey)
|
|||||||
[YMMYandexMetrica activateWithConfiguration:configuration];
|
[YMMYandexMetrica activateWithConfiguration:configuration];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RCT_EXPORT_METHOD(activateWithConfig:(NSDictionary *)config) {
|
||||||
|
YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:config[@"apiKey"]];
|
||||||
|
if (config[@"sessionTimeout"] != (id)[NSNull null]) {
|
||||||
|
[configuration setSessionTimeout:[config[@"sessionTimeout"] intValue]];
|
||||||
|
}
|
||||||
|
if (config[@"firstActivationAsUpdate"] != (id)[NSNull null]) {
|
||||||
|
[configuration setHandleFirstActivationAsUpdate:[config[@"firstActivationAsUpdate"] boolValue]];
|
||||||
|
}
|
||||||
|
[YMMYandexMetrica activateWithConfiguration:configuration];
|
||||||
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(reportEvent:(NSString *)message)
|
RCT_EXPORT_METHOD(reportEvent:(NSString *)message)
|
||||||
{
|
{
|
||||||
[YMMYandexMetrica reportEvent:message onFailure:NULL];
|
[YMMYandexMetrica reportEvent:message onFailure:NULL];
|
||||||
|
Loading…
Reference in New Issue
Block a user