Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

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

Open
vovka-s opened this issue Aug 19, 2022 · 1 comment

Comments

@vovka-s
Copy link

vovka-s commented Aug 19, 2022

Привет!
Столкнулся с крешами приложухи, возникающими из-за вызовова 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
Copy link

ghost commented Aug 19, 2022 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant