Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event gets associated with wrong user #131

Open
xa17d opened this issue May 7, 2021 · 2 comments
Open

Event gets associated with wrong user #131

xa17d opened this issue May 7, 2021 · 2 comments

Comments

@xa17d
Copy link

xa17d commented May 7, 2021

Events recorded after changeDeviceIdWithoutMerge are still associated with the previous user.

Code to reproduce:

import android.app.Activity
import android.os.Bundle
import ly.count.android.sdk.Countly
import ly.count.android.sdk.CountlyConfig
import ly.count.android.sdk.DeviceId

class DemoActivity : Activity() {

    private lateinit var countly: Countly

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val config = CountlyConfig(
            application,
            CountlyIntegration.COUNTLY_APP_KEY,
            CountlyIntegration.COUNTLY_SERVER_URL
        ).apply {
            setHttpPostForced(true)
            setDeviceId("dg-20210507-test1")
            setLoggingEnabled(true)
            setParameterTamperingProtectionSalt(CountlyIntegration.COUNTLY_SALT)
        }

        countly = Countly.sharedInstance().init(config)

        countly.events().recordEvent("Test", mapOf("event" to "1"))

        countly.changeDeviceIdWithoutMerge(DeviceId.Type.DEVELOPER_SUPPLIED, "dg-20210507-test2")
        countly.events().recordEvent("Test2", mapOf("event" to "2"))

        countly.changeDeviceIdWithoutMerge(DeviceId.Type.DEVELOPER_SUPPLIED, "dg-20210507-test1")
        countly.events().recordEvent("Test", mapOf("event" to "3"))

        countly.doStoredRequests() // send data to server
    }

    override fun onStart() {
        super.onStart()
        countly.onStart(this)
    }

    override fun onStop() {
        super.onStop()
        countly.onStop()
    }
}

The real application is much more complex and initialization is happening in Application.onCreate, but the issue is also reproducible with the code provided above.

Expected Behavior

User with deviceId == "dg-20210507-test1" should have the events:

{"key":"Test", "segmentation":{"event":"1"}}
{"key":"Test", "segmentation":{"event":"3"}}

User with deviceId == "dg-20210507-test2" should have the events:

{"key":"Test2", "segmentation":{"event":"2"}}

Current Behavior

User with deviceId == "dg-20210507-test1" receives all events:

{"key":"Test", "segmentation":{"event":"1"}}
{"key":"Test2", "segmentation":{"event":"2"}}
{"key":"Test", "segmentation":{"event":"3"}}

User with deviceId == "dg-20210507-test2" doesn't receive any events:

Screenshots (if appropriate):

Screenshot of the current behavior from the user profile of user with deviceId == "dg-20210507-test1":
Screenshot 2021-05-07 at 19 08 23

Possible Solution

No proposal. I saw that code that should make sure that events are not associated with the wrong deviceId is in place, but it doesn't seem to work in the provided scenario. Could be a race condition when events are tracked too fast after each other.

Steps to Reproduce (for bugs)

  1. Copy code provided at top into an Android project.
  2. Insert proper values for CountlyIntegration.COUNTLY_APP_KEY, CountlyIntegration.COUNTLY_SERVER_URL, CountlyIntegration.COUNTLY_SALT.
  3. Run the app.
  4. Observe events in User Profiles on Countly Server.

More Description

Our app allows to switch users. We noticed that some events are associated with the wrong user. Especially those that are happening close to the changeDeviceIdWithoutMerge call. We tried to eliminate our own code as root cause and then tried to reproduce the issue with a minimal example. The result is the code provided in this issue.

Your Environment

  • Countly Android SDK version: 20.11.8
  • Your Android version: Android 11
  • Your device: Pixel 3a
  • Any changes you have made to this SDK: none. It's the version provided by your maven repository.
@schusterlich
Copy link

I have the same issue and its posing a real challenge for us, because it breaks the consistency that we need. Hopefully this is fixed soon, for us it could also be a dealbreaker mid-term.

@ArtursKadikis
Copy link
Member

Hello. I'm looking into this and we'll try to ship a fix for this in the next release shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants