TelemetryDeck / SwiftSDK

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

Add terminate method #46

Closed StarLard closed 2 years ago

StarLard commented 2 years ago

This PR adds a terminate method so that users can manually terminate the SDK early if desired.

This is useful for apps which allow their users to enable and disable data collection.

StarLard commented 2 years ago

Idea behind this PR is that my app has a toggle in settings that allows users to turn off analytics. I'm currently handling that by wrapping telemetry in a custom controller and just not forwarding events to the SDK if analytics are turned off, but I know the SDK does some work in the background whether or not I send events. It would be nice to allow adopters to completely shut down the SDK on demand.

winsmith commented 2 years ago

This is a very good idea! Can you check wether calling TelemetryManager.send(...) without an initialized instance causes the app to crash? That would be something to avoid.

StarLard commented 2 years ago

It will crash because there is a fatal error when shared is accessed, but I believe that is expected behavior. If you have called terminate() you should call initialize again before trying to interact with the SDK.

winsmith commented 2 years ago

Fair enough! Thanks for your contribution :)