Solomon7890 commited on
Commit
ce6a24b
·
verified ·
1 Parent(s): f07a1a9

Add Analytics & SEO

Browse files
Files changed (1) hide show
  1. analytics_seo.py +142 -0
analytics_seo.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Analytics & SEO Module for ProVerBs Ultimate Brain
3
+ - Google Analytics integration
4
+ - Query tracking
5
+ - User behavior analytics
6
+ - SEO optimization
7
+ """
8
+
9
+ import json
10
+ from datetime import datetime
11
+ from typing import Dict, List, Optional
12
+ import logging
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+ class AnalyticsTracker:
17
+ """Track user queries and interactions"""
18
+
19
+ def __init__(self):
20
+ self.queries: List[Dict] = []
21
+ self.sessions: Dict[str, Dict] = {}
22
+ self.popular_modes: Dict[str, int] = {}
23
+ self.popular_ai_models: Dict[str, int] = {}
24
+
25
+ def track_query(
26
+ self,
27
+ query: str,
28
+ mode: str,
29
+ ai_provider: str,
30
+ reasoning_enabled: bool,
31
+ response_time: float,
32
+ success: bool
33
+ ):
34
+ """Track a query"""
35
+ entry = {
36
+ "timestamp": datetime.now().isoformat(),
37
+ "query": query[:100], # Truncate for privacy
38
+ "mode": mode,
39
+ "ai_provider": ai_provider,
40
+ "reasoning_enabled": reasoning_enabled,
41
+ "response_time": response_time,
42
+ "success": success
43
+ }
44
+
45
+ self.queries.append(entry)
46
+
47
+ # Track mode popularity
48
+ self.popular_modes[mode] = self.popular_modes.get(mode, 0) + 1
49
+
50
+ # Track AI model popularity
51
+ self.popular_ai_models[ai_provider] = self.popular_ai_models.get(ai_provider, 0) + 1
52
+
53
+ logger.info(f"Tracked query: {query[:50]}... [Mode: {mode}, AI: {ai_provider}]")
54
+
55
+ def get_analytics(self) -> Dict:
56
+ """Get analytics summary"""
57
+ total_queries = len(self.queries)
58
+ successful_queries = sum(1 for q in self.queries if q['success'])
59
+ avg_response_time = sum(q['response_time'] for q in self.queries) / total_queries if total_queries > 0 else 0
60
+
61
+ # Get top modes
62
+ top_modes = sorted(self.popular_modes.items(), key=lambda x: x[1], reverse=True)[:3]
63
+
64
+ # Get top AI models
65
+ top_ai = sorted(self.popular_ai_models.items(), key=lambda x: x[1], reverse=True)[:3]
66
+
67
+ return {
68
+ "total_queries": total_queries,
69
+ "successful_queries": successful_queries,
70
+ "success_rate": f"{(successful_queries/total_queries*100):.2f}%" if total_queries > 0 else "0%",
71
+ "avg_response_time": f"{avg_response_time:.2f}s",
72
+ "top_modes": top_modes,
73
+ "top_ai_models": top_ai,
74
+ "queries_with_reasoning": sum(1 for q in self.queries if q['reasoning_enabled']),
75
+ "recent_queries": self.queries[-10:][::-1] # Last 10, reversed
76
+ }
77
+
78
+ def export_analytics(self, filepath: str = "analytics_data.json"):
79
+ """Export analytics to JSON file"""
80
+ data = self.get_analytics()
81
+ with open(filepath, 'w') as f:
82
+ json.dump(data, f, indent=2)
83
+ logger.info(f"Analytics exported to {filepath}")
84
+
85
+
86
+ class SEOOptimizer:
87
+ """SEO optimization utilities"""
88
+
89
+ @staticmethod
90
+ def get_meta_tags() -> str:
91
+ """Generate SEO meta tags"""
92
+ return """
93
+ <meta name="description" content="ProVerBs Ultimate Legal AI Brain - Advanced legal assistant with 100+ reasoning protocols, multi-AI support, and specialized legal modes. Free to use.">
94
+ <meta name="keywords" content="legal AI, legal assistant, chain of thought, reasoning AI, legal research, document validation, ProVerBs, ADAPPT-I, quantum reasoning">
95
+ <meta name="author" content="Solomon7890">
96
+ <meta name="robots" content="index, follow">
97
+ <meta property="og:title" content="ProVerBs Ultimate Legal AI Brain">
98
+ <meta property="og:description" content="The most advanced legal AI platform with 100+ reasoning protocols and multi-AI support">
99
+ <meta property="og:type" content="website">
100
+ <meta property="og:url" content="https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE">
101
+ <meta property="og:image" content="https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE/resolve/main/preview.png">
102
+ <meta name="twitter:card" content="summary_large_image">
103
+ <meta name="twitter:title" content="ProVerBs Ultimate Legal AI Brain">
104
+ <meta name="twitter:description" content="Advanced legal AI with 100+ reasoning protocols">
105
+ """
106
+
107
+ @staticmethod
108
+ def get_structured_data() -> str:
109
+ """Generate JSON-LD structured data for SEO"""
110
+ return """
111
+ <script type="application/ld+json">
112
+ {
113
+ "@context": "https://schema.org",
114
+ "@type": "SoftwareApplication",
115
+ "name": "ProVerBs Ultimate Legal AI Brain",
116
+ "description": "Advanced legal AI assistant with 100+ reasoning protocols, multi-AI support, and specialized legal modes",
117
+ "applicationCategory": "LegalTechnology",
118
+ "operatingSystem": "Web Browser",
119
+ "offers": {
120
+ "@type": "Offer",
121
+ "price": "0",
122
+ "priceCurrency": "USD"
123
+ },
124
+ "author": {
125
+ "@type": "Person",
126
+ "name": "Solomon7890"
127
+ },
128
+ "featureList": [
129
+ "100+ Reasoning Protocols",
130
+ "6 AI Models (GPT-4, Gemini, Perplexity, etc.)",
131
+ "7 Specialized Legal Modes",
132
+ "Chain-of-Thought Reasoning",
133
+ "Document Validation",
134
+ "Legal Research Assistant"
135
+ ]
136
+ }
137
+ </script>
138
+ """
139
+
140
+
141
+ # Global analytics tracker
142
+ analytics_tracker = AnalyticsTracker()