add activation config
This commit is contained in:
parent
0452aa26fd
commit
a395a43e0c
@ -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');
|
||||
|
@ -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 {
|
||||
|
14
index.js
14
index.js
@ -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
|
||||
|
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user