segmentio / analytics-next

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

Typescript issue on consent object of CoreExtraContext type #1060

Closed philibea closed 5 months ago

philibea commented 6 months ago

As we start adding the consent management on our configuration actually there is no consent type on CoreExtraContext https://github.com/segmentio/analytics-next/blob/master/packages/core/src/events/interfaces.ts#L50

i wonder if it was normal as i find how to configure the consent middleware on a javascript project: https://github.com/segmentio/consent-manager/blob/f9d5166679b3c928b394b8ad50d517fdf43654b1/src/consent-manager-builder/analytics.ts#L20 and with a typescript project you will have type error on any.

Maybe there is better way do to that but this clearly missing of documentation on the website.

Do we need to use this wrapper https://github.com/segmentio/analytics-next/blob/master/packages/consent/consent-tools/README.md

silesky commented 6 months ago

Thanks for taking out an issue @philibea,

Documentation is still a WIP, but I think the reasoning is these special consent objects are meant to be constructed by our libraries -- we haven't been encouraging people to use them directly, so documenting them has not been front of mind.

Regardless, CoreExtraContext has a very loose index signature, which means you won't get any TypeScript errors -- for better or for worse.

Segment Consent Manager is confusingly, not actually related to our consent manager library in this repo. They actually using different APIs (you can see the middleware that consent-tools uses and it creates a totally different object than in the segment consent manager repo). Segment Consent Manager is a simple GUI consent manager that uses hardcoded categories per integration, whereas the consent management solution in this repo is meant to be a flexible solution that works with OneTrust, TrustArc, or even a home-rolled consent manager. The app consent dashboard only works with this library.

If you can utilize this library instead, I would probably do it -- as this is the future of consent at Segment.