segmentio / analytics-next

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

Rare Context2 in Nuxt 3 #1040

Closed agracia-foticos closed 4 months ago

agracia-foticos commented 4 months ago

We have this environment https://stackblitz.com/edit/nuxt-starter-juxjq4

When i use segment into a Nuxt 3 composable, the object into the composable and outthere its diferent!!!

image

silesky commented 4 months ago

Hey, @agracia-foticos

AnalyticsBrowser instances are thenable.

const analytics = new AnalyticsBrowser() // this is buffered

analytics.load(...)

const [analyticsInternal, ctx] = await analytics // this is the underlying, initialized analytics -- you generally don't need to do this:

We recommend you don't await.

const segment = await useSegment();  // don't do this
const segment = useSegment();  // do this