-
Notifications
You must be signed in to change notification settings - Fork 6
feat: support survey-interaction segment filters (ENG-1275) #52
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
Merged
+862
−11
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,21 @@ | ||
| import Foundation | ||
|
|
||
| struct Config { | ||
| struct Environment { | ||
| /// On error, the environment will be refreshed after this amount of time (in minutes) | ||
| static let refreshStateOnErrorTimeoutInMinutes = 10 | ||
| } | ||
|
|
||
| struct User { | ||
| /// Floor for the gap between two user-state syncs. Guards against a device clock | ||
| /// running ahead of the server, where every `expiresAt` the server returns is already | ||
| /// in the device's past and an unclamped timer would sync in a tight loop. | ||
| /// A `var` only so tests can shorten it; the SDK never writes to it. | ||
| static var minimumSyncIntervalInSeconds: TimeInterval = 60 | ||
|
|
||
| /// How long to wait before retrying a user-state sync that failed. Deliberately much | ||
| /// longer than the minimum interval so a sustained outage doesn't turn into a | ||
| /// fixed-rate request stream. Mirrors `Environment.refreshStateOnErrorTimeoutInMinutes`. | ||
| static var retryAfterFailureInMinutes = 10 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Sources/FormbricksSDK/Model/Workspace/Surveys/InteractionRefresh.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import Foundation | ||
|
|
||
| /// The three survey-lifecycle moments that can flip interaction-based segment membership. | ||
| /// Raw values match the source names used by the JS SDK so the gate below can be keyed | ||
| /// off the same vocabulary on both platforms. | ||
| enum InteractionSource: String { | ||
| case onDisplay | ||
| case onResponse | ||
| case onFinished | ||
| } | ||
|
|
||
| /// Per-survey gate for the post-interaction segment refresh. | ||
| /// | ||
| /// Each flag says whether interacting with *this* survey via that event can change some | ||
| /// live survey's segment membership — e.g. a survey referenced only by a "have seen" | ||
| /// filter refreshes on display but not on response or finish, and a survey no interaction | ||
| /// filter references never refreshes at all. | ||
| /// | ||
| /// The client API attaches this only for workspaces that use survey-interaction targeting, | ||
| /// so it is absent for everyone else, and present-but-all-false for surveys in such a | ||
| /// workspace that no interaction filter points at. | ||
| struct InteractionRefresh: Codable, Equatable { | ||
| let onDisplay: Bool | ||
| let onResponse: Bool | ||
| let onFinished: Bool | ||
|
|
||
| private enum CodingKeys: String, CodingKey { | ||
| case onDisplay, onResponse, onFinished | ||
| } | ||
|
|
||
| init(onDisplay: Bool = false, onResponse: Bool = false, onFinished: Bool = false) { | ||
| self.onDisplay = onDisplay | ||
| self.onResponse = onResponse | ||
| self.onFinished = onFinished | ||
| } | ||
|
|
||
| /// Missing sub-keys decode as `false`, mirroring the tolerant `Segment` decoder. A strict | ||
| /// model would turn a partial object into a `keyNotFound` on the whole workspace-state | ||
| /// decode, which blanks out every survey — so never require these keys. | ||
| init(from decoder: Decoder) throws { | ||
| let container = try decoder.container(keyedBy: CodingKeys.self) | ||
| onDisplay = try container.decodeIfPresent(Bool.self, forKey: .onDisplay) ?? false | ||
| onResponse = try container.decodeIfPresent(Bool.self, forKey: .onResponse) ?? false | ||
| onFinished = try container.decodeIfPresent(Bool.self, forKey: .onFinished) ?? false | ||
| } | ||
|
|
||
| /// Whether an interaction of this kind should trigger a user-state refresh. | ||
| func shouldRefresh(on source: InteractionSource) -> Bool { | ||
| switch source { | ||
| case .onDisplay: return onDisplay | ||
| case .onResponse: return onResponse | ||
| case .onFinished: return onFinished | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.