Skip to content

userId Not Included in Event Object When Using @segment/analytics-node #1267

@kkanyingi

Description

@kkanyingi

Description

I've been following the Segment docs to send page and track events using the @segment/analytics-node package in my Node.js API.

However, when I call analytics.page as documented:

analytics.page({
    userId,
    properties,
});

I get the following validation error:

Error: .userId/anonymousId/previousId/groupId is nil

Upon inspecting the event object passed to assertUserIdentity(event), I noticed that userId is missing:

{
  "timestamp": "2025-03-21T15:01:38.730Z",
  "integrations": {},
  "type": "page",
  "properties": {},
  "context": {},
  "messageId": "node-next-...."
}

Interestingly, if I pass userId as the first argument:

analytics.page(userId, {
    userId,
    properties,
});

It bypasses the validation error but then causes issues elsewhere.

Question

Is this the expected behaviour? Am I structuring the call incorrectly, or is there a known issue with how userId is handled? Any guidance would be appreciated!

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