snowplow / snowplow-android-tracker

Snowplow event tracker for Android. Add analytics to your Android apps and games
http://snowplowanalytics.com
Apache License 2.0
110 stars 63 forks source link

Track new properties in platform context version 1-0-3 and make it configurable which properties to track (close #598) #599

Closed matus-tomlein closed 1 year ago

matus-tomlein commented 1 year ago

Issue #598

Adds the new properties in platform context entity (mobile_context schema) version 1-0-3:

Property Description
isPortrait A Boolean indicating whether the device orientation is portrait (either upright or upside down)
resolution Screen resolution in pixels. Arrives in the form of WIDTHxHEIGHT (e.g., 1200x900). Doesn't change when device orientation changes
scale Scale factor used to convert logical coordinates to device coordinates of the screen (uses UIScreen.scale on iOS and DisplayMetrics.density on Android)
language System language currently used on the device (ISO 639)
appSetId Android vendor ID scoped to the set of apps published under the same Google Play developer account (see https://developer.android.com/training/articles/app-set-id)
appSetIdScope Scope of the appSetId. Can be scoped to the app or to a developer account on an app store (all apps from the same developer on the same device will have the same ID)

Also makes it configurable which properties should be tracked in the entity in case the user does not want to track all of them.

Related issues

Limitations

The app set ID has to be retrieved on a background thread so it is asynchronous from the tracker initialization. This means that in between the time that the tracker is initialized (createTracker is called) and the identifier is retrieved, there may be several events tracked without it being retrieved yet.

Unfortunately, I couldn't find a way around this. But to make the impact smaller, I set the ID to be stored in Android general preferences (persistent storage) once it is retrieved the first time. So on the second and following starts of the app, it can be read synchronously from the general prefs and can be added to all events.