diff --git a/lib/Segment.php b/lib/Segment.php index 2e1aee0..875f389 100644 --- a/lib/Segment.php +++ b/lib/Segment.php @@ -53,7 +53,9 @@ public static function identify(array $message) { public static function group(array $message) { self::checkClient(); $groupId = !empty($message["groupId"]); - self::assert($groupId, "Segment::group() expects groupId"); + $userId = !(array_key_exists('userID', $message) && strlen((string) $message['userID']) > 0); + + self::assert($groupId && $userId, "Segment::group() expects userId and groupId"); self::validate($message, "group"); return self::$client->group($message); @@ -93,8 +95,8 @@ public static function screen(array $message) { */ public static function alias(array $message) { self::checkClient(); - $userId = !empty($message["userId"]); - $previousId = !empty($message["previousId"]); + $userId = !(array_key_exists('userID', $message) && strlen((string) $message['userID']) > 0); + $previousId = !(array_key_exists('previousId', $message) && strlen((string) $message['previousId']) > 0); self::assert($userId && $previousId, "Segment::alias() requires both userId and previousId"); return self::$client->alias($message); @@ -107,7 +109,7 @@ public static function alias(array $message) { * @param string $type */ public static function validate($msg, $type){ - $userId = !empty($msg["userId"]); + $userId = !(array_key_exists('userID', $msg) && strlen((string) $msg['userID']) > 0); $anonId = !empty($msg["anonymousId"]); self::assert($userId || $anonId, "Segment::${type}() requires userId or anonymousId"); }