Add analytics to a Places UI Kit component
You can subscribe to analytics events about users tapping Directions, Call or Website, opening Google Maps, tapping the star rating or an author attribution, opening the photo lightbox, or switching tabs. Each event says which component and content type fired, as well as the place ID and location.
Analytics events that are provided
The following table provides examples of analytics events that are provided by the Places UI Kit.
| UI Interaction | tags: Set<String> |
Associated content/Content type |
|---|---|---|
| Directions button | {"click", "directions", "outbound"} |
"main_action_button" or "corner_action_button" |
| Open in Maps button | {"click", "maps", "outbound"} |
"main_action_button" or "corner_action_button" |
| Call button / Phone number (Overview tab) | {"click", "call_place", "outbound"} |
"phone_number", "main_action_button", or "corner_action_button" |
| Website button / Website (Overview tab) | {"click", "place_website", "outbound"} |
"website", "main_action_button", or "corner_action_button" |
| Attribution link | {"click", "attribution", "outbound"} |
"review" or "media" |
| Rating link | {"click", "reviews", "outbound"} |
"rating" or "review_summaries" |
Legal disclosure link (ⓘ dialog links) |
{"click", "disclosure", "outbound"} |
null (not configurable) |
| Report link | {"click", "report", "outbound"} |
"media", "review", or "generative_summary" |
| Review link | {"click", "review", "outbound"} |
"review" |
| Media / Photo link | {"click", "media", "outbound"} |
"media" |
| Photo Lightbox opened (in-app) | {"click", "media"} |
"media" |
| Overview tab selected (in-app) | {"click", "overview_tab"} |
null |
| Reviews tab selected (in-app) | {"click", "reviews_tab"} |
"review" |
| About tab selected (in-app) | {"click", "about_tab"} |
"features" |
Reviews overflow menu (⋮) opened (in-app) |
{"click", "reviews_menu"} |
"review" |
Lightbox overflow menu (⋮) opened (in-app) |
{"click", "lightbox_menu"} |
"media" |
Generative summary menu (⋮) opened (in-app) |
{"click", "generative_summary_menu"} |
"generative_summary" |
Generative review summary menu (⋮) opened (in-app) |
{"click", "review_summary_menu"} |
"review" |
Because new events and tags may be added over time, you can attach a generic handler during development to log every event that is broadcast as you interact with a component:
// Wrap your Places UI Kit composable or parent layout to inspect all broadcast events. // AnalyticsEvent.toString() includes componentType, tags, place IDs, and contentType. ProvidePlacesAnalyticsHandler( handler = { event -> Log.d("PlacesAnalytics", "$event") } ) { // Places UI Kit composables... }
Subscribe to and handle analytics events
You can subscribe to analytics events from a UI Kit Compose component by wrapping a parent layout container or the component itself in ProvidePlacesAnalyticsHandler.
The following code shows how to subscribe to and handle analytics events within a container hierarchy:
import android.util.Log import androidx.compose.foundation.layout.Column import androidx.compose.runtime.Composable import com.google.android.libraries.places.compose.AnalyticsEvent import com.google.android.libraries.places.compose.AdvancedPlaceDetailsCompact import com.google.android.libraries.places.compose.PlaceReference import com.google.android.libraries.places.compose.ProvidePlacesAnalyticsHandler import com.google.firebase.* @Composable fun PlaceCardScreen() { val placeRef = PlaceReference.PlaceId("ChIJN1t_tDeuEmsRUsoyG83frY4") // Analytics callback wraps the container hierarchy ProvidePlacesAnalyticsHandler( handler = { event -> val placeId = event.places.firstOrNull()?.id ?: "none" // Option A: Check for specific interactions using built-in Tags constants if (AnalyticsEvent.Tags.DIRECTIONS in event.tags) { Log.d("PlacesAnalytics", "User requested directions for place: $placeId") } if (AnalyticsEvent.Tags.OUTBOUND in event.tags) { Log.d( "PlacesAnalytics", "User is leaving the app via: ${event.tags.sorted().joinToString(", ")}" ) } // Option B: Forward every event directly to your analytics SDK (e.g., Firebase) val firebaseAnalytics = remember { Firebase.analytics } firebaseAnalytics.logEvent("place_ui_kit_interaction") { param("component_type", event.componentType) param("content_type", event.contentType ?: "none") param("tags", event.tags.sorted().joinToString(",")) param("place_id", placeId) } } ) { Column { AdvancedPlaceDetailsCompact( reference = placeRef, // Direct card tap (for UI navigation, e.g., centering a map) onClick = { place -> Log.d("Places", "Card tapped for place ID: ${place.id ?: "unknown"}") } ) } } }
If your app displays multiple cards of the same widget type (for instance, two AdvancedPlaceDetailsCompact composables), wrapping each composable in its own ProvidePlacesAnalyticsHandler lets you know which specific card instance triggered the event.
The following code snippet shows how to subscribe to and handle analytics events for a single AdvancedPlaceDetailsCompact composable:
import android.util.Log import androidx.compose.runtime.Composable import com.google.android.libraries.places.compose.AdvancedPlaceDetailsCompact import com.google.android.libraries.places.compose.AnalyticsEvent import com.google.android.libraries.places.compose.Orientation import com.google.android.libraries.places.compose.PlaceReference import com.google.android.libraries.places.compose.ProvidePlacesAnalyticsHandler @Composable fun SinglePlaceCardView() { val placeRef = PlaceReference.PlaceId("ChIJN1t_tDeuEmsRUsoyG83frY4") // Analytics callback scoped to this specific composable instance ProvidePlacesAnalyticsHandler( handler = { event -> val placeIds = event.places.mapNotNull { it.id }.joinToString(", ") val tags = event.tags.sorted().joinToString(", ") Log.d( "PlacesAnalytics", "[$tags] in ${event.componentType}, content: ${event.contentType ?: "null"}, places: [$placeIds]" ) if (AnalyticsEvent.Tags.DIRECTIONS in event.tags) { Log.d("PlacesAnalytics", "Directions tapped on this card") } } ) { AdvancedPlaceDetailsCompact( reference = placeRef, orientation = Orientation.HORIZONTAL, // Direct card-tap callback onClick = { place -> Log.d("Places", "Tapped card for place: ${place.id ?: "unknown"}") } ) } }
Add and handle card tap callbacks
Card tap callbacks must be configured and handled separately for each UI Kit component.
Use the onClick parameter on a UI Kit composable to handle taps on the card body. When the user taps the card, onClick passes a Place object populated with three properties:
place.id(String?): The unique Place ID to, for example, open a full Place Details view or select a marker.place.location(LatLng?): The latitude/longitude coordinates of the place to, for example, center a map camera or place a marker.place.viewport(LatLngBounds?): The recommended map viewport bounds (northeastandsouthwestcoordinates) for framing the place on a map.
The following code shows how to add and handle a card tap callback for an AdvancedPlaceDetailsCompact composable:
import android.util.Log import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import com.google.android.libraries.places.api.model.Place import com.google.android.libraries.places.compose.AdvancedPlaceDetailsCompact import com.google.android.libraries.places.compose.Orientation import com.google.android.libraries.places.compose.PlaceReference @Composable fun PlaceCardTapSampleView() { val peetsCoffeePlaceId = "ChIJT7FdmYiAhYAROFOvrIxRJDU" var selectedPlace by remember { mutableStateOf<Place?>(null) } AdvancedPlaceDetailsCompact( reference = PlaceReference.PlaceId(peetsCoffeePlaceId), orientation = Orientation.HORIZONTAL, onClick = { place -> // Handle the card tap using place.id, place.location, or place.viewport selectedPlace = place Log.d("Places", "Tapped place ID: ${place.id ?: "unknown"}") place.location?.let { location -> Log.d("Places", "Coordinates: ${location.latitude}, ${location.longitude}") } place.viewport?.let { viewport -> Log.d("Places", "Viewport NE: ${viewport.northeast}, SW: ${viewport.southwest}") } } ) }