Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`trackClick` implementation for Composable `onClick` functions that take parameters

Open
#1,409 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
kotlin
Domain
mobile

Research direction

Start by locating the existing Compose SDK implementation of trackClick and TapActionTracker, then compare their callback types with ClickableText's (Int) -> Unit signature. Confirm how the current composable wrapper tracks clicks and forwards callbacks. Done means parameterized onClick functions can be wrapped while preserving their argument and existing click tracking behavior.

Written by the indexing model from the issue text.

Description

enhancement

Is your feature request related to a problem? Please describe.
In the Compose SDK, com.datadog.android.compose.trackClick cannot be used for Composables that take an onClick with parameters, such as ClickableText which has a function signature:

@Composable
fun ClickableText(
    ...
    onClick: (Int) -> Unit
)

If we try to use it, there's a type mismatch:

@Composable
fun ClickableTextWithTrackedClicks(
    onClick: (Int) -> Unit
) {
    ClickableText(
        ...
        onClick = trackClick(targetName = "Test") { TODO() } // Type mismatch here, as (Int) -> Unit is expected
    )
}

Because trackClick is also a @Composable, it doesn't seem like there's a way to wrap it in a lambda.
eg. If we wished to print the Int parameter

    ClickableText(
        ... 
        onClick = { i: Int ->
            println(i)
            trackClick(targetName = "Test") {}.invoke() // Can't be invoked because we're not in a `Composable` context
        }
    )

Describe the solution you'd like
An implementation of trackClick that accepts a generically typed onClick lambda parameter such as:

@Composable
fun <T> trackClick(
    targetName: String,
    onClick: (T) -> Unit
): (T) -> Unit {
    val onTapState = rememberUpdatedState(newValue = onClick)
    return remember(targetName, attributes) {
        TapActionTracker(targetName, attributes, onTapState)
    }
}

// This will require a separate mplementation of TapActionTracker as well
internal class TapActionTracker<T>(
    private val targetName: String,
    private val attributes: Map<String, Any?> = emptyMap(),
    private val onTap: State<(T) -> Unit>,
    private val rumMonitor: RumMonitor = GlobalRum.get()
) : (T) -> Unit {

    override fun invoke(param: T) {
        // RUM code
        onTap.value.invoke(arg)
    }
}
Dominant language
Kotlin
Stars
226
Forks
86
Avg merge
1d 12h
Merged PRs (30d)
65

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DataDog/dd-sdk-android

All issues in DataDog/dd-sdk-android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.