Skip to content

Commit 46abef5

Browse files
criticalAYdavid-allison
authored andcommitted
feat: add GA4 API key to build.gradle file
1 parent 7b7334e commit 46abef5

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

AnkiDroid/build.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ android {
110110
testApplicationId = "com.ichi2.anki.tests"
111111
vectorDrawables.useSupportLibrary = true
112112
testInstrumentationRunner = 'com.ichi2.testutils.NewCollectionPathTestRunner'
113+
114+
// GA4 Measurement Protocol api_secret. Sourced from `local.properties`
115+
// (ANALYTICS_API_KEY) or the ANALYTICS_API_KEY env var; falls back to
116+
// a dummy value so contributor builds still compile.
117+
//
118+
// The dummy key is rejected by GA's ingest, so analytics requests from
119+
// unsigned/local builds go nowhere this means `setDevMode()` (100%
120+
// sampling) has no observable effect on a build without the real key.
121+
Properties properties = new Properties()
122+
def localPropsFile = project.rootProject.file("local.properties")
123+
if (localPropsFile.exists()) {
124+
properties.load(localPropsFile.newDataInputStream())
125+
}
126+
127+
def apiKey = properties.getProperty("ANALYTICS_API_KEY") ?: System.getenv("ANALYTICS_API_KEY") ?: "DUMMY_API_XXX"
128+
buildConfigField "String", "ANALYTICS_API_KEY", "\"${apiKey}\""
113129
}
114130
signingConfigs {
115131
release {

0 commit comments

Comments
 (0)