Skip to content

Commit

Permalink
Make sure to pass no consent to GA
Browse files Browse the repository at this point in the history
  • Loading branch information
kasnder committed Jul 17, 2022
1 parent d38d53e commit fcba98e
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions library/src/main/java/net/kollnig/consent/ConsentManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,20 @@ public void saveConsent(boolean consent) {
SharedPreferences prefs = getPreferences();
prefs.edit().putBoolean("has_consent", consent).apply();

if (consent) {
Class firebaseAnalyticsClass = findFirebaseAnalytics();

if (firebaseAnalyticsClass != null) {
try {
// Call FirebaseAnalytics.getInstance(context)
Object[] arglist = {context};
Method getInstance = firebaseAnalyticsClass.getMethod("getInstance", Context.class);
Object firebaseAnalytics = getInstance.invoke(null, arglist);

// Call FirebaseAnalytics.setAnalyticsCollectionEnabled(true)
arglist[0] = true;
Method setAnalyticsCollectionEnabled = firebaseAnalyticsClass.getMethod("setAnalyticsCollectionEnabled", boolean.class);
setAnalyticsCollectionEnabled.invoke(firebaseAnalytics, arglist);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Class firebaseAnalyticsClass = findFirebaseAnalytics();
if (firebaseAnalyticsClass != null) {
try {
// Call FirebaseAnalytics.getInstance(context)
Object[] arglist = {context};
Method getInstance = firebaseAnalyticsClass.getMethod("getInstance", Context.class);
Object firebaseAnalytics = getInstance.invoke(null, arglist);

// Call FirebaseAnalytics.setAnalyticsCollectionEnabled(true)
arglist[0] = consent;
Method setAnalyticsCollectionEnabled = firebaseAnalyticsClass.getMethod("setAnalyticsCollectionEnabled", boolean.class);
setAnalyticsCollectionEnabled.invoke(firebaseAnalytics, arglist);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
}
Expand Down

0 comments on commit fcba98e

Please sign in to comment.