TelemetryDeck / SwiftSDK

Swift SDK for TelemetryDeck, a privacy-conscious analytics service for apps and websites.
https://telemetrydeck.com/
Other
149 stars 30 forks source link

Use a self-generated UUID as default ID on macOS + add tvOS support #71

Closed Jeehut closed 1 year ago

Jeehut commented 1 year ago

Note that I skipped the app group based API (outlined here) as I figured very few would actually need it and those could simply override the default ID and store it in their shared app group defaults.

Also, I noticed lack of support for tvOS which supports identifierForVendor just like iOS according to Apples docs, so I added it. Plus some really minor docs improvements.

Lastly, because there was a lot of #else end even a nested #if I opted to indent them here inside the defaultUserIdentifier implementation. I did not search for other places and make them consistent everywhere, so if you dislike this inconsistency, feel free to re-indent. If you dislike indented #if in general, a compromise could be to only allow/require indentation where the #if is made within a function body or when there's nesting involved.

Fixes https://github.com/TelemetryDeck/SwiftClient/issues/12.

Jeehut commented 1 year ago

BTW: UserDefaults(suiteName: "\(appIdHash).TelemetryDeck") should ensure that two apps that both use TelemetryDeck don't accidentally use the same file (as the appIdHash will be different for each app). According to the docs, only sandboxed apps are sure to not reuse the same suiteName, but TelemetryDeck could also be included in non-sandboxed apps, so this additional distinction is needed.

And I opted against the appID directly to keep it secret from the users.

Jeehut commented 1 year ago

UPDATE: When I tested this branch in my app, I noticed that the defaults file created by the previous code resulted in this outlier in the Preferences folder which probably isn't a good idea and stands out too much: before

So in the latest commit I shortened the SHA256 hash to the last 12 characters (still 16^12 = ~281 trillion variations) and used Apples recommended reversed domain structure using com.telemetrydeck (using the apps domain would require dynamic code which is less reliable), resulting in this: after

I think this is better and it's also tested now. :)

winsmith commented 1 year ago

Really cool! Thanks a lot!