Skip to content

iOS: sendHitsInBackground ability? #74

Description

@jvjvjv

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.

Activity

  1. jvjvjv commented on Jan 27, 2017

    @jvjvjv
    Author

    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.

  2. petarov commented on Jan 27, 2017

    @petarov
    Collaborator

    @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.

  3. cmackay commented on Jan 27, 2017

    @cmackay
    Owner

    @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. :)

  4. cmackay commented on Jan 27, 2017

    @cmackay
    Owner

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

  5. cmackay commented on Jan 28, 2017

    @cmackay
    Owner

    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

  6. petarov commented on Jan 28, 2017

    @petarov
    Collaborator

    @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.

  7. cmackay commented on Jan 28, 2017

    @cmackay
    Owner

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions