Analytics
Learn how to set up and use various analytics tools in your MkSaaS website
MkSaaS supports multiple analytics tools to track website traffic and user behavior. This flexible approach allows you to choose the analytics service that best fits your needs, privacy requirements, and budget.
Analytics System Structure
The analytics system in MkSaaS is designed with the following components:
This modular structure makes it easy to enable or disable specific analytics providers, and to add new ones as needed.
Setup
MkSaaS comes pre-configured with support for several popular analytics services:
Vercel Analytics
Vercel Analytics provides detailed insights into your website's visitors without compromising user privacy.
-
Enable Web Analytics in your Vercel project:
- Go to the Vercel dashboard and select your project
- Navigate to the Analytics tab
- Click "Enable" in the Web Analytics section
-
No environment variables are required as MkSaaS integrates Vercel Analytics through website configuration:
- If you don't want to use Vercel Analytics, you can disable it in the website configuration:
Vercel Analytics is implemented using the official @vercel/analytics package.
Vercel Speed Insights
Speed Insights helps you monitor and improve your website's performance by measuring Core Web Vitals and user interactions.
-
Enable Speed Insights in your Vercel project:
- Go to the Vercel dashboard and select your project
- Navigate to the Analytics tab
- Click "Enable" in the Speed Insights section
-
No environment variables are required as MkSaaS integrates Speed Insights through website configuration:
- If you don't want to use Speed Insights, you can disable it in the website configuration:
Speed Insights is implemented using the official @vercel/speed-insights package.
Google Analytics is a widely used analytics service that provides comprehensive website tracking and analytics capabilities.
- Create a Google Analytics account at analytics.google.com
- Set up a new property and get your Measurement ID (starts with "G-")
- Add the following environment variable:
Google Analytics is integrated using the official @next/third-parties package for Next.js.
Umami
Umami is a simple, privacy-focused alternative to Google Analytics. It provides essential website statistics without compromising visitor privacy.
- Create a Umami account at umami.is or set up your own Umami instance
- Create a new website in your Umami dashboard
- Get your Website ID and script URL
- Add the following environment variables:
For self-hosted Umami instances, use your custom script URL instead of the default one.
Plausible
Plausible is a lightweight, open-source, and privacy-friendly analytics tool that doesn't require cookie notices.
- Create a Plausible account at plausible.io
- Add your website
- Get your domain
- Add the following environment variables:
For self-hosted Plausible instances, use your custom script URL instead of the default one.
OpenPanel
OpenPanel is an open-source product analytics platform designed for tracking user behavior.
- Create an OpenPanel account at openpanel.dev
- Create a new project
- Get your Client ID
- Add the following environment variable:
DataFast
DataFast is a simple, privacy-friendly analytics tool focused on speed and reliability.
- Create a DataFast account at datafa.st
- Add your website
- Get your Website ID and domain
- Add the following environment variables:
Seline
Seline is an analytics platform with a focus on subscription businesses and conversion tracking.
- Create a Seline account at seline.com
- Set up your project
- Get your token
- Add the following environment variable:
How It Works
MkSaaS implements analytics tracking through a central Analytics
component that conditionally renders individual analytics components based on environment variables and configuration:
Each analytics component is:
- Only active in production mode
- Only loaded if the required environment variables are set or enabled in website configuration
- Implemented with minimal overhead
This means you can enable multiple analytics services simultaneously, or just use one that fits your needs.
Customization
Adding a Custom Analytics
You can add support for additional analytics services by following these steps:
- Create a new file in the
src/analytics
directory (e.g.,my-analytics.tsx
) - Implement your analytics component
- Add it to the
Analytics
component
Here's an example of adding a custom analytics service:
Then, update the Analytics
component to include your new service:
Finally, add the necessary environment variables:
Best Practices
- Consider Privacy Regulations: Choose analytics tools that comply with privacy regulations like GDPR and CCPA
- Implement Cookie Consent: If your analytics solution uses cookies, implement a proper cookie consent mechanism
- Use Multiple Tools for Different Purposes: Consider combining privacy-friendly tools like Plausible or Vercel Analytics for basic metrics with more comprehensive tools for detailed analysis
- Keep Environment Variables Secure: Never commit your API keys to version control; use environment variables and secrets management
- Test in Development: While analytics components only activate in production, test that they correctly load when the required environment variables are set
- Minimize Performance Impact: Use the appropriate loading strategy for scripts (
afterInteractive
orlazyOnload
) to minimize impact on page performance
Next Steps
Now that you understand how to set up analytics for your MkSaaS website, explore these related integrations: