Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: offline support #171

Merged
merged 19 commits into from
Jan 24, 2024
Merged

feat: offline support #171

merged 19 commits into from
Jan 24, 2024

Conversation

Mercy811
Copy link
Contributor

@Mercy811 Mercy811 commented Jan 2, 2024

Summary

Requirements

ACCESS_NETWORK_STATE permission is required. If not, this feature will not supported and will fallback to previous behavior (causing an error)

User interfaces

This feature is enabled by default.

To opt out of using AndroidNetworkConnectivityPlugin and implement custom offline logic, setting config.offline to null will prevent plugin setup.

// Disable this feature
amplitude = Amplitude(
    Configuration(
        apiKey = AMPLITUDE_API_KEY,
        context = applicationContext,
        offline = AndroidNetworkConnectivityCheckerPlugin.Disabled
    )
)

// Implement your own plugin to toggle offline 

Implementation

  • AndroidNetworkConnectivityPlugin
    • Network connectivity checker will detect network connectivity when setup and set config.offline accordingly
    • Network listener will flush all stored events when back to online
  • EventPipeline
    • If no network, it will only save events to storage and will not schedule a flush
    • Otherwise (network connected, no permission, feature disabled), save events and schedule a flush

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

Save events on offline and send out when back to online automatically
@Mercy811 Mercy811 marked this pull request as ready for review January 2, 2024 16:57
@Mercy811 Mercy811 requested a review from qingzhuozhen January 4, 2024 05:55
Copy link
Contributor Author

@Mercy811 Mercy811 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move network listener from Amplitude to the network connectivity plugin. So that customers can remove the plugin and have their own offline implementation.

Copy link
Contributor Author

@Mercy811 Mercy811 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check how to remove a plugin.

Plugins are removed by reference. So come up with another way to disable the default plugin by setting config.offline to null.

@Mercy811 Mercy811 requested a review from qingzhuozhen January 12, 2024 18:36
Copy link
Contributor

@justin-fiedler justin-fiedler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Mercy811 !

@Mercy811 Mercy811 merged commit 669eead into main Jan 24, 2024
3 checks passed
@Mercy811 Mercy811 deleted the AMP-90600-offline branch January 24, 2024 00:49
github-actions bot pushed a commit that referenced this pull request Jan 24, 2024
# [1.13.0](v1.12.2...v1.13.0) (2024-01-24)

### Features

* offline support ([#171](#171)) ([669eead](669eead))
Copy link

🎉 This PR is included in version 1.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants