TelemetryDeck / SwiftSDK

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

Added local and disk caching and test targets. #33

Closed ddaddy closed 3 years ago

ddaddy commented 3 years ago

Ok, so there's a lot going on here.

I've added your local caching but fixed a few bugs. I also made it generic and not specific to SignalPostBody as was suggested on Twitter. The cache will load any previously unsent signals from disk on initialisation. I've refactored the SignalPayload into it's own struct. There's a new SignalManager that handles the cache, timer etc.. SignalManager will send a new batch of signals every 10 seconds and also once at startup (If any previous signals exist) Signals are sent in batches of 25. Attempting with 50 sometimes resulted in a Payload Too Large error. There's no mitigation if sending 25 gives this error, so maybe increase the payload size server side just to make sure. If signals fail to send, they will be added back to the queue, so if a Payload Too Large error does occur, they will always be stuck in the cache.

The cache is saved to disk at different points depending on device/os:

There is a new showDebugLogs option on the TelemetryManagerConfiguration that will show very detailed logs of everything in action.

There are 4 new targets added to the project that I have thoroughly tested:

You will notice that in the Xcode project there is a separate framework target for watchOS. This is necessary because building for watchOS builds both the iOS and watchOS targets and results in errors trying to add the iOS framework into a watchOS target. This is purely for the sample targets and shouldn't affect how the SPM package is delivered and built. (Someone else may be able to fix it to use the 1 framework 🤷‍♂️)

I have not updated the README

winsmith commented 3 years ago

Hi Darren.

this looks really good! I'm reading through the code and nodding my head.

One question though: You're copying the ClientTester application into the repository, and I assume that is to directly test the client without having to do the package dance, but I can't get it to work? I was expecting an xcproj file or something, but there's just a Package.swift and it doesn't seem to define a target.

Is this an oversight on your part, or am I just not getting how to use it?

ddaddy commented 3 years ago

There should definitely be an xcode proj file. Maybe it didn't check in. Just out watching the football (Come on England 😬). I'll check it later or in the morning.

ddaddy commented 3 years ago

🥳 The .gitignore that the project had, ignored the Xcode project file. It should be added now.

winsmith commented 3 years ago

Okay, so it looks really good! I just updated the server to accept up to 1MB post requests on that endpoint, so I think we can accept larger numbers of signals at once. I'm going to play around with it a little more :)

ddaddy commented 3 years ago

Great. 100 should be easily achievable and within 10 seconds should be fine. It'll only really hit the limit when the app is used without an internet connection and all signals cached.

winsmith commented 3 years ago

This all works really well in my tests! Thank you very much! I'm going to merge it and layer some docs on top!