microsoft / clarity-apps

Repo for distributing Clarity Apps packages
MIT License
46 stars 2 forks source link

Android does not support enabling/disabling tracking after initialisation #28

Closed antonis closed 9 months ago

antonis commented 10 months ago

Problem

According to the documentation the Clarity SDK should be initialised at app startup (startup activity, application class or just after a custom WorkManager initializer) in order to function properly. This poses a limitation since in some countries tracking needs to be communicated and approved by the user.

Proposal

Add the ability to enable Clarity tracking after the SDK initialisation and disable it if the user decides to opt out of tracking.

antonis commented 9 months ago

Hey @ibradwan 👋 Sorry for the direct ping on this. I was wondering if the proposed enhancement is something that is considered for the SDK roadmap. We are working on integrating Clarity SDK in the Jetpack (WordPress) Android app and this is a blocker for us at this point 🙇

maryamshal commented 9 months ago

Hello @antonis, it seems from your PR that you check for user optin before initializing clarity. And that should work across app restarts. If you are referring to the option to opt out mid sessions (when the app goes to the background), that is not yet supported, however, the next time the app starts the preference should take effect.
Also note, you can call initialize anywhere in the app (given work manager is initialized) and clarity will start working from that point onward. So, on the first cold app start you can prompt the user to opt in then start clarity.

antonis commented 9 months ago

Thank you for the prompt reply @maryamshal! I really appreciate this 🙇

you check for user optin before initializing clarity. And that should work across app restarts.

This is the case. This works already for us.

Also note, you can call initialize anywhere in the app (given work manager is initialized) and clarity will start working from that point onward. So, on the first cold app start you can prompt the user to opt in then start clarity.

Thank you for the clarification. This should cover our need for the most part 👍 I misinterpreted the below note from the documentation thinking that everything should happen on startup 😅

ℹī¸ Note

  • This can be called in your startup activity only. If you have multiple startup activities, you can call it inside a custom application class or duplicate the call in all startup activities.
  • If you use a custom WorkManager initializer, call this function after the initialization. Otherwise, Clarity won't function properly.

Is there an option to stop tracking after initialisation? For example if a user gets to the app privacy settings and disables tracking. Or we should force an app restart for that use case?

maryamshal commented 9 months ago

Hi @antonis

Thank you for the clarification. This should cover our need for the most part 👍 I misinterpreted the below note from the documentation thinking that everything should happen on startup 😅

You will still need to call initialize upon startup if you want to track the entire user journey in normal cases when user has opted in. But upon first cold start you can initialize after user opt in prompt.

Is there an option to stop tracking after initialisation? For example if a user gets to the app privacy settings and disables tracking. Or we should force an app restart for that use case?

We currently don't support that. You'll need to force app restart to check before initializing clarity.

antonis commented 9 months ago

Thank you for the clarifications @maryamshal! This was really helpful 🙇