Packages | Maven Central | Android API |
---|---|---|
posthog-android | 21 |
Please see the main PostHog docs.
Specifically, the Android integration details.
PostHog Android SDK
Home Page: https://posthog.com/docs/libraries/android
License: MIT License
Packages | Maven Central | Android API |
---|---|---|
posthog-android | 21 |
Please see the main PostHog docs.
Specifically, the Android integration details.
See https://github.com/PostHog/posthog-ios-recorder/pull/8#discussion_r1361624547 for context
Hello!
What's the expected behaviour when calling posthog.identify
whilst the posthog
client is opt'd out?
I can see that the propertiesCache
contains the properties set whilst the client was opt'd out but they're never sent.
posthog.optOut(true)
posthog.identify(properties)
posthog.optOut(false)
posthog.identify(id)
iOS code has to be fixed as well: https://github.com/PostHog/posthog-ios/blob/aab0004088fc17b8da88a0e43b37181773408ce2/PostHog/Internal/PHGPostHogIntegration.m#L653-L657
As long as it's not false
, it's considered active.
When building a project I see these warning in the logs:
"The following legacy support libraries are detected:\n:app:debugRuntimeClasspath -> com.posthog.android:posthog:1.1.2 -> com.android.support:support-annotations:28.0.0"
This behavior will not be allowed in Android Gradle plugin 8.0."
Would be nice to update dependencies client library is using.
Right now, an option controls this, which defaults to false, leading to confusion for clients, as all other client libraries have this on by default
Relates to PostHog/posthog-js#524
const isKnownAnonymous = this.persistence.get_user_state() === 'anonymous'
is the check where we know if calling identify
again is allowed or not.
If the user is already identified, calling identify
again isn't allowed, if that's intentional, you should call alias
instead.
If you want to identify another user again, you have to call reset
first.
https://posthog.com/docs/product-analytics/identify#3-reset-after-logout
There are more restrictions described here.
By not doing this, we might be merging users wrongly and we'll likely get a support request to split persons.
This has to be done on the other SDKs as well such as:
I'd like to see sessions come to the PostHog Android SDK, would be very useful for some more analytics.
https://posthog.com/questions/how-to-filter-out-usage-from-i-os-android-simulators-emulators
[ ] iOS
[ ] Android
[ ] RN
[ ] Flutter will get it for free once Android and RN is updated.
After the migration, events from older versions of the SDKs won't work when using Session properties such as Session durations (Part of the new Mobile dashboard template).
Web analytics need to migrate from v4 to v7 to speed up a few things:
@robbie-c It pretty much is a must, as it allows sampling by session ID, and even without sampling it's about 2x faster. I can't really release web analytics without this change
So we need to fit this within this sprint or latest the beginning of the next sprint before Web Analytics does the migration and breaks the current version of the SDKs
implementation("com.posthog:posthog-android:3.+") is causing the build error this :.gradle/caches/transforms-3/2e83842a3dca5618ece679a149e8fbde/transformed/jetified-okio-jvm-3.6.0.jar!/META-INF/okio.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
User reported we're causing some crashes with a NullPointerException
here:
Context ueman/flutter_referrer_info#2
Android already listens to ActivityLifecycleCallbacks
so it'd be easier to add the referrerURL reading the intent Intent.EXTRA_REFERRER, Intent.EXTRA_REFERRER_NAME and or com.android.browser.application_id
.
Prop $referrer, and $referring_domain
In PostHog.java:479
if (shouldSendFeatureFlags) {
ValueMap flags = featureFlags.getFlagVariants();
List<String> activeFlags = featureFlags.getFlags();
An exception happens if PostHogFeatureFlags.reloadFeatureFlagsRequest() did not finish when featureFlags.getFlags() was called.
Although this does not make my app crash, it makes lose my very early events before reloadFeatureFlagsRequest() finishes.
3.1.1
This is firebase carshlytics report from a production app. It occasionally fails on startup due to the posthog crash. For a certain user it crashed 4 times in a row on this error
Android 10
Model:A5 2020
Brand:Oppo
Not crash
Fatal Exception: java.lang.InstantiationError: F8.c
at com.posthog.PostHog.setup(PostHog.java:66)
at com.posthog.PostHog$Companion.setup(PostHog.java:648)
at com.posthog.android.PostHogAndroid$Companion.setup(PostHogAndroid.java:42)
at com.evelize.teleprompter.TeleprompterApplication.initPostHog(TeleprompterApplication.kt:128)
at com.evelize.teleprompter.TeleprompterApplication.onCreate(TeleprompterApplication.kt:57)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1199)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6913)
at android.app.ActivityThread.access$1600(ActivityThread.java:240)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2067)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:7888)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:512)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:998)
Stack trace points here, that leaves me fairly confused
screen
via PosthogObserver or manually)screen
via wix, react-navigation or manually)Relates to PostHog/posthog-js-lite#110
You can use Surveys thru the APIs directly, see this comment.
Version used: 2.0.3
When enabling the screen view recording, we encountered the following crash:
FATAL EXCEPTION: main
Process: at.beeone.george.dev, PID: 2802
java.lang.IllegalArgumentException: name must be provided.
at com.posthog.android.PostHog.screen(PostHog.java:523)
at com.posthog.android.PostHog.screen(PostHog.java:501)
at com.posthog.android.PostHog.recordScreenViews(PostHog.java:316)
at com.posthog.android.PostHogActivityLifecycleCallbacks.onActivityStarted(PostHogActivityLifecycleCallbacks.java:106)
at android.app.Application.dispatchActivityStarted(Application.java:421)
at android.app.Activity.dispatchActivityStarted(Activity.java:1407)
at android.app.Activity.onStart(Activity.java:1948)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:345)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:251)
...
We have some activities that deliberately set android:label=""
to avoid being read by screen reader that are probably causing this. The sdk should not crash. Either not tracking the event or tracking the activity class name instead would be better.
Exception java.lang.IllegalStateException: This ViewTreeObserver is not alive, call getViewTreeObserver() again
at android.view.ViewTreeObserver.checkIsAlive (ViewTreeObserver.java:984)
at android.view.ViewTreeObserver.removeOnDrawListener (ViewTreeObserver.java:759)
at com.posthog.android.replay.PostHogReplayIntegration.cleanSessionState$lambda$6$lambda$5 (PostHogReplayIntegration.kt:253)
at com.posthog.android.replay.PostHogReplayIntegration.$r8$lambda$Fo0KroR9KoezO0ojDFIMQW4ICps
at com.posthog.android.replay.PostHogReplayIntegration$$ExternalSyntheticLambda2.run
at android.os.Handler.handleCallback (Handler.java:938)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loopOnce (Looper.java:226)
at android.os.Looper.loop (Looper.java:313)
at android.app.ActivityThread.main (ActivityThread.java:8663)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)
This error happens when start the service of posthog
Tried to access visual service WindowManager from a non-visual Context:id.app.App@9b44ad0 WindowManager should be accessed from Activity or other visual Context.
Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen.
java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context:id.app.App@9b44ad0
at android.app.ContextImpl.getSystemService(ContextImpl.java:2070)
at android.content.ContextWrapper.getSystemService(ContextWrapper.java:869)
at com.posthog.android.internal.Utils.getSystemService(Utils.java:153)
at com.posthog.android.PostHogContext.putScreen(PostHogContext.java:251)
at com.posthog.android.PostHogContext.create(PostHogContext.java:132)
at com.posthog.android.PostHog$Builder.build(PostHog.java:1015)
at id.app.data.services.trackers.PostHogTrackerService.startService(PostHogTrackerService.kt:19)
at id.app.App.startTrackerService(App.kt:63)
at id.app.App.onCreate(App.kt:56)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1225)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7069)
at android.app.ActivityThread.access$1800(ActivityThread.java:258)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2207)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:233)
at android.os.Looper.loop(Looper.java:344)
at android.app.ActivityThread.main(ActivityThread.java:8204)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:589)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1071).
This error happens same when use the context from Activity
posthog-android/posthog/src/main/java/com/posthog/PostHog.kt
Lines 455 to 457 in 1eee12c
js-lite
SDK sets it to false
:
Which one is the right option?
$is_identified
is the property to filter identified users or not (anonymous).
https://github.com/PostHog/posthog-js/blob/7022ab69505959fb065d41870d2bceeb69145916/src/posthog-core.ts#L912
JS SDK uses the $user_state
super property to track if the user has identified already or not with the values identified
or anonymous
(this super property is in deny list so not set in the event)
Add to:
Integrating Posthog in Kotlin multiplatform projects currently requires integrating the android and ios libraries separatly. With a multiplatform library the code for android and ios must not be duplicated and user must not themself create expect/actual declarations for PostHog. The kotlin library can also be used nativly in android only projects.
Worth noting that the Android SDK v2 also didn't cache the feature flags: just in memory.
Hey ๐ are you new around here? Feel free to contribute to this issue! It is quite straightforward since there's a clear spec - no need to think about what's the best solution.
However, it isn't a teeny tiny task, which is why we're offering a $100 gift card for PostHog merch for a merged PR that implements this. You'll also be listed as a contributor on our main repo's README (4.3k stars) and get a digital contributor card.
PostHog provides support for feature flags. These allow turning functionality on and off based on a response from the PostHog API.
For a client-side library like this one, we'd need an implementation similar to that of posthog-js
.
Here's an overview of what implementing this entails:
A mechanism to send a POST
request to /decide/
with the following data:
// Content-Type: application/json
{
token: <posthog_project_api_key>,
distinct_id: <user_distinct_id>
}
The response will contain an array/list at response['featureFlags']
with the flags that are enabled for this user. The distinct ID should be already available from existing methods implemented in this lib.
The response should be cached and refreshed periodically.
A method isFeatureEnabled
This method takes a feature flag key as an input and returns a boolean indicating if the given flag is on or off for the user based on the response from above.
A method reloadFeatureFlags
This forces a refresh of the cache by calling /decide/
again.
A method onFeatureFlagsLoaded
Every time the flags are reloaded, this should be called as a callback.
Feel free to ask me anything about this! I'm also reachable on the PostHog Slack.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.