NextJS
Alytica Analytics Integration for Next.js
Overview
Alytica is a lightweight, privacy-conscious web analytics tool perfectly suited for Next.js applications. Offering comprehensive tracking capabilities with minimal performance impact, Alytica helps you understand user interactions across server-side and client-side rendered pages.
Key Features
- Automatic page view tracking
- Server-side and client-side compatibility
- Custom event tracking
- Performance-optimized tracking script
- Seamless Next.js integration
Integration Steps
1. Create a Project
First create a project from your Alytica dashboard by clicking the button "New Website"
2. Static Script Injection
For Next.js, you have multiple integration approaches:
Option 1: _document.js (Recommended)
Option 2: Dynamic Script Injection (App Router)
3. Custom Event Tracking
Use the global window.alytica()
function across your Next.js application:
If you want to use our revenue attribution features you will have to set up payment events on your payment confirmation page like this:
You can use the global window.alytica()
function to track not only signups and payments, but also any event with any custom data
4. Server-Side Considerations
For server-side events or tracking, you'll need client-side execution:
Best Practices
- Use
strategy="afterInteractive"
in_document.js
- Implement tracking only on the client-side
- Avoid multiple script injections
- Keep tracking lightweight
Testing Your Integration
- Click the Verify Script button in the setup form. This will automatically check if the script is correctly installed and configured on your website.
- If successful, you'll see a "Verification Successful" message.
- If it fails, review the script placement and domain settings, then try again.
- Check Network tab for
https://alytica.tech/api/track-visit
calls - Verify custom events are being sent
- Use Alytica's dashboard for comprehensive insights
Conclusion
Alytica offers a straightforward, performant analytics solution for Next.js applications. By following these steps, you'll gain deep insights into user behavior with minimal configuration overhead.