https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
b

bright-autumn-23919

03/07/2022, 2:49 PM
Hello 👋 Did anyone managed to integrate growthbook with nextjs middleware + Segment? Trying to utilise the trackingCallback but it seems like
analytics-node
and middleware might not be so compatible.. Been patiently waiting for the follow up on this article: https://dev.to/jdorn/ab-testing-with-the-new-nextjs-12-middleware-54j6 😄 thanks!
f

future-teacher-7046

03/07/2022, 2:59 PM
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
analytics-node
package - https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/
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.
b

bright-autumn-23919

03/07/2022, 3:24 PM
Thanks, I will give http endpoint a shot! 👍
n

narrow-psychiatrist-15437

03/08/2022, 8:24 AM
Another tip is to track the event inside the
waitUntil()
method to avoid a timeout if the analytics endpoint responds slowly. See more here: https://vercel.com/docs/concepts/functions/edge-functions#nextfetchevent
👍 1
42 Views