google-analytics-plugin icon indicating copy to clipboard operation
google-analytics-plugin copied to clipboard

iOS: sendHitsInBackground ability?

Open jvjvjv opened this issue 8 years ago • 7 comments

Hey this is an enhancement request. Google's default dispatch interval is two minutes. But it looks like if a user closes the app before that two minutes, the data won't be dispatched.

jvjvjv avatar Jan 27 '17 15:01 jvjvjv

I also wanted to request manual dispatch capability, but I wasn't sure if I should make it a separate ticket. I apologise for immediately unloading this onto you instead of implementing it myself and then sending you a pull request.

jvjvjv avatar Jan 27 '17 15:01 jvjvjv

@jvjvjv About your first question - yes, that seems to be the case as written in the GA docs.

By default, data is dispatched from the Google Analytics SDK for iOS every 2 minutes.

If a user loses network access or quits your app while there are still hits waiting to be dispatched, those hits are persisted in local storage. They will be dispatched the next time your app is running and dispatch is called.

So the hits should be dispatched once the user opens the app again.

There are currently 3 dispatch modes - periodic, manual and background. I think this plugin only supports periodic dispatch. Manual seems easy to implement, background looks also possible, but I haven't tried it myself so far.

petarov avatar Jan 27 '17 18:01 petarov

@petarov Thanks for the info. Yeah I just also looked at both the Android and iOS APIs and those seem pretty straight forward to implement. We could probably add setLocalDispatchPeriod and dispatchLocalHits pretty easily. I'll can add them tomorrow if we want. :)

cmackay avatar Jan 27 '17 23:01 cmackay

Just realized setDispatchInterval is already implemented. Forgot about that. :) But I am adding a dispatchHits() function which can be used to manually trigger dispatching.

cmackay avatar Jan 27 '17 23:01 cmackay

I added the dispatchHits functions and I should have it released sometime this weekend. #75 Thanks for adding the feature request. This will allow you manually dispatch the hits. The background dispatching requires additional permissions WAKE_LOCK and I am not sure I would want to add that as part of this plugin since it would apply to all users. I am open to suggestions if there are other ideas. Thanks!

Here are the dispatch related docs: https://developers.google.com/analytics/devguides/collection/android/v4/dispatch https://developers.google.com/analytics/devguides/collection/ios/v3/dispatch

cmackay avatar Jan 28 '17 00:01 cmackay

@cmackay Good points about WAKE_LOCK! This is something I've been wondering as well. Perhaps we can solve this by using Cordova hooks and only add dependencies when users specify they need them. This might also be a solution for optional IDFA dependencies. Will have a look when I have some time.

petarov avatar Jan 28 '17 09:01 petarov

I published the release 1.0.2 to npm which contains the dispatchHits function. I guess I will leave this issue open for the related investigation of background dispatching. Let me know if there are any questions or additional ideas for the plugin. Thanks!

cmackay avatar Jan 28 '17 14:01 cmackay