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

Flush-only disabling for client-specific (e.g., expensive internet) conditions #361

Closed
cprince-foreflight opened this issue Sep 17, 2024 · 6 comments
Assignees
Labels

Comments

@cprince-foreflight
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Some of our users have expensive internet connections. They don't want to pay for sending Segment events while only that expensive internet is available.

Describe the solution you'd like
What I'd like is a dynamic means (e.g., a Swift closure) that can be called near here to determine whether or not to flush analytics events. This could be setup in the Configuration.

Right now, there is a general purpose enabled flag, but if that is false, as far as I understand it, that will also disable events from being persisted.

What we want is a means to specifically disable flushing, but still have new events persisted.

Describe alternatives you've considered
We are planning to setup our own change (just locally, on top of your SDK) using a long flushInterval to effectively disable only flushing.

Additional context
This is for an aviation related app.

@bsneed
Copy link
Contributor

bsneed commented Sep 17, 2024

Hi @cprince-foreflight! It sounds like what you want is a custom flush policy. You can see an example one here: https://github.com/segmentio/analytics-swift/blob/main/Examples/tasks/NetBlockerFlushPolicy.swift

There's also the default ones that might be useful as working examples too.
https://github.com/segmentio/analytics-swift/tree/main/Sources/Segment/Utilities/Policies

Once you've made one, you'd add it to your analytics config like so ...

analytics.add(policy: ExpensiveNetworkPolicy)

I notice that the flush policy stuff isn't documented terribly well and have filed an internal ticket to improve that. Let me know if you need any assistance, happy to help.

@cprince-foreflight
Copy link
Contributor Author

Thanks. We are solving this right now via a custom flush policy. And within that using a long (infinite) flushInterval to delay flushing. Are you suggesting entirely replacing the current flush policies with just one of our own? And not relying on this flushInterval strategy?

@bsneed
Copy link
Contributor

bsneed commented Sep 17, 2024

No problem! Yeah, we can probably do better than that. I did find a bug in the policies in that they're flushing too often right now. I'm going to fix that, and I'll also come back here in just a bit with an example of how to structure yours. Gimmie just a few and I'll be back.

@bsneed
Copy link
Contributor

bsneed commented Sep 17, 2024

Heya @cprince-foreflight, if you could have a look at this example: https://github.com/segmentio/analytics-swift/blob/main/Examples/tasks/UncleFlushPolicy.swift

If you try that against main and can verify that meets your needs, lemme know and I'll do a release for you. If you need further changes, etc, I can do that too. I'll leave this issue open till I hear from you. Thanks so much!

@bsneed
Copy link
Contributor

bsneed commented Sep 20, 2024

I just needed to do a release for another issue. Please reopen this if necessary.

@bsneed bsneed closed this as completed Sep 20, 2024
@cprince-foreflight
Copy link
Contributor Author

Thanks! I'm passing this onto my colleague who was actually looking into this.

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

No branches or pull requests

2 participants