Bug 1863603 - Add handling of Meta attribution in percent format

fenix/121.0
Roger Yang 8 months ago committed by mergify[bot]
parent 41120b4c4f
commit a34c5d7542

@ -16,6 +16,8 @@ import org.mozilla.fenix.GleanMetrics.MetaAttribution
import org.mozilla.fenix.GleanMetrics.PlayStoreAttribution
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.utils.Settings
import java.io.UnsupportedEncodingException
import java.net.URLDecoder
/**
* A metrics service used to derive the UTM parameters with the Google Play Install Referrer library.
@ -249,12 +251,20 @@ data class MetaParams(
if (contentString == null) {
return null
}
val decodedContentString = try {
// content string can be in percent format
URLDecoder.decode(contentString, "UTF-8")
} catch (e: UnsupportedEncodingException) {
logger.error("failed to decode content string", e)
// can't recover from this
return null
}
val data: String
val nonce: String
val contentJson = try {
JSONObject(contentString)
JSONObject(decodedContentString)
} catch (e: JSONException) {
logger.error("content is not JSON", e)
// can't recover from this

@ -127,6 +127,21 @@ internal class InstallReferrerMetricsServiceTest {
assertEquals(metaParams, expectedMetaParams)
}
@Test
fun `WHEN receiving a Meta encrypted attribution in percent format THEN will decrypt correctly`() {
val metaParams = MetaParams.extractMetaAttribution("%7B%22app%22%3A12345%2C%22t%22%3A1234567890%2C%22source%22%3A%7B%22data%22%3A%22DATA%22%2C%22nonce%22%3A%22NONCE%22%7D%7D")
val expectedMetaParams = MetaParams("12345", "1234567890", "DATA", "NONCE")
assertEquals(metaParams, expectedMetaParams)
}
@Test
fun `WHEN receiving a Meta encrypted attribution in bad format THEN it should not crash`() {
val metaParams = MetaParams.extractMetaAttribution("%7B%22app%22%3A12345%2C%22t%22%3A1234567890%2C%22source%22%3A%7B%22data%22%3A%22DATA%22%2C%22nonce%22%3A%22NONCE%22%7B%7D")
assertNull(metaParams)
}
@Test
fun `WHEN parsing referrer response with meta attribution THEN both UTM and Meta params should match expected`() {
val utmParams = UTMParams.parseUTMParameters("""utm_content={"app":12345, "t":1234567890,"source":{"data":"DATA","nonce":"NONCE"}}""")

Loading…
Cancel
Save