diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index f3a02ce4..b4aa27ce 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -219,6 +219,7 @@ model Blog { category BlogCategory? @relation(fields: [categoryId], references: [id], onDelete: SetNull) tags BlogTag[] comments BlogComment[] + researchFinding ContentResearchFinding? @@index([categoryId]) @@index([status]) @@ -1020,3 +1021,67 @@ model SmsCampaign { @@map("sms_campaigns") } +// ------------------------------------------------------------------------------ +// 5. SEO & Performance Tracking Models +// ------------------------------------------------------------------------------ +enum ResearchFindingStatus { + RESEARCHED + ACTIONED + EVALUATING + SCALED + PRUNED +} + +model ContentResearchFinding { + id String @id @default(uuid()) @db.Uuid + title String @db.VarChar(255) + hypothesis String @db.Text + targetKeywords String[] @map("target_keywords") + primaryKeyword String @map("primary_keyword") @db.VarChar(128) + expectedOutcome String @map("expected_outcome") @db.Text + status ResearchFindingStatus @default(RESEARCHED) + + blogId String? @unique @map("blog_id") @db.Uuid + blog Blog? @relation(fields: [blogId], references: [id], onDelete: SetNull) + + ceoFeedback String? @map("ceo_feedback") @db.Text + feedbackSubmittedAt DateTime? @map("feedback_submitted_at") @db.Timestamptz() + + snapshots ContentPerformanceSnapshot[] + + createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz() + updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz() + + @@index([status]) + @@index([primaryKeyword]) + @@map("content_research_findings") +} + +model ContentPerformanceSnapshot { + id String @id @default(uuid()) @db.Uuid + findingId String @map("finding_id") @db.Uuid + finding ContentResearchFinding @relation(fields: [findingId], references: [id], onDelete: Cascade) + + snapshotDate DateTime @default(now()) @map("snapshot_date") @db.Timestamptz() + + gscImpressions Int @default(0) @map("gsc_impressions") + gscClicks Int @default(0) @map("gsc_clicks") + gscPosition Float @default(0.0) @map("gsc_position") + + ga4ActiveUsers Int @default(0) @map("ga4_active_users") + ga4AvgEngagementSec Float @default(0.0) @map("ga4_avg_engagement_sec") + ga4BounceRate Float @default(0.0) @map("ga4_bounce_rate") + ga4ScrollDepthRate Float @default(0.0) @map("ga4_scroll_depth_rate") + + attributedOrdersCount Int @default(0) @map("attributed_orders_count") + attributedSalesValue Decimal @default(0) @map("attributed_sales_value") @db.Decimal(15, 2) + + actionRecommendation String? @map("action_recommendation") @db.VarChar(64) + analysisNotes String? @map("analysis_notes") @db.Text + + createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz() + + @@index([findingId, snapshotDate]) + @@map("content_performance_snapshots") +} + diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 066c9cab..551fd873 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -38,10 +38,12 @@ import { FaqModule } from "./faq/faq.module"; import { MenuModule } from "./menu/menu.module"; import { RevalidationModule } from "./common/revalidation/revalidation.module"; +import { SeoTrackingModule } from "./seo-tracking/seo-tracking.module"; import { Request, Response, NextFunction } from "express"; @Module({ imports: [ + SeoTrackingModule, SupportChatModule, RevalidationModule, SmsModule, diff --git a/backend/src/seo-tracking/dto/seo-tracking.dto.ts b/backend/src/seo-tracking/dto/seo-tracking.dto.ts new file mode 100644 index 00000000..605f00ea --- /dev/null +++ b/backend/src/seo-tracking/dto/seo-tracking.dto.ts @@ -0,0 +1,95 @@ +import { IsString, IsArray, IsOptional, IsEnum, IsUUID, ArrayNotEmpty } from 'class-validator'; +import { ResearchFindingStatus } from '@prisma/client'; + +export class CreateFindingDto { + @IsString() + title: string; + + @IsString() + hypothesis: string; + + @IsArray() + @ArrayNotEmpty() + @IsString({ each: true }) + targetKeywords: string[]; + + @IsString() + primaryKeyword: string; + + @IsString() + expectedOutcome: string; + + @IsOptional() + @IsEnum(ResearchFindingStatus) + status?: ResearchFindingStatus; + + @IsOptional() + @IsUUID() + blogId?: string; +} + +export class UpdateCeoFeedbackDto { + @IsString() + feedback: string; +} + +export class QueryFindingsDto { + @IsOptional() + page?: number; + + @IsOptional() + limit?: number; + + @IsOptional() + @IsString() + search?: string; + + @IsOptional() + @IsEnum(ResearchFindingStatus) + status?: ResearchFindingStatus; + + @IsOptional() + @IsString() + sortBy?: string; + + @IsOptional() + @IsString() + sortOrder?: 'asc' | 'desc'; +} + +export class CreateSnapshotDto { + @IsOptional() + gscImpressions?: number; + + @IsOptional() + gscClicks?: number; + + @IsOptional() + gscPosition?: number; + + @IsOptional() + ga4ActiveUsers?: number; + + @IsOptional() + ga4AvgEngagementSec?: number; + + @IsOptional() + ga4BounceRate?: number; + + @IsOptional() + ga4ScrollDepthRate?: number; + + @IsOptional() + attributedOrdersCount?: number; + + @IsOptional() + attributedSalesValue?: number; + + @IsOptional() + @IsString() + actionRecommendation?: string; + + @IsOptional() + @IsString() + analysisNotes?: string; +} diff --git a/backend/src/seo-tracking/seo-tracking.controller.ts b/backend/src/seo-tracking/seo-tracking.controller.ts new file mode 100644 index 00000000..f6d149a6 --- /dev/null +++ b/backend/src/seo-tracking/seo-tracking.controller.ts @@ -0,0 +1,58 @@ +import { + Controller, + Get, + Post, + Patch, + Body, + Param, + Query, + UseGuards, +} from '@nestjs/common'; +import { SeoTrackingService } from './seo-tracking.service'; +import { + CreateFindingDto, + QueryFindingsDto, + UpdateCeoFeedbackDto, + CreateSnapshotDto, +} from './dto/seo-tracking.dto'; +import { JwtAuthGuard } from '../auth/jwt-auth.guard'; +import { RolesGuard } from '../common/guards/roles.guard'; +import { Roles } from '../common/decorators/roles.decorator'; + +@Controller('admin/seo-tracking') +@UseGuards(JwtAuthGuard, RolesGuard) +@Roles('ADMIN', 'SUPER_ADMIN') +export class SeoTrackingController { + constructor(private readonly seoTrackingService: SeoTrackingService) {} + + @Post() + async createFinding(@Body() dto: CreateFindingDto) { + return this.seoTrackingService.createFinding(dto); + } + + @Get() + async findAll(@Query() query: QueryFindingsDto) { + return this.seoTrackingService.findAll(query); + } + + @Get(':id') + async findOne(@Param('id') id: string) { + return this.seoTrackingService.findOne(id); + } + + @Patch(':id/feedback') + async updateCeoFeedback( + @Param('id') id: string, + @Body() dto: UpdateCeoFeedbackDto, + ) { + return this.seoTrackingService.updateCeoFeedback(id, dto); + } + + @Post(':id/snapshots') + async addSnapshot( + @Param('id') id: string, + @Body() dto: CreateSnapshotDto, + ) { + return this.seoTrackingService.addSnapshot(id, dto); + } +} diff --git a/backend/src/seo-tracking/seo-tracking.module.ts b/backend/src/seo-tracking/seo-tracking.module.ts new file mode 100644 index 00000000..9bb5a82e --- /dev/null +++ b/backend/src/seo-tracking/seo-tracking.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common'; +import { SeoTrackingController } from './seo-tracking.controller'; +import { SeoTrackingService } from './seo-tracking.service'; +import { PrismaModule } from '../prisma/prisma.module'; + +@Module({ + imports: [PrismaModule], + controllers: [SeoTrackingController], + providers: [SeoTrackingService], + exports: [SeoTrackingService], +}) +export class SeoTrackingModule {} diff --git a/backend/src/seo-tracking/seo-tracking.service.spec.ts b/backend/src/seo-tracking/seo-tracking.service.spec.ts new file mode 100644 index 00000000..5ad54fd1 --- /dev/null +++ b/backend/src/seo-tracking/seo-tracking.service.spec.ts @@ -0,0 +1,119 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { SeoTrackingService } from './seo-tracking.service'; +import { PrismaService } from '../prisma/prisma.service'; +import { NotFoundException } from '@nestjs/common'; + +describe('SeoTrackingService (TDD)', () => { + let service: SeoTrackingService; + let prisma: any; + + const mockFinding = { + id: 'f9d3b841-8f52-4412-bc78-8316c029e001', + title: 'تغذیه گربه مبتلا به نارسایی کلیه', + hypothesis: 'تمرکز بر مکمل رنال و اسیدهای آمینه به دلیل خلا در نتایج فارسی', + targetKeywords: ['غذای کلیه گربه', 'مکمل رنال گربه'], + primaryKeyword: 'مکمل رنال گربه', + expectedOutcome: 'افزایش بازدید ارگانیک و رشد فروش مکمل‌های کلیه', + status: 'RESEARCHED', + blogId: null, + ceoFeedback: null, + feedbackSubmittedAt: null, + createdAt: new Date(), + updatedAt: new Date(), + }; + + beforeEach(async () => { + prisma = { + contentResearchFinding: { + create: jest.fn().mockResolvedValue(mockFinding), + findMany: jest.fn().mockResolvedValue([mockFinding]), + count: jest.fn().mockResolvedValue(1), + findUnique: jest.fn().mockResolvedValue(mockFinding), + update: jest.fn().mockImplementation(({ data }) => + Promise.resolve({ ...mockFinding, ...data }), + ), + }, + contentPerformanceSnapshot: { + create: jest.fn().mockResolvedValue({ + id: 'snap-1', + findingId: mockFinding.id, + gscImpressions: 1200, + gscClicks: 85, + attributedOrdersCount: 4, + attributedSalesValue: 2400000, + }), + }, + }; + + const module: TestingModule = await Test.createTestingModule({ + providers: [ + SeoTrackingService, + { provide: PrismaService, useValue: prisma }, + ], + }).compile(); + + service = module.get(SeoTrackingService); + }); + + it('should create a new research finding', async () => { + const dto = { + title: 'تغذیه گربه مبتلا به نارسایی کلیه', + hypothesis: 'تمرکز بر مکمل رنال', + targetKeywords: ['غذای کلیه گربه'], + primaryKeyword: 'مکمل رنال گربه', + expectedOutcome: 'فروش بیشتر', + }; + + const result = await service.createFinding(dto as any); + expect(result).toBeDefined(); + expect(result.title).toBe(dto.title); + expect(prisma.contentResearchFinding.create).toHaveBeenCalled(); + }); + + it('should return paginated findings with standard metadata', async () => { + const res = await service.findAll({ page: 1, limit: 10 }); + expect(res.data).toHaveLength(1); + expect(res.meta).toEqual({ + total: 1, + page: 1, + limit: 10, + totalPages: 1, + lastPage: 1, + hasNextPage: false, + hasPrevPage: false, + }); + }); + + it('should update CEO feedback atomically and record timestamp', async () => { + const feedback = 'تمرکز باید دقیقاً روی علائم زودرس کراتینین بالا باشد.'; + const updated = await service.updateCeoFeedback(mockFinding.id, { feedback }); + expect(updated.ceoFeedback).toBe(feedback); + expect(prisma.contentResearchFinding.update).toHaveBeenCalledWith( + expect.objectContaining({ + where: { id: mockFinding.id }, + data: expect.objectContaining({ + ceoFeedback: feedback, + }), + }), + ); + }); + + it('should throw NotFoundException if finding does not exist for feedback', async () => { + prisma.contentResearchFinding.findUnique.mockResolvedValueOnce(null); + await expect( + service.updateCeoFeedback('non-existing', { feedback: 'test' }), + ).rejects.toThrow(NotFoundException); + }); + + it('should add performance snapshot with GSC and Sales data', async () => { + const snap = await service.addSnapshot(mockFinding.id, { + gscImpressions: 1200, + gscClicks: 85, + attributedOrdersCount: 4, + attributedSalesValue: 2400000, + }); + + expect(snap.attributedOrdersCount).toBe(4); + expect(prisma.contentPerformanceSnapshot.create).toHaveBeenCalled(); + }); +}); diff --git a/backend/src/seo-tracking/seo-tracking.service.ts b/backend/src/seo-tracking/seo-tracking.service.ts new file mode 100644 index 00000000..a00a9f88 --- /dev/null +++ b/backend/src/seo-tracking/seo-tracking.service.ts @@ -0,0 +1,122 @@ +import { Injectable, NotFoundException } from '@nestjs/common'; +import { PrismaService } from '../prisma/prisma.service'; +import { CreateFindingDto, QueryFindingsDto, UpdateCeoFeedbackDto, CreateSnapshotDto } from './dto/seo-tracking.dto'; +import { createPaginationMeta } from '../common/utils/search.utils'; +import { Prisma } from '@prisma/client'; + +@Injectable() +export class SeoTrackingService { + constructor(private prisma: PrismaService) {} + + async createFinding(dto: CreateFindingDto) { + return this.prisma.contentResearchFinding.create({ + data: { + title: dto.title, + hypothesis: dto.hypothesis, + targetKeywords: dto.targetKeywords, + primaryKeyword: dto.primaryKeyword, + expectedOutcome: dto.expectedOutcome, + status: dto.status || 'RESEARCHED', + blogId: dto.blogId, + }, + include: { + blog: { + select: { id: true, title: true, slug: true, status: true }, + }, + }, + }); + } + + async findAll(query: QueryFindingsDto) { + const { page = 1, limit = 10, search, status, sortBy = 'createdAt', sortOrder = 'desc' } = query; + const safePage = Math.max(1, Number(page) || 1); + const safeLimit = Math.max(1, Number(limit) || 10); + const skip = (safePage - 1) * safeLimit; + + const where: Prisma.ContentResearchFindingWhereInput = {}; + if (status) { + where.status = status; + } + if (search) { + where.OR = [ + { title: { contains: search, mode: 'insensitive' } }, + { primaryKeyword: { contains: search, mode: 'insensitive' } }, + { hypothesis: { contains: search, mode: 'insensitive' } }, + ]; + } + + const [data, total] = await Promise.all([ + this.prisma.contentResearchFinding.findMany({ + where, + skip, + take: safeLimit, + orderBy: { [sortBy]: sortOrder }, + include: { + blog: { select: { id: true, title: true, slug: true } }, + snapshots: { + orderBy: { snapshotDate: 'desc' }, + take: 1, + }, + }, + }), + this.prisma.contentResearchFinding.count({ where }), + ]); + + return { + data, + meta: createPaginationMeta(total, safePage, safeLimit), + }; + } + + async findOne(id: string) { + const finding = await this.prisma.contentResearchFinding.findUnique({ + where: { id }, + include: { + blog: true, + snapshots: { + orderBy: { snapshotDate: 'desc' }, + take: 30, + }, + }, + }); + + if (!finding) { + throw new NotFoundException(`Research finding with ID ${id} not found`); + } + + return finding; + } + + async updateCeoFeedback(id: string, dto: UpdateCeoFeedbackDto) { + await this.findOne(id); + + return this.prisma.contentResearchFinding.update({ + where: { id }, + data: { + ceoFeedback: dto.feedback, + feedbackSubmittedAt: new Date(), + }, + }); + } + + async addSnapshot(findingId: string, dto: CreateSnapshotDto) { + await this.findOne(findingId); + + return this.prisma.contentPerformanceSnapshot.create({ + data: { + findingId, + gscImpressions: dto.gscImpressions || 0, + gscClicks: dto.gscClicks || 0, + gscPosition: dto.gscPosition || 0.0, + ga4ActiveUsers: dto.ga4ActiveUsers || 0, + ga4AvgEngagementSec: dto.ga4AvgEngagementSec || 0.0, + ga4BounceRate: dto.ga4BounceRate || 0.0, + ga4ScrollDepthRate: dto.ga4ScrollDepthRate || 0.0, + attributedOrdersCount: dto.attributedOrdersCount || 0, + attributedSalesValue: dto.attributedSalesValue || 0, + actionRecommendation: dto.actionRecommendation, + analysisNotes: dto.analysisNotes, + }, + }); + } +} diff --git a/frontend/admin-panel/src/components/Sidebar.tsx b/frontend/admin-panel/src/components/Sidebar.tsx index e20517cf..dc8dcab3 100644 --- a/frontend/admin-panel/src/components/Sidebar.tsx +++ b/frontend/admin-panel/src/components/Sidebar.tsx @@ -172,6 +172,7 @@ export default function Sidebar({ isOpen, setIsOpen, isCollapsed = false }: Side items: [ { icon: Image, label: 'بنرها و اسلایدرها', path: '/banners' }, { icon: FileText, label: 'وبلاگ و مقالات', path: '/blogs' }, + { icon: TrendingUp, label: 'پایش سئو و عملکرد', path: '/seo-tracking' }, { icon: FlaskConical, label: 'دانشنامه ترکیبات', path: '/ingredients' }, { icon: BookOpen, label: 'دانشنامه عمومی و علمی', path: '/wiki' }, { icon: UserCheck, label: 'پزشکان و کادر علمی', path: '/doctors' }, diff --git a/frontend/admin-panel/src/pages/SeoTrackingPage.test.tsx b/frontend/admin-panel/src/pages/SeoTrackingPage.test.tsx new file mode 100644 index 00000000..66d10fcf --- /dev/null +++ b/frontend/admin-panel/src/pages/SeoTrackingPage.test.tsx @@ -0,0 +1,64 @@ +import { render, screen, waitFor } from '@testing-library/react'; +import { BrowserRouter } from 'react-router-dom'; +import SeoTrackingPage from './SeoTrackingPage'; +import { seoTrackingApi } from '../services/seoTrackingApi'; +import { vi, describe, it, expect, beforeEach } from 'vitest'; + +vi.mock('../services/seoTrackingApi', () => ({ + seoTrackingApi: { + getFindings: vi.fn(), + getFindingById: vi.fn(), + updateCeoFeedback: vi.fn(), + }, +})); + +describe('SeoTrackingPage Admin UI', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('renders table headers and findings correctly', async () => { + (seoTrackingApi.getFindings as any).mockResolvedValueOnce({ + data: [ + { + id: 'test-finding-1', + title: 'بررسی پوکی استخوان در سگ‌های مسن', + hypothesis: 'کمبود گلوکزآمین در جیره غذایی', + primaryKeyword: 'گلوکزآمین سگ', + targetKeywords: ['گلوکزآمین سگ'], + expectedOutcome: 'افزایش فروش مکمل مفاصل', + status: 'ACTIONED', + blog: { + id: 'b1', + title: 'مقاله سلامت مفاصل', + slug: 'dog-joint-health', + }, + ceoFeedback: 'روی نژاد ژرمن شپرد تمرکز شود', + }, + ], + meta: { + total: 1, + page: 1, + limit: 10, + totalPages: 1, + lastPage: 1, + hasNextPage: false, + hasPrevPage: false, + }, + }); + + render( + + + + ); + + expect(screen.getByText('پایش عملکرد سئو و بازخورد مدیرعامل')).toBeDefined(); + + await waitFor(() => { + expect(screen.getByText('بررسی پوکی استخوان در سگ‌های مسن')).toBeDefined(); + expect(screen.getByText('گلوکزآمین سگ')).toBeDefined(); + expect(screen.getByText('دستور ثبت‌شده')).toBeDefined(); + }); + }); +}); diff --git a/frontend/admin-panel/src/pages/SeoTrackingPage.tsx b/frontend/admin-panel/src/pages/SeoTrackingPage.tsx new file mode 100644 index 00000000..9c09f771 --- /dev/null +++ b/frontend/admin-panel/src/pages/SeoTrackingPage.tsx @@ -0,0 +1,450 @@ +import { useState, useEffect, useCallback } from 'react'; +import { + TrendingUp, + Search, + Filter, + Eye, + MessageSquare, + Sparkles, + RefreshCw, + ExternalLink, + ChevronLeft, + ChevronRight, + BarChart2, + Send, +} from 'lucide-react'; +import toast from 'react-hot-toast'; +import { + seoTrackingApi, + type ResearchFinding, + type PerformanceSnapshot, +} from '../services/seoTrackingApi'; + +const STATUS_LABELS: Record = { + RESEARCHED: { label: 'تحقیق‌شده', color: 'bg-blue-50 text-blue-700 border-blue-200' }, + ACTIONED: { label: 'اقدام‌شده (مقاله زنده)', color: 'bg-emerald-50 text-emerald-700 border-emerald-200' }, + EVALUATING: { label: 'در حال پایش سنجه‌ها', color: 'bg-amber-50 text-amber-700 border-amber-200' }, + SCALED: { label: 'توسعه‌یافته (موفق)', color: 'bg-purple-50 text-purple-700 border-purple-200' }, + PRUNED: { label: 'بازنگری / حذف', color: 'bg-rose-50 text-rose-700 border-rose-200' }, +}; + +export default function SeoTrackingPage() { + const [findings, setFindings] = useState([]); + const [loading, setLoading] = useState(true); + const [page, setPage] = useState(1); + const [limit] = useState(10); + const [totalPages, setTotalPages] = useState(1); + const [totalCount, setTotalCount] = useState(0); + const [search, setSearch] = useState(''); + const [statusFilter, setStatusFilter] = useState(''); + + // Detail Modal & CEO Feedback + const [selectedFinding, setSelectedFinding] = useState(null); + const [detailLoading, setDetailLoading] = useState(false); + const [feedbackText, setFeedbackText] = useState(''); + const [submittingFeedback, setSubmittingFeedback] = useState(false); + + const fetchFindings = useCallback(async () => { + try { + setLoading(true); + const res = await seoTrackingApi.getFindings({ + page, + limit, + search: search.trim() || undefined, + status: statusFilter || undefined, + }); + setFindings(res.data); + setTotalPages(res.meta.totalPages); + setTotalCount(res.meta.total); + } catch { + toast.error('خطا در بارگذاری داده‌های پایش سئو'); + } finally { + setLoading(false); + } + }, [page, limit, search, statusFilter]); + + useEffect(() => { + fetchFindings(); + }, [fetchFindings]); + + const handleOpenDetail = async (id: string) => { + try { + setDetailLoading(true); + const data = await seoTrackingApi.getFindingById(id); + setSelectedFinding(data); + setFeedbackText(data.ceoFeedback || ''); + } catch { + toast.error('خطا در دریافت جزئیات یافته سئو'); + } finally { + setDetailLoading(false); + } + }; + + const handleSaveCeoFeedback = async () => { + if (!selectedFinding) return; + try { + setSubmittingFeedback(true); + const updated = await seoTrackingApi.updateCeoFeedback( + selectedFinding.id, + feedbackText.trim() + ); + setSelectedFinding(updated); + toast.success('دستور و بازخورد مدیرعامل با موفقیت ثبت شد'); + fetchFindings(); + } catch { + toast.error('خطا در ثبت بازخورد مدیرعامل'); + } finally { + setSubmittingFeedback(false); + } + }; + + const latestSnapshot: PerformanceSnapshot | undefined = + selectedFinding?.snapshots && selectedFinding.snapshots.length > 0 + ? selectedFinding.snapshots[0] + : undefined; + + return ( +
+ {/* Header */} +
+
+
+ +
+
+

+ پایش عملکرد سئو و بازخورد مدیرعامل +

+

+ اتصال هوشمند نتایج تحقیقات روزانه سئو به سنجه‌های زنده گوگل (GSC)، رفتار کاربر (GA4) و فروش استور +

+
+
+ + +
+ + {/* Filter and Search Bar */} +
+
+ + { + setSearch(e.target.value); + setPage(1); + }} + placeholder="جستجو در موضوع، کلیدواژه یا فرضیه سئو..." + className="w-full pl-4 pr-11 py-2.5 bg-white border border-gray-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-purple-500" + /> +
+ +
+ + +
+
+ + {/* Main Table */} +
+
+ + + + + + + + + + + + + {loading ? ( + + + + ) : findings.length === 0 ? ( + + + + ) : ( + findings.map((f) => { + const statusInfo = STATUS_LABELS[f.status] || { + label: f.status, + color: 'bg-gray-100 text-gray-600 border-gray-200', + }; + + return ( + + + + + + + + + ); + }) + )} + +
موضوع و فرضیهکلیدواژه اصلیوضعیتمقاله مرتبطدستور مدیرعاملعملیات
+ + در حال دریافت داده‌ها... +
+ موردی یافت نشد. +
+
{f.title}
+
{f.hypothesis}
+
+ + {f.primaryKeyword} + + + + {statusInfo.label} + + + {f.blog ? ( + + {f.blog.title} + + + ) : ( + بدون مقاله + )} + + {f.ceoFeedback ? ( + + + دستور ثبت‌شده + + ) : ( + ثبت‌نشده + )} + + +
+
+ + {/* Pagination Footer */} +
+
+ تعداد کل: {totalCount} مورد +
+ +
+ + + صفحه {page} از {totalPages || 1} + + +
+
+
+ + {/* Detail & CEO Feedback Modal */} + {selectedFinding && ( +
+
+ {/* Modal Header */} +
+
+

{selectedFinding.title}

+
+ کلیدواژه اصلی: + + {selectedFinding.primaryKeyword} + +
+
+ +
+ + {/* Modal Body */} +
+ {detailLoading ? ( +
+ + در حال بارگذاری جزئیات... +
+ ) : ( + <> + {/* Hypothesis & Outcome */} +
+
+

فرضیه و منطق سئو:

+

+ {selectedFinding.hypothesis} +

+
+ +
+

نتیجه مورد انتظار بیزینس:

+

+ {selectedFinding.expectedOutcome} +

+
+
+ + {/* Performance Metrics Cards */} +
+

+ + آخرین پایش زنده سنجه‌ها +

+ + {latestSnapshot ? ( +
+
+ ایمپرشن سرچ گوگل +
+ {latestSnapshot.gscImpressions.toLocaleString('fa-IR')} +
+ کلیک: {latestSnapshot.gscClicks} +
+ +
+ کاربر فعال GA4 +
+ {latestSnapshot.ga4ActiveUsers.toLocaleString('fa-IR')} +
+ + میانگین حضور: {Math.round(latestSnapshot.ga4AvgEngagementSec)} ثانیه + +
+ +
+ سفارش‌های متصل +
+ {latestSnapshot.attributedOrdersCount} سفارش +
+ + فروش: {Number(latestSnapshot.attributedSalesValue).toLocaleString('fa-IR')} ت + +
+ +
+ پیشنهاد سیستم +
+ {latestSnapshot.actionRecommendation || 'ادامه پایش'} +
+ خودکار +
+
+ ) : ( +
+ هنوز اولین پایش سنجه‌ها برای این موضوع ثبت نشده است. +
+ )} +
+ + {/* CEO Feedback Directive Section */} +
+
+ +

+ دستور و بازخورد مستقیم مدیرعامل (Parsa Aghayi) +

+
+

+ ثبت نظر در اینجا اختیاری است، ولی در صورت ثبت، به عنوان دستور الزام‌آور در چرخه خودکار بعدی رعایت می‌شود. +

+ +