vercel / analytics

Privacy-friendly, real-time traffic insights
https://vercel.com/analytics
Mozilla Public License 2.0
429 stars 26 forks source link

web/react: add use client directive to react component #36

Closed MaxLeiter closed 1 year ago

MaxLeiter commented 1 year ago

This should remove the need for consumers to wrap vercel/analytics in its own client component

tobiaslins commented 1 year ago

We did not add this yet because of multiple reasons:

MaxLeiter commented 1 year ago

At the time created the package, the app directory didn't support importing packages that had "use client" in it so it didn't had any affect. Will check if this is supported already

Confirmed this is supported

It's not possible to pass functions from a server component to our component then. This is needed for beforeSend.

What if the user doesn’t use beforeSend? If we add use client, the user can use <Analytics /> as is, and if they need beforeSend they can make their own wrapper component

The bundler did not add "use client" in the first line (but yes, we could manually add that after compiling in the first line)

It'd be best for the bundler to support it, but yeah any hack like this could work