Skip to content

Groups are not working #71

@mnapoli

Description

@mnapoli

groupIdentify() doesn't work

            PostHog::groupIdentify([
                'groupType' => 'team',
                'groupKey' => $team->id,
                'properties' => [
                    'name' => $team->name,
                ],
            ]);

It pushes events that are attached to a broken user:

Image

Full payload:

{
  "uuid": "019585bf-7ccf-7ecd-b9c6-1a748a7eab86",
  "event": "$groupidentify",
  "properties": {
    "$group_set": {
      "created_at": "2024-07-11",
      "name": "Team name"
    },
    "$lib": "posthog-php",
    "$lib_version": "3.0.3",
    "$group_key": 1,
    "$lib_consumer": "LibCurl",
    "$active_feature_flags": [],
    "$group_type": "team",
    "$geoip_...": "...",
    "$transformations_succeeded": [],
    "$transformations_failed": []
  },
  "timestamp": "2025-03-11T16:07:53+01:00",
  "team_id": ...,
  "distinct_id": "$team_1",
  "elements_chain": "",
  "created_at": "2025-03-11T16:07:55.062000+01:00"
}

The problem lies here:

"distinct_id": "$team_1",

I think this line is wrong:

"distinctId" => "\${$message['groupType']}_{$message['groupKey']}",

$group_type in capture is not working

Because of the problem above, I tried attaching the group to every event instead:

        $properties = [...];

        $properties['$group_type'] = 'team';
        $properties['$group_key'] = $team->id;

        PostHog::capture([
            'distinctId' => $user->id,
            'event' => $event,
            'properties' => $properties,
        ]);

The event is now attached to the user but not the group.

Full payload:

{
  "uuid": "019585d4-62cc-71ec-a70a-bb2dbc06a386",
  "event": "Event name",
  "properties": {
    "$group_type": "team",
    "$lib": "posthog-php",
    "$active_feature_flags": [],
    "$lib_version": "3.0.3",
    "$group_key": 1,
    "$lib_consumer": "LibCurl",
    "$set": {
      "$geoip_...": "...",
    },
    "$set_once": {
      "$initial_geoip_...": "..."
    },
    "$geoip_...": "...",
    "$transformations_succeeded": [],
    "$transformations_failed": []
  },
  "timestamp": "2025-03-11T16:30:43+01:00",
  "team_id": ...,
  "distinct_id": "1",
  "elements_chain": "",
  "created_at": "2025-03-11T16:30:44.506000+01:00"
}

If we only look at user and group-related data:

{
  "properties": {
    "$group_type": "team",
    "$group_key": 1,
  },
  "distinct_id": "1",
}

That looks incorrect. If I compare to an event reported by the web (JavaScript) SDK:

{
  "event": "$pageview",
  "properties": {
    "distinct_id": "1",
    "$user_id": "1",
    "$groups": {
      "team": 1
    },
    "$group_0": 1
  }
}

Properties don't look formatted the same way.

Is the PHP SDK using an obsolete format for the events API?

To be clear:

  • events reported by the web SDK are attached to the group
  • events reported by the PHP SDK are not attached to the group

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions