Skip to content

Commit

Permalink
Registering mobile_app_install event
Browse files Browse the repository at this point in the history
Summary: Previously, we only captured custom events triggered by AppEventsLogger.logEvent(...). However, this approach missed the "mobile_app_install" event, which are automatically logged during app initialization. In this diff we include those events to capture scenario without triggering any custom events.

Reviewed By: youerkang

Differential Revision:
D69886513

Privacy Context Container: L1326170

fbshipit-source-id: 1d4d2ca160c3b0b9d11f4a4ffc0f16bdf45748c1
  • Loading branch information
Shen Guo authored and facebook-github-bot committed Feb 21, 2025
1 parent a635cfb commit 462aad0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ internal constructor(activityName: String, applicationId: String?, accessToken:
// Will do nothing in case AutoLogAppEventsEnabled is true, as we already started the
// tracking as part of sdkInitialize() flow
startTracking(application, applicationId)

if (isEnabled(FeatureManager.Feature.GPSPACAProcessing)) {
PACustomAudienceClient.joinCustomAudience(applicationId, "fb_mobile_app_install")
}
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import android.annotation.TargetApi
import android.os.Bundle
import android.os.OutcomeReceiver
import android.util.Log
import androidx.core.net.toUri
import com.facebook.FacebookSdk
import com.facebook.appevents.AppEvent
import com.facebook.appevents.gps.GpsDebugLogger
import com.facebook.appevents.internal.Constants
import com.facebook.internal.instrument.crashshield.AutoHandleExceptions
import org.json.JSONException
import java.util.concurrent.Executors
import kotlin.toString
import androidx.core.net.toUri
import com.facebook.appevents.gps.GpsDebugLogger

@AutoHandleExceptions
object PACustomAudienceClient {
Expand Down Expand Up @@ -74,10 +74,33 @@ object PACustomAudienceClient {
}
}

@TargetApi(34)
fun joinCustomAudience(appId: String, event: AppEvent) {
fun joinCustomAudience(appId: String?, eventName: String?) {
if (!enabled) return

joinCustomAudienceImpl(appId, eventName)
}


fun joinCustomAudience(appId: String?, event: AppEvent?) {
if (!enabled) return

var eventName: String? = null
try {
eventName = event?.getJSONObject()?.getString(Constants.EVENT_NAME_EVENT_KEY)
} catch (e: JSONException) {
Log.w(TAG, "Failed to get event name from event.")
}

joinCustomAudienceImpl(appId, eventName)
}

@TargetApi(34)
private fun joinCustomAudienceImpl(appId: String?, eventName: String?) {
val caName = validateAndCreateCAName(appId, eventName)
if (caName == null) {
return
}

val callback: OutcomeReceiver<Any, Exception> =
object : OutcomeReceiver<Any, Exception> {
override fun onResult(result: Any) {
Expand All @@ -99,8 +122,6 @@ object PACustomAudienceClient {
}

try {
val caName = validateAndCreateCAName(appId, event) ?: return

// Each custom audience has to be attached with at least one ad to be valid, so we need to create a dummy ad and attach it to the ca.
val dummyAd = AdData.Builder()
.setRenderUri("$baseUri/ad".toUri())
Expand Down Expand Up @@ -136,8 +157,10 @@ object PACustomAudienceClient {
}
}

private fun validateAndCreateCAName(appId: String, event: AppEvent): String? {
val eventName = event.getJSONObject().getString(Constants.EVENT_NAME_EVENT_KEY)
private fun validateAndCreateCAName(appId: String?, eventName: String?): String? {
if (appId == null || eventName == null) {
return null
}
if (eventName == REPLACEMENT_STRING || eventName.contains(GPS_PREFIX)) {
return null
}
Expand Down

0 comments on commit 462aad0

Please sign in to comment.