yandexmobile / metrica-plugin-cordova

Cordova plugin for Yandex AppMetrica SDK
Other
11 stars 26 forks source link

Креши приложения из-за вызов репортов до инициализации метрики #30

Open vovka-s opened 2 years ago

vovka-s commented 2 years ago

Привет! Столкнулся с крешами приложухи, возникающими из-за вызовова reportEvent до инициализации метрики Добавил проверок на активность - креши прекратились. Прошу проверить, всё ли верно, и залить в реп

diff --git a/node_modules/yandex-appmetrica-plugin-cordova/platforms/android/com/yandex/metrica/plugin/cordova/AppMetricaPlugin.java b/node_modules/yandex-appmetrica-plugin-cordova/platforms/android/com/yandex/metrica/plugin/cordova/AppMetricaPlugin.java
index 1512def..ff1300a 100644
--- a/node_modules/yandex-appmetrica-plugin-cordova/platforms/android/com/yandex/metrica/plugin/cordova/AppMetricaPlugin.java
+++ b/node_modules/yandex-appmetrica-plugin-cordova/platforms/android/com/yandex/metrica/plugin/cordova/AppMetricaPlugin.java
@@ -209,10 +209,12 @@ public class AppMetricaPlugin extends CordovaPlugin {
             eventParametersJSONString = eventParametersObj.toString();
         } catch (JSONException ignored) {}

-        if (eventParametersJSONString != null) {
-            YandexMetrica.reportEvent(eventName, eventParametersJSONString);
-        } else {
-            YandexMetrica.reportEvent(eventName);
+        if (mAppMetricaActivated) {
+            if (eventParametersJSONString != null) {
+                YandexMetrica.reportEvent(eventName, eventParametersJSONString);
+            } else {
+                YandexMetrica.reportEvent(eventName);
+            }
         }
     }

@@ -225,7 +227,9 @@ public class AppMetricaPlugin extends CordovaPlugin {
             errorThrowable = new Throwable(errorReason);
         } catch (JSONException ignored) {}

-        YandexMetrica.reportError(errorName, errorThrowable);
+        if (mAppMetricaActivated) {
+            YandexMetrica.reportError(errorName, errorThrowable);
+        }
     }

     private void setLocation(final JSONArray args,
@@ -233,13 +237,18 @@ public class AppMetricaPlugin extends CordovaPlugin {
         final JSONObject locationObj = args.getJSONObject(0);

         final Location location = toLocation(locationObj);
-        YandexMetrica.setLocation(location);
+
+        if (mAppMetricaActivated) {
+            YandexMetrica.setLocation(location);
+        }
     }

     private void setLocationTracking(final JSONArray args,
                                      final CallbackContext callbackContext) throws JSONException {
         final boolean enabled = args.getBoolean(0);

-        YandexMetrica.setLocationTracking(enabled);
+        if (mAppMetricaActivated) {
+            YandexMetrica.setLocationTracking(enabled);
+        }
     }
 }

This issue body was partially generated by patch-package.

ghost commented 2 years ago

Добрый день!Ваше письмо получено и зарегистрировано под уникальным номером № 18823391. Ответ обязательно будет предоставлен, пожалуйста, ожидайте.Просим Вас не отправлять повторное письмо по данному вопросу - оно будет считаться новой заявкой и может быть обработано позднее.Помощь сервиса: https://yandex.ru/support/direct/?from=email--С уважением,Отдел клиентского сервисател.: 8 800 234-24-80 (звонок из регионов России бесплатный)тел.: +7 495 739-37-77&nbsp19.08.2022, 19:43, "vovka-s" @.***>: Привет! Столкнулся с крешами приложухи, возникающими из-за вызовова reportEvent до инициализации метрики Добавил проверок на активность - креши прекратились. Прошу проверить, всё ли верно, и залить в реп diff --git a/node_modules/yandex-appmetrica-plugin-cordova/platforms/android/com/yandex/metrica/plugin/cordova/AppMetricaPlugin.java b/node_modules/yandex-appmetrica-plugin-cordova/platforms/android/com/yandex/metrica/plugin/cordova/AppMetricaPlugin.java index 1512def..ff1300a 100644 --- a/node_modules/yandex-appmetrica-plugin-cordova/platforms/android/com/yandex/metrica/plugin/cordova/AppMetricaPlugin.java +++ b/node_modules/yandex-appmetrica-plugin-cordova/platforms/android/com/yandex/metrica/plugin/cordova/AppMetricaPlugin.java @@ -209,10 +209,12 @@ public class AppMetricaPlugin extends CordovaPlugin { eventParametersJSONString = eventParametersObj.toString(); } catch (JSONException ignored) {}

@@ -225,7 +227,9 @@ public class AppMetricaPlugin extends CordovaPlugin { errorThrowable = new Throwable(errorReason); } catch (JSONException ignored) {}

This issue body was partially generated by patch-package.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>