Skip to content

Commit

Permalink
added Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
admineral committed Sep 21, 2024
1 parent 8fdabc6 commit 50d727d
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/app/components/Landingpage/DataInsights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Legend,
} from "recharts";
import { FaChartLine, FaShoppingCart } from "react-icons/fa";
import { track } from '@vercel/analytics';

interface DataPoint {
date: string;
Expand Down Expand Up @@ -283,6 +284,8 @@ const DataInsights: React.FC<DataInsightsProps> = () => {
setSelectedYears([]); // Clear selected years when switching to Total View
setInRowView(false); // Disable In-Row View when switching
}
// Track view mode change
track('View Mode Changed', { mode });
};

// Function to toggle year selection
Expand All @@ -295,6 +298,8 @@ const DataInsights: React.FC<DataInsightsProps> = () => {
return [...prev, year];
}
});
// Track year selection
track('Year Selected', { year });
};

// Function to extract unique years from the data
Expand Down Expand Up @@ -512,8 +517,12 @@ const DataInsights: React.FC<DataInsightsProps> = () => {
{/* Toggle Button for Total In-Row View */}
<div className="flex flex-wrap gap-2 mb-6">
<button
onClick={() => setInRowView(!inRowView)}
disabled={!isByYear} // Enable only when By Year View is active
onClick={() => {
setInRowView(!inRowView);
// Track in-row view toggle
track('In-Row View Toggled', { enabled: !inRowView });
}}
disabled={!isByYear}
className={`px-4 py-2 rounded-full border ${
inRowView
? "bg-yellow-500 text-white border-yellow-500"
Expand All @@ -527,7 +536,11 @@ const DataInsights: React.FC<DataInsightsProps> = () => {
{/* Toggle Buttons for Time Granularity */}
<div className="flex flex-wrap gap-2 mb-6">
<button
onClick={() => setTimeGranularity("Monthly")}
onClick={() => {
setTimeGranularity("Monthly");
// Track time granularity change
track('Time Granularity Changed', { granularity: 'Monthly' });
}}
className={`px-4 py-2 rounded-full border ${
timeGranularity === "Monthly"
? "bg-purple-500 text-white border-purple-500"
Expand All @@ -537,7 +550,11 @@ const DataInsights: React.FC<DataInsightsProps> = () => {
Monthly
</button>
<button
onClick={() => setTimeGranularity("Weekly")}
onClick={() => {
setTimeGranularity("Weekly");
// Track time granularity change
track('Time Granularity Changed', { granularity: 'Weekly' });
}}
className={`px-4 py-2 rounded-full border ${
timeGranularity === "Weekly"
? "bg-purple-500 text-white border-purple-500"
Expand Down

0 comments on commit 50d727d

Please sign in to comment.