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

fix: rename groupProperties to groups for capture methods #139

Merged
merged 5 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Next

- chore: change host to new address ([#137](https://github.com/PostHog/posthog-android/pull/137))
- fix: rename groupProperties to groups for capture methods ([#139](https://github.com/PostHog/posthog-android/pull/139))

## 3.3.0 - 2024-05-24

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PostHogFake : PostHogInterface {
properties: Map<String, Any>?,
userProperties: Map<String, Any>?,
userPropertiesSetOnce: Map<String, Any>?,
groupProperties: Map<String, Any>?,
groups: Map<String, String>?,
) {
this.event = event
this.properties = properties
Expand Down
26 changes: 13 additions & 13 deletions posthog/src/main/java/com/posthog/PostHog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public class PostHog private constructor(
properties: Map<String, Any>?,
userProperties: Map<String, Any>?,
userPropertiesSetOnce: Map<String, Any>?,
groupProperties: Map<String, Any>?,
groups: Map<String, String>?,
appendSharedProps: Boolean = true,
appendGroups: Boolean = true,
): Map<String, Any> {
Expand Down Expand Up @@ -294,7 +294,7 @@ public class PostHog private constructor(

if (appendGroups) {
// merge groups
mergeGroups(groupProperties)?.let {
mergeGroups(groups)?.let {
props["\$groups"] = it
}
}
Expand All @@ -310,18 +310,18 @@ public class PostHog private constructor(
return props
}

private fun mergeGroups(groupProperties: Map<String, Any>?): Map<String, Any>? {
private fun mergeGroups(givenGroups: Map<String, String>?): Map<String, String>? {
val preferences = getPreferences()

@Suppress("UNCHECKED_CAST")
val groups = preferences.getValue(GROUPS) as? Map<String, Any>
val newGroups = mutableMapOf<String, Any>()
val groups = preferences.getValue(GROUPS) as? Map<String, String>
val newGroups = mutableMapOf<String, String>()

groups?.let {
newGroups.putAll(it)
}

groupProperties?.let {
givenGroups?.let {
newGroups.putAll(it)
}

Expand All @@ -334,7 +334,7 @@ public class PostHog private constructor(
properties: Map<String, Any>?,
userProperties: Map<String, Any>?,
userPropertiesSetOnce: Map<String, Any>?,
groupProperties: Map<String, Any>?,
groups: Map<String, String>?,
) {
try {
if (!isEnabled()) {
Expand Down Expand Up @@ -368,7 +368,7 @@ public class PostHog private constructor(
properties = properties,
userProperties = userProperties,
userPropertiesSetOnce = userPropertiesSetOnce,
groupProperties = groupProperties,
groups = groups,
// only append shared props if not a snapshot event
appendSharedProps = !snapshotEvent,
// only append groups if not a group identify event
Expand Down Expand Up @@ -527,8 +527,8 @@ public class PostHog private constructor(

synchronized(groupsLock) {
@Suppress("UNCHECKED_CAST")
val groups = preferences.getValue(GROUPS) as? Map<String, Any>
val newGroups = mutableMapOf<String, Any>()
val groups = preferences.getValue(GROUPS) as? Map<String, String>
val newGroups = mutableMapOf<String, String>()

groups?.let {
val currentKey = it[type]
Expand Down Expand Up @@ -561,7 +561,7 @@ public class PostHog private constructor(

private fun loadFeatureFlagsRequest(onFeatureFlags: PostHogOnFeatureFlags?) {
@Suppress("UNCHECKED_CAST")
val groups = getPreferences().getValue(GROUPS) as? Map<String, Any>
val groups = getPreferences().getValue(GROUPS) as? Map<String, String>

val distinctId = this.distinctId
val anonymousId = this.anonymousId
Expand Down Expand Up @@ -783,15 +783,15 @@ public class PostHog private constructor(
properties: Map<String, Any>?,
userProperties: Map<String, Any>?,
userPropertiesSetOnce: Map<String, Any>?,
groupProperties: Map<String, Any>?,
groups: Map<String, String>?,
) {
shared.capture(
event,
distinctId = distinctId,
properties = properties,
userProperties = userProperties,
userPropertiesSetOnce = userPropertiesSetOnce,
groupProperties = groupProperties,
groups = groups,
)
}

Expand Down
4 changes: 2 additions & 2 deletions posthog/src/main/java/com/posthog/PostHogInterface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public interface PostHogInterface {
* @param properties the custom properties
* @param userProperties the user properties, set as a "$set" property, Docs https://posthog.com/docs/product-analytics/user-properties
* @param userPropertiesSetOnce the user properties to set only once, set as a "$set_once" property, Docs https://posthog.com/docs/product-analytics/user-properties
* @param groupProperties the group properties, set as a "$groups" property, Docs https://posthog.com/docs/product-analytics/group-analytics
* @param groups the groups, set as a "$groups" property, Docs https://posthog.com/docs/product-analytics/group-analytics
*/
public fun capture(
event: String,
distinctId: String? = null,
properties: Map<String, Any>? = null,
userProperties: Map<String, Any>? = null,
userPropertiesSetOnce: Map<String, Any>? = null,
groupProperties: Map<String, Any>? = null,
groups: Map<String, String>? = null,
)

/**
Expand Down
2 changes: 1 addition & 1 deletion posthog/src/main/java/com/posthog/internal/PostHogApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ internal class PostHogApi(
fun decide(
distinctId: String,
anonymousId: String?,
groups: Map<String, Any>?,
groups: Map<String, String>?,
): PostHogDecideResponse? {
val decideRequest = PostHogDecideRequest(config.apiKey, distinctId, anonymousId = anonymousId, groups)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class PostHogDecideRequest(
apiKey: String,
distinctId: String,
anonymousId: String?,
groups: Map<String, Any>?,
groups: Map<String, String>?,
// add person_properties, group_properties
) : HashMap<String, Any>() {
init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class PostHogFeatureFlags(
fun loadFeatureFlags(
distinctId: String,
anonymousId: String?,
groups: Map<String, Any>?,
groups: Map<String, String>?,
onFeatureFlags: PostHogOnFeatureFlags?,
) {
executor.executeSafely {
Expand Down
34 changes: 17 additions & 17 deletions posthog/src/test/java/com/posthog/PostHogTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ internal class PostHogTest {
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.shutdownAndAwaitTermination()
Expand All @@ -363,7 +363,7 @@ internal class PostHogTest {
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.awaitExecution()
Expand All @@ -376,7 +376,7 @@ internal class PostHogTest {
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.shutdownAndAwaitTermination()
Expand All @@ -399,7 +399,7 @@ internal class PostHogTest {
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.shutdownAndAwaitTermination()
Expand All @@ -421,7 +421,7 @@ internal class PostHogTest {
assertEquals("value", theEvent.properties!!["prop"] as String)
assertEquals(userProps, theEvent.properties!!["\$set"])
assertEquals(userPropsOnce, theEvent.properties!!["\$set_once"])
assertEquals(groupProps, theEvent.properties!!["\$groups"])
assertEquals(groups, theEvent.properties!!["\$groups"])

sut.close()
}
Expand All @@ -438,7 +438,7 @@ internal class PostHogTest {
properties = props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.shutdownAndAwaitTermination()
Expand Down Expand Up @@ -570,7 +570,7 @@ internal class PostHogTest {

sut.group("theType", "theKey", groupProps)

sut.capture("test", groupProperties = mutableMapOf("theType3" to "theKey3"))
sut.capture("test", groups = mutableMapOf("theType3" to "theKey3"))

queueExecutor.shutdownAndAwaitTermination()

Expand Down Expand Up @@ -605,7 +605,7 @@ internal class PostHogTest {
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.shutdownAndAwaitTermination()
Expand Down Expand Up @@ -637,7 +637,7 @@ internal class PostHogTest {
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.shutdownAndAwaitTermination()
Expand Down Expand Up @@ -671,7 +671,7 @@ internal class PostHogTest {
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.shutdownAndAwaitTermination()
Expand Down Expand Up @@ -701,7 +701,7 @@ internal class PostHogTest {
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.shutdownAndAwaitTermination()
Expand All @@ -723,7 +723,7 @@ internal class PostHogTest {
assertEquals("value", theEvent.properties!!["prop"] as String)
assertEquals(userProps, theEvent.properties!!["\$set"])
assertEquals(userPropsOnce, theEvent.properties!!["\$set_once"])
assertEquals(groupProps, theEvent.properties!!["\$groups"])
assertEquals(groups, theEvent.properties!!["\$groups"])

sut.close()
}
Expand All @@ -743,7 +743,7 @@ internal class PostHogTest {
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.shutdownAndAwaitTermination()
Expand All @@ -765,7 +765,7 @@ internal class PostHogTest {
properties = props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.shutdownAndAwaitTermination()
Expand Down Expand Up @@ -913,7 +913,7 @@ internal class PostHogTest {
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.shutdownAndAwaitTermination()
Expand Down Expand Up @@ -946,7 +946,7 @@ internal class PostHogTest {
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.awaitExecution()
Expand All @@ -968,7 +968,7 @@ internal class PostHogTest {
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
groupProperties = groupProps,
groups = groups,
)

queueExecutor.shutdownAndAwaitTermination()
Expand Down
2 changes: 1 addition & 1 deletion posthog/src/test/java/com/posthog/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public val date: Date = ISO8601Utils.parse("2023-09-20T11:58:49.000Z", ParsePosi
public const val EVENT: String = "event"
public const val DISTINCT_ID: String = "distinctId"
public const val ANON_ID: String = "anonId"
public val groups: Map<String, Any> = mapOf("group1" to "theValue")
public val groups: Map<String, String> = mapOf("group1" to "theValue")
public val userProps: Map<String, Any> = mapOf("user1" to "theValue")
public val userPropsOnce: Map<String, Any> = mapOf("logged" to true)
public val groupProps: Map<String, Any> = mapOf("premium" to true)
Expand Down
Loading