Bing Analytics and Insights added, background jobs added, database setup updated, environment setup updated, frontend updated, backend updated.
Onboarding Manager and Router Manager refactored, analytics and background jobs added, database setup updated, environment setup updated, frontend updated, backend updated. Critical onboarding database migration implemented.
This commit is contained in:
15
backend/services/analytics/models/__init__.py
Normal file
15
backend/services/analytics/models/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""
|
||||
Analytics Models Package
|
||||
|
||||
Contains data models and type definitions for the analytics system.
|
||||
"""
|
||||
|
||||
from .analytics_data import AnalyticsData
|
||||
from .platform_types import PlatformType, AnalyticsStatus, PlatformConnectionStatus
|
||||
|
||||
__all__ = [
|
||||
'AnalyticsData',
|
||||
'PlatformType',
|
||||
'AnalyticsStatus',
|
||||
'PlatformConnectionStatus'
|
||||
]
|
||||
51
backend/services/analytics/models/analytics_data.py
Normal file
51
backend/services/analytics/models/analytics_data.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""
|
||||
Analytics Data Models
|
||||
|
||||
Core data structures for analytics data across all platforms.
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, Any, Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class AnalyticsData:
|
||||
"""Standardized analytics data structure for all platforms"""
|
||||
platform: str
|
||||
metrics: Dict[str, Any]
|
||||
date_range: Dict[str, str]
|
||||
last_updated: str
|
||||
status: str # 'success', 'error', 'partial'
|
||||
error_message: Optional[str] = None
|
||||
|
||||
def is_successful(self) -> bool:
|
||||
"""Check if the analytics data was successfully retrieved"""
|
||||
return self.status == 'success'
|
||||
|
||||
def is_partial(self) -> bool:
|
||||
"""Check if the analytics data is partially available"""
|
||||
return self.status == 'partial'
|
||||
|
||||
def has_error(self) -> bool:
|
||||
"""Check if there was an error retrieving analytics data"""
|
||||
return self.status == 'error'
|
||||
|
||||
def get_metric(self, key: str, default: Any = None) -> Any:
|
||||
"""Get a specific metric value with fallback"""
|
||||
return self.metrics.get(key, default)
|
||||
|
||||
def get_total_clicks(self) -> int:
|
||||
"""Get total clicks across all platforms"""
|
||||
return self.get_metric('total_clicks', 0)
|
||||
|
||||
def get_total_impressions(self) -> int:
|
||||
"""Get total impressions across all platforms"""
|
||||
return self.get_metric('total_impressions', 0)
|
||||
|
||||
def get_avg_ctr(self) -> float:
|
||||
"""Get average click-through rate"""
|
||||
return self.get_metric('avg_ctr', 0.0)
|
||||
|
||||
def get_avg_position(self) -> float:
|
||||
"""Get average position in search results"""
|
||||
return self.get_metric('avg_position', 0.0)
|
||||
85
backend/services/analytics/models/platform_types.py
Normal file
85
backend/services/analytics/models/platform_types.py
Normal file
@@ -0,0 +1,85 @@
|
||||
"""
|
||||
Platform Types and Enums
|
||||
|
||||
Type definitions and constants for platform analytics.
|
||||
"""
|
||||
|
||||
from enum import Enum
|
||||
from typing import Dict, Any, List, Optional
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
class PlatformType(Enum):
|
||||
"""Supported analytics platforms"""
|
||||
GSC = "gsc"
|
||||
BING = "bing"
|
||||
WORDPRESS = "wordpress"
|
||||
WIX = "wix"
|
||||
|
||||
|
||||
class AnalyticsStatus(Enum):
|
||||
"""Analytics data retrieval status"""
|
||||
SUCCESS = "success"
|
||||
ERROR = "error"
|
||||
PARTIAL = "partial"
|
||||
|
||||
|
||||
@dataclass
|
||||
class PlatformConnectionStatus:
|
||||
"""Platform connection status information"""
|
||||
connected: bool
|
||||
sites_count: int
|
||||
sites: List[Dict[str, Any]]
|
||||
error: Optional[str] = None
|
||||
|
||||
def has_sites(self) -> bool:
|
||||
"""Check if platform has connected sites"""
|
||||
return self.sites_count > 0
|
||||
|
||||
def get_first_site(self) -> Optional[Dict[str, Any]]:
|
||||
"""Get the first connected site"""
|
||||
return self.sites[0] if self.sites else None
|
||||
|
||||
|
||||
# Platform configuration constants
|
||||
PLATFORM_CONFIG = {
|
||||
PlatformType.GSC: {
|
||||
"name": "Google Search Console",
|
||||
"description": "SEO performance and search analytics",
|
||||
"api_endpoint": "https://www.googleapis.com/webmasters/v3/sites",
|
||||
"cache_ttl": 3600, # 1 hour
|
||||
},
|
||||
PlatformType.BING: {
|
||||
"name": "Bing Webmaster Tools",
|
||||
"description": "Search performance and SEO insights",
|
||||
"api_endpoint": "https://ssl.bing.com/webmaster/api.svc/json",
|
||||
"cache_ttl": 3600, # 1 hour
|
||||
},
|
||||
PlatformType.WORDPRESS: {
|
||||
"name": "WordPress.com",
|
||||
"description": "Content management and site analytics",
|
||||
"api_endpoint": "https://public-api.wordpress.com/rest/v1.1",
|
||||
"cache_ttl": 1800, # 30 minutes
|
||||
},
|
||||
PlatformType.WIX: {
|
||||
"name": "Wix",
|
||||
"description": "Website builder and analytics",
|
||||
"api_endpoint": "https://www.wix.com/_api/wix-business-accounts",
|
||||
"cache_ttl": 1800, # 30 minutes
|
||||
}
|
||||
}
|
||||
|
||||
# Default platforms to include in comprehensive analytics
|
||||
DEFAULT_PLATFORMS = [PlatformType.GSC, PlatformType.BING, PlatformType.WORDPRESS, PlatformType.WIX]
|
||||
|
||||
# Metrics that are common across platforms
|
||||
COMMON_METRICS = [
|
||||
'total_clicks',
|
||||
'total_impressions',
|
||||
'avg_ctr',
|
||||
'avg_position',
|
||||
'total_queries',
|
||||
'connection_status',
|
||||
'connected_sites',
|
||||
'last_updated'
|
||||
]
|
||||
Reference in New Issue
Block a user