segmentio / analytics-next

Segment Analytics.js 2.0
https://segment.com/docs/connections/sources/catalog/libraries/website/javascript
MIT License
403 stars 136 forks source link

Can't Use analytics-next without using Identitfy ? #1019

Closed F1LT3R closed 7 months ago

F1LT3R commented 9 months ago

I'm trying to use this library from Node, because Brave does not allow tracking.

Here is the error I am receiving:

.userId/anonymousId/previousId/groupId is nil

But it appears I am forced track a login event for user first?

I do not want to use the following code, as my site does not have users:

analytics.identify({
    userId: req.body.userId,
    previousId: req.body.previousId,
})

Am I meant to be using a different tracking library for this?

chrisradek commented 8 months ago

@F1LT3R Sorry for the delayed response here.

So you're trying to make track calls using @segment/analytics-node, but without specifying a user/anonymousId?

Every event needs to be associated with either an identified or anonymous user. If you have no registered users, you can either set the anonymousId on your events to a new guid per event, or share the same id if you don't care about associating events to different user sessions. If you have a way of correlating inbound HTTP requests to a specific user's session (e.g. with a cookie/custom header/custom field in request body) then you can set the anonymousId on your events to that value.

No need to call analytics.identify() from your node service unless you want to either:

F1LT3R commented 7 months ago

Thanks @chrisradek - appreciate your feedback.