forked from PostHog/posthog-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(libraries): add groups, multivar FF, continuity support for post…
…hog-android (PostHog#11) Co-authored-by: Li Yi Yu <[email protected]>
- Loading branch information
1 parent
15bcec6
commit 7107ec0
Showing
27 changed files
with
1,169 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,3 +150,6 @@ build/ | |
|
||
# Ignore Gradle GUI config | ||
gradle-app.setting | ||
|
||
# Jacoco | ||
/posthog/jacoco.exec |
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
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
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 |
---|---|---|
|
@@ -26,13 +26,14 @@ | |
package com.posthog.android.sample; | ||
|
||
import android.app.Application; | ||
import android.util.Log; | ||
import com.posthog.android.PostHog; | ||
import com.posthog.android.Properties; | ||
|
||
import uk.co.chrisjenx.calligraphy.CalligraphyConfig; | ||
|
||
public class SampleApp extends Application { | ||
|
||
private static final String POSTHOG_API_KEY = "8jVz0YZ2YPtP7eL1I5l5RQIp-WcuFeD3pZO8c0YDMx4"; | ||
private static final String POSTHOG_API_KEY = "phc_X8B6bhR1QgQKP1WdpFLN82LxLxgZ7WPXDgJyRyvIpib"; | ||
|
||
@Override | ||
public void onCreate() { | ||
|
@@ -46,7 +47,7 @@ public void onCreate() { | |
|
||
// Initialize a new instance of the PostHog client. | ||
PostHog.Builder builder = | ||
new PostHog.Builder(this, POSTHOG_API_KEY, "http://d37f3802.ngrok.io") | ||
new PostHog.Builder(this, POSTHOG_API_KEY, "https://app.posthog.com") | ||
.captureApplicationLifecycleEvents() | ||
.recordScreenViews(); | ||
|
||
|
@@ -55,5 +56,8 @@ public void onCreate() { | |
|
||
// Now anytime you call PostHog.with, the custom instance will be returned. | ||
PostHog posthog = PostHog.with(this); | ||
|
||
// Identify from the getgo | ||
PostHog.with(this).identify("test_distinct_id", new Properties().putValue("name", "my name").putValue("email", "[email protected]")); | ||
} | ||
} |
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
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
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
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
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
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
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
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
76 changes: 76 additions & 0 deletions
76
posthog/src/main/java/com/posthog/android/Persistence.java
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,76 @@ | ||
package com.posthog.android; | ||
|
||
import static java.util.Collections.unmodifiableMap; | ||
|
||
import android.content.Context; | ||
|
||
import com.posthog.android.internal.Utils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Persistence layer is a cache map attached to a PostHog singleton instance | ||
*/ | ||
public class Persistence extends ValueMap { | ||
public static final String ENABLED_FEATURE_FLAGS_KEY = "$enabled_feature_flags"; | ||
public static final String GROUPS_KEY = "$groups"; | ||
|
||
static Persistence create() { | ||
Persistence persistence = new Persistence(); | ||
return persistence; | ||
} | ||
|
||
public Persistence() {} | ||
|
||
public Persistence(int initialCapacity) { | ||
super(initialCapacity); | ||
} | ||
|
||
// For deserialization | ||
Persistence(Map<String, Object> delegate) { | ||
super(delegate); | ||
} | ||
|
||
public Persistence unmodifiableCopy() { | ||
LinkedHashMap<String, Object> map = new LinkedHashMap<>(this); | ||
return new Persistence(unmodifiableMap(map)); | ||
} | ||
|
||
Persistence putEnabledFeatureFlags(Map featureFlags) { | ||
return putValue(ENABLED_FEATURE_FLAGS_KEY, featureFlags); | ||
} | ||
|
||
public ValueMap enabledFeatureFlags() { | ||
return getValueMap(ENABLED_FEATURE_FLAGS_KEY); | ||
} | ||
|
||
Persistence putGroups(Map groups) { | ||
return putValue(GROUPS_KEY, groups); | ||
} | ||
|
||
public ValueMap groups() { | ||
return getValueMap(GROUPS_KEY); | ||
} | ||
|
||
@Override | ||
public Persistence putValue(String key, Object value) { | ||
super.putValue(key, value); | ||
return this; | ||
} | ||
|
||
static class Cache extends ValueMap.Cache<Persistence> { | ||
|
||
Cache(Context context, Cartographer cartographer, String tag) { | ||
super(context, cartographer, tag, tag, Persistence.class); | ||
} | ||
|
||
@Override | ||
public Persistence create(Map<String, Object> map) { | ||
// PostHog client can be called on any thread, so this instance should be thread safe. | ||
return new Persistence(new Utils.NullableConcurrentHashMap<>(map)); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.