Skip to content

Commit 7bd12c5

Browse files
committed
feat: add GA4 API key to build.gradle file
1 parent 6fe8bd4 commit 7bd12c5

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

0 commit comments

Comments
 (0)