@@ -956,7 +956,7 @@ static void onAppFocus() {
956956
957957 getCurrentPermissionState (appContext ).refreshAsTo ();
958958
959- if (trackFirebaseAnalytics != null )
959+ if (trackFirebaseAnalytics != null && getFirebaseAnalyticsEnabled ( appContext ) )
960960 trackFirebaseAnalytics .trackInfluenceOpenEvent ();
961961 }
962962
@@ -1487,7 +1487,7 @@ public void run() {
14871487 }
14881488 });
14891489
1490- if (trackFirebaseAnalytics != null )
1490+ if (trackFirebaseAnalytics != null && getFirebaseAnalyticsEnabled ( appContext ) )
14911491 trackFirebaseAnalytics .trackOpenedEvent (openedResult );
14921492 }
14931493
@@ -1501,7 +1501,7 @@ static void handleNotificationReceived(JSONArray data, boolean displayed, boolea
15011501 OSNotificationOpenResult openResult = generateOsNotificationOpenResult (data , displayed , fromAlert );
15021502 mInitBuilder .mNotificationReceivedHandler .notificationReceived (openResult .notification );
15031503
1504- if (trackFirebaseAnalytics != null )
1504+ if (trackFirebaseAnalytics != null && getFirebaseAnalyticsEnabled ( appContext ) )
15051505 trackFirebaseAnalytics .trackReceivedEvent (openResult );
15061506
15071507 }
@@ -1634,6 +1634,26 @@ static void updateUserIdDependents(String userId) {
16341634 OneSignalChromeTab .setup (appContext , appId , userId , AdvertisingIdProviderGPS .getLastValue ());
16351635 }
16361636
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+
16371657 // If true(default) - Device will always vibrate unless the device is in silent mode.
16381658 // If false - Device will only vibrate when the device is set on it's vibrate only mode.
16391659 /**
0 commit comments