Analytics w/ RSC

Trying out the App Router for my blogsite. My blogsite is mostly a static website and is a perfect candidate for RSC. However, I do a lot of tracking about interactions on my blog page - e.g. if you click a link to another blog post, I send an analytics event for a BUNCH of data. These events are sent on the onClick event handler of the <a> tag. Now the blog link is a completely static component that is perfect for RSC, but I also would have to send JS to do that tracking. How should I build this ? I hate to convert this to a client side component. It feels weird to send Javascript w/ a component for purely tracking purposes that does nothing to the UX. A static link, on paper, should be the perfect candidate to send 0 JS w/ it. P.S. I dont own the web server that receives the <a> requests so I cant do the tracking there. Plus this question is more around general tracking that happens on client side on various components.
3 Replies
whatplan
whatplan2y ago
you can make a small client component wrapper for the <a> tag with the handler and any logic required, and insert it where needed into your server components
Jai
Jai2y ago
ahh. good call. Thanks
whatplan
whatplan2y ago
yep this is really one of the selling points of server components very easy to add sprinkles of interactivity to your mostly static site
Want results from more Discord servers?
Add your server