Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): consent mode #82

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ repositories {
}

dependencies {
implementation 'com.google.firebase:firebase-analytics:21.0.0'
implementation 'com.google.firebase:firebase-analytics:21.5.1'
implementation 'com.google.firebase:firebase-installations:17.0.1'
}
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 5.2.0
version: 5.3.0
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: titanium-firebase-analytics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
import android.os.Bundle;

import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.analytics.FirebaseAnalytics.ConsentStatus;
import com.google.firebase.analytics.FirebaseAnalytics.ConsentType;
import com.google.firebase.installations.FirebaseInstallations;

import java.io.IOException;
import java.util.EnumMap;
import java.util.Map;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollFunction;
Expand All @@ -32,6 +35,9 @@ public class TitaniumFirebaseAnalyticsModule extends KrollModule
private static final boolean DBG = TiConfig.LOGD;
private static FirebaseAnalytics mFirebaseAnalytics;

public static final int GRANTED = 0;
public static final int DENIED = 1;

@SuppressLint("MissingPermission") // Android Studio only doesn't know it's included via tiapp.xml, so all good here!
private FirebaseAnalytics analyticsInstance()
{
Expand All @@ -53,6 +59,41 @@ public void resetAnalyticsData()
{
this.analyticsInstance().resetAnalyticsData();
}
@Kroll.method
public void setConsent(KrollDict opts)
{
int analyticsStorage = TiConvert.toInt(opts.get("analyticsStorage"), -1);
int adStorage = TiConvert.toInt(opts.get("adStorage"), -1);
int adUserData = TiConvert.toInt(opts.get("adUserData"), -1);
int adPerson = TiConvert.toInt(opts.get("adPersonalization"), -1);

Map<ConsentType, ConsentStatus> consentMap = new EnumMap<>(ConsentType.class);
if (analyticsStorage == GRANTED) {
consentMap.put(ConsentType.ANALYTICS_STORAGE, ConsentStatus.GRANTED);
} else if (analyticsStorage == DENIED) {
consentMap.put(ConsentType.ANALYTICS_STORAGE, ConsentStatus.DENIED);
}
if (adStorage == GRANTED) {
consentMap.put(ConsentType.AD_STORAGE, ConsentStatus.GRANTED);
} else if (adStorage == DENIED) {
consentMap.put(ConsentType.AD_STORAGE, ConsentStatus.DENIED);
}
if (adUserData == GRANTED) {
consentMap.put(ConsentType.AD_USER_DATA, ConsentStatus.GRANTED);
} else if (adUserData == DENIED) {
consentMap.put(ConsentType.AD_USER_DATA, ConsentStatus.DENIED);
}
if (adPerson == GRANTED) {
consentMap.put(ConsentType.AD_PERSONALIZATION, ConsentStatus.GRANTED);
} else if (adPerson == DENIED) {
consentMap.put(ConsentType.AD_PERSONALIZATION, ConsentStatus.DENIED);
}

if (mFirebaseAnalytics != null) {
mFirebaseAnalytics.setConsent(consentMap);
}

}

@Kroll.method
@Kroll.setProperty
Expand Down