-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a30ec27
commit ec3db8f
Showing
3 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
41 changes: 41 additions & 0 deletions
41
contents/docs/integrate/feature-flags-code/_snippets/feature-flags-code-java.mdx
This file contains 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,41 @@ | ||
There are 2 steps to implement feature flags in Go: | ||
|
||
### Step 1: Evaluate the feature flag value | ||
|
||
#### Boolean feature flags | ||
|
||
```java | ||
boolean isMyFlagEnabled = posthog.isFeatureFlagEnabled("flag-key", "distinct_id_of_your_user"); | ||
|
||
if isMyFlagEnabled == true { | ||
// Do something differently for this user | ||
} | ||
``` | ||
|
||
#### Multivariate feature flags | ||
|
||
```java | ||
Optional<String> variant = posthog.getFeatureFlagVariant("flag-key", "distinct_id_of_your_user"); | ||
|
||
if (variant.isPresent() && variant.get().equals("variant-key")) { // replace 'variant-key' with the key of your variant | ||
// Do something differently for this user | ||
} | ||
``` | ||
|
||
import IncludePropertyInEvents from "./include-feature-flag-property-in-backend-events.mdx" | ||
|
||
<IncludePropertyInEvents /> | ||
|
||
There are two methods you can use to include feature flag information in your events: | ||
|
||
#### Include the `$feature/feature_flag_name` property | ||
|
||
In the event properties, include `$feature/feature_flag_name: variant_key`: | ||
|
||
```java | ||
posthog.capture("distinct_id_of_your_user", "event_name", new HashMap<String, Object>() { | ||
{ | ||
put("$feature/feature-flag-key", "variant-key"); // replace feature-flag-key with your flag key. Replace 'variant-key' with the key of your variant | ||
} | ||
}); | ||
``` |
This file contains 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