I'm not sure any of the usual analytics SDKs work with middleware right now since neither NodeJS nor browser APIs are fully supported. For Segment, you should be able to track events using their HTTP endpoint instead of the
The other option is to pass the assigned variation down to the client in a cookie and call Segment from the front-end. That approach is pretty messy though, not sure I would recommend that.