Skip to content

Commit

Permalink
Remove properties from identify and alias (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Oct 24, 2023
1 parent 4ea7477 commit a17da13
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Next

- Ship proguard rules for proguard/r8 full mode ([#52](https://github.com/PostHog/posthog-android/pull/52))
- Remove properties from `identify` and `alias` ([#55](https://github.com/PostHog/posthog-android/pull/55))

## 3.0.0-beta.2 - 2023-10-20

Expand Down
5 changes: 2 additions & 3 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,15 @@ Identify the user

```kotlin
PostHog.identify(
"user123",
properties = mapOf("is_free_trial" to true),
"user123",
userProperties = mapOf("email" to "user@posthog.com")
)
```

Create an alias for the current user

```kotlin
PostHog.alias("theAlias", properties = mapOf("is_free_trial" to true))
PostHog.alias("theAlias")
```

Identify a group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class PostHogFake : PostHogInterface {

override fun identify(
distinctId: String,
properties: Map<String, Any>?,
userProperties: Map<String, Any>?,
userPropertiesSetOnce: Map<String, Any>?,
) {
Expand Down Expand Up @@ -71,7 +70,7 @@ public class PostHogFake : PostHogInterface {
this.screenTitle = screenTitle
}

override fun alias(alias: String, properties: Map<String, Any>?) {
override fun alias(alias: String) {
}

override fun isOptOut(): Boolean {
Expand Down
15 changes: 7 additions & 8 deletions posthog/api/posthog.api
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
public final class com/posthog/PostHog : com/posthog/PostHogInterface {
public static final field Companion Lcom/posthog/PostHog$Companion;
public synthetic fun <init> (Ljava/util/concurrent/ExecutorService;Ljava/util/concurrent/ExecutorService;Ljava/util/concurrent/ExecutorService;ZLkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun alias (Ljava/lang/String;Ljava/util/Map;)V
public fun alias (Ljava/lang/String;)V
public fun capture (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)V
public fun close ()V
public fun distinctId ()Ljava/lang/String;
public fun flush ()V
public fun getFeatureFlag (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
public fun getFeatureFlagPayload (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
public fun group (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;)V
public fun identify (Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)V
public fun identify (Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;)V
public fun isFeatureEnabled (Ljava/lang/String;Z)Z
public fun isOptOut ()Z
public fun optIn ()V
Expand All @@ -23,15 +23,15 @@ public final class com/posthog/PostHog : com/posthog/PostHogInterface {
}

public final class com/posthog/PostHog$Companion : com/posthog/PostHogInterface {
public fun alias (Ljava/lang/String;Ljava/util/Map;)V
public fun alias (Ljava/lang/String;)V
public fun capture (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)V
public fun close ()V
public fun distinctId ()Ljava/lang/String;
public fun flush ()V
public fun getFeatureFlag (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
public fun getFeatureFlagPayload (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
public fun group (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;)V
public fun identify (Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)V
public fun identify (Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;)V
public fun isFeatureEnabled (Ljava/lang/String;Z)Z
public fun isOptOut ()Z
public fun optIn ()V
Expand Down Expand Up @@ -140,15 +140,15 @@ public final class com/posthog/PostHogIntegration$DefaultImpls {
}

public abstract interface class com/posthog/PostHogInterface {
public abstract fun alias (Ljava/lang/String;Ljava/util/Map;)V
public abstract fun alias (Ljava/lang/String;)V
public abstract fun capture (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)V
public abstract fun close ()V
public abstract fun distinctId ()Ljava/lang/String;
public abstract fun flush ()V
public abstract fun getFeatureFlag (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
public abstract fun getFeatureFlagPayload (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
public abstract fun group (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;)V
public abstract fun identify (Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)V
public abstract fun identify (Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;)V
public abstract fun isFeatureEnabled (Ljava/lang/String;Z)Z
public abstract fun isOptOut ()Z
public abstract fun optIn ()V
Expand All @@ -162,12 +162,11 @@ public abstract interface class com/posthog/PostHogInterface {
}

public final class com/posthog/PostHogInterface$DefaultImpls {
public static synthetic fun alias$default (Lcom/posthog/PostHogInterface;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)V
public static synthetic fun capture$default (Lcom/posthog/PostHogInterface;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;ILjava/lang/Object;)V
public static synthetic fun getFeatureFlag$default (Lcom/posthog/PostHogInterface;Ljava/lang/String;Ljava/lang/Object;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun getFeatureFlagPayload$default (Lcom/posthog/PostHogInterface;Ljava/lang/String;Ljava/lang/Object;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun group$default (Lcom/posthog/PostHogInterface;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)V
public static synthetic fun identify$default (Lcom/posthog/PostHogInterface;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;ILjava/lang/Object;)V
public static synthetic fun identify$default (Lcom/posthog/PostHogInterface;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;ILjava/lang/Object;)V
public static synthetic fun isFeatureEnabled$default (Lcom/posthog/PostHogInterface;Ljava/lang/String;ZILjava/lang/Object;)Z
public static synthetic fun reloadFeatureFlags$default (Lcom/posthog/PostHogInterface;Lcom/posthog/PostHogOnFeatureFlags;ILjava/lang/Object;)V
public static synthetic fun screen$default (Lcom/posthog/PostHogInterface;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)V
Expand Down
17 changes: 3 additions & 14 deletions posthog/src/main/java/com/posthog/PostHog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -333,24 +333,19 @@ public class PostHog private constructor(
capture("\$screen", properties = props)
}

public override fun alias(alias: String, properties: Map<String, Any>?) {
public override fun alias(alias: String) {
if (!isEnabled()) {
return
}

val props = mutableMapOf<String, Any>()
props["alias"] = alias

properties?.let {
props.putAll(it)
}

capture("\$create_alias", properties = props)
}

public override fun identify(
distinctId: String,
properties: Map<String, Any>?,
userProperties: Map<String, Any>?,
userPropertiesSetOnce: Map<String, Any>?,
) {
Expand All @@ -363,10 +358,6 @@ public class PostHog private constructor(
val props = mutableMapOf<String, Any>()
props["\$anon_distinct_id"] = anonymousId

properties?.let {
props.putAll(it)
}

capture(
"\$identify",
distinctId = distinctId,
Expand Down Expand Up @@ -609,13 +600,11 @@ public class PostHog private constructor(

public override fun identify(
distinctId: String,
properties: Map<String, Any>?,
userProperties: Map<String, Any>?,
userPropertiesSetOnce: Map<String, Any>?,
) {
shared.identify(
distinctId,
properties = properties,
userProperties = userProperties,
userPropertiesSetOnce = userPropertiesSetOnce,
)
Expand Down Expand Up @@ -658,8 +647,8 @@ public class PostHog private constructor(
shared.screen(screenTitle, properties = properties)
}

public override fun alias(alias: String, properties: Map<String, Any>?) {
shared.alias(alias, properties = properties)
public override fun alias(alias: String) {
shared.alias(alias)
}

public override fun isOptOut(): Boolean = shared.isOptOut()
Expand Down
5 changes: 1 addition & 4 deletions posthog/src/main/java/com/posthog/PostHogInterface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ public interface PostHogInterface {
* Identifies the user
* Docs https://posthog.com/docs/product-analytics/identify
* @param distinctId the distinctId
* @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
*/
public fun identify(
distinctId: String,
properties: Map<String, Any>? = null,
userProperties: Map<String, Any>? = null,
userPropertiesSetOnce: Map<String, Any>? = null,
)
Expand Down Expand Up @@ -119,9 +117,8 @@ public interface PostHogInterface {
* Creates an alias for the user
* Docs https://posthog.com/docs/product-analytics/identify#alias-assigning-multiple-distinct-ids-to-the-same-user
* @param alias the alias
* @param properties the custom properties
*/
public fun alias(alias: String, properties: Map<String, Any>? = null)
public fun alias(alias: String)

/**
* Checks if the [optOut] mode is enabled or disabled
Expand Down
4 changes: 0 additions & 4 deletions posthog/src/test/java/com/posthog/PostHogTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ internal class PostHogTest {

sut.identify(
distinctId,
props,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
)
Expand All @@ -462,7 +461,6 @@ internal class PostHogTest {
val theEvent = batch.batch.first()
assertEquals("\$identify", theEvent.event)
assertEquals(distinctId, theEvent.distinctId)
assertEquals("value", theEvent.properties!!["prop"] as String)
assertNotNull(theEvent.properties!!["\$anon_distinct_id"])
assertEquals(userProps, theEvent.properties!!["\$set"])
assertEquals(userPropsOnce, theEvent.properties!!["\$set_once"])
Expand All @@ -479,7 +477,6 @@ internal class PostHogTest {

sut.alias(
"theAlias",
props,
)

queueExecutor.shutdownAndAwaitTermination()
Expand All @@ -493,7 +490,6 @@ internal class PostHogTest {
assertEquals("\$create_alias", theEvent.event)
assertNotNull(theEvent.distinctId)
assertEquals("theAlias", theEvent.properties!!["alias"] as String)
assertEquals("value", theEvent.properties!!["prop"] as String)

sut.close()
}
Expand Down

0 comments on commit a17da13

Please sign in to comment.