@@ -956,7 +956,7 @@ static void onAppFocus() {
956
956
957
957
getCurrentPermissionState (appContext ).refreshAsTo ();
958
958
959
- if (trackFirebaseAnalytics != null )
959
+ if (trackFirebaseAnalytics != null && getFirebaseAnalyticsEnabled ( appContext ) )
960
960
trackFirebaseAnalytics .trackInfluenceOpenEvent ();
961
961
}
962
962
@@ -1487,7 +1487,7 @@ public void run() {
1487
1487
}
1488
1488
});
1489
1489
1490
- if (trackFirebaseAnalytics != null )
1490
+ if (trackFirebaseAnalytics != null && getFirebaseAnalyticsEnabled ( appContext ) )
1491
1491
trackFirebaseAnalytics .trackOpenedEvent (openedResult );
1492
1492
}
1493
1493
@@ -1501,7 +1501,7 @@ static void handleNotificationReceived(JSONArray data, boolean displayed, boolea
1501
1501
OSNotificationOpenResult openResult = generateOsNotificationOpenResult (data , displayed , fromAlert );
1502
1502
mInitBuilder .mNotificationReceivedHandler .notificationReceived (openResult .notification );
1503
1503
1504
- if (trackFirebaseAnalytics != null )
1504
+ if (trackFirebaseAnalytics != null && getFirebaseAnalyticsEnabled ( appContext ) )
1505
1505
trackFirebaseAnalytics .trackReceivedEvent (openResult );
1506
1506
1507
1507
}
@@ -1634,6 +1634,26 @@ static void updateUserIdDependents(String userId) {
1634
1634
OneSignalChromeTab .setup (appContext , appId , userId , AdvertisingIdProviderGPS .getLastValue ());
1635
1635
}
1636
1636
1637
+ /**
1638
+ * By default, OneSignal does not auto-track notification events through Firebase.
1639
+ * Call this method with {@code true} to start tracking.
1640
+ *
1641
+ * @see <a href="https://documentation.onesignal.com/docs/firebase-analytics">Firebase Analytics | OneSignal Docs</a>
1642
+ * @param enable whether to enable Firebase tracking
1643
+ */
1644
+ public static void enableFirebaseAnalytics (boolean enable ) {
1645
+ if (appContext == null )
1646
+ return ;
1647
+
1648
+ OneSignalPrefs .saveBool (OneSignalPrefs .PREFS_ONESIGNAL ,
1649
+ OneSignalPrefs .PREFS_GT_FIREBASE_TRACKING_ENABLED , enable );
1650
+ }
1651
+
1652
+ static boolean getFirebaseAnalyticsEnabled (Context context ) {
1653
+ return OneSignalPrefs .getBool (OneSignalPrefs .PREFS_ONESIGNAL ,
1654
+ OneSignalPrefs .PREFS_GT_FIREBASE_TRACKING_ENABLED ,false );
1655
+ }
1656
+
1637
1657
// If true(default) - Device will always vibrate unless the device is in silent mode.
1638
1658
// If false - Device will only vibrate when the device is set on it's vibrate only mode.
1639
1659
/**
0 commit comments