Merge pull request #16 from hssrrw/activation-config

Add activation config
This commit is contained in:
Aleksei Androsov 2018-09-10 16:07:23 +03:00 committed by GitHub
commit 83386897be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 1 deletions

View File

@ -33,6 +33,12 @@ import AppMetrica from 'react-native-appmetrica';
// Starts the statistics collection process.
AppMetrica.activateWithApiKey('...KEY...');
// OR
AppMetrica.activateWithConfig({
apiKey: '...KEY...',
sessionTimeout: 120,
firstActivationAsUpdate: true,
});
// Sends a custom event message and additional parameters (optional).
AppMetrica.reportEvent('My event');

View File

@ -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
public void reportError(String message) {
try {

View File

@ -3,6 +3,12 @@
import { NativeModules } from 'react-native';
const { AppMetrica } = NativeModules;
type ActivationConfig = {
apiKey: string,
sessionTimeout?: number,
firstActivationAsUpdate?: boolean,
};
export default {
/**
@ -13,6 +19,14 @@ export default {
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).
* @param {string} message

View File

@ -2,7 +2,7 @@
#import <YandexMobileMetrica/YandexMobileMetrica.h>
@implementation RCTAppMetrica {
}
RCT_EXPORT_MODULE();
@ -13,6 +13,17 @@ RCT_EXPORT_METHOD(activateWithApiKey:(NSString *)apiKey)
[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)
{
[YMMYandexMetrica reportEvent:message onFailure:NULL];