fix(seo): Collect GSC data during SEO audit trigger, not only AI audit
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
The SEO audit from admin panel uses seo_audit.py (SEOAuditor), not audit_ai_service.py. Added GSC OAuth enrichment step after audit save. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
bc2bc4f556
commit
ac984b50a6
@ -435,6 +435,35 @@ def api_seo_audit_trigger():
|
||||
'company_name': company.name
|
||||
}), 500
|
||||
|
||||
# Enrich with OAuth data (Search Console) if available
|
||||
try:
|
||||
from oauth_service import OAuthService
|
||||
from search_console_service import SearchConsoleService
|
||||
|
||||
oauth = OAuthService()
|
||||
gsc_token = oauth.get_valid_token(db, company.id, 'google', 'search_console')
|
||||
if gsc_token and company.website:
|
||||
gsc = SearchConsoleService(gsc_token)
|
||||
gsc_data = gsc.get_search_analytics(company.website, days=28)
|
||||
if gsc_data:
|
||||
# Update the analysis record with GSC data
|
||||
analysis_record = db.query(CompanyWebsiteAnalysis).filter_by(
|
||||
company_id=company.id
|
||||
).first()
|
||||
if analysis_record:
|
||||
analysis_record.gsc_clicks = gsc_data.get('clicks')
|
||||
analysis_record.gsc_impressions = gsc_data.get('impressions')
|
||||
analysis_record.gsc_ctr = gsc_data.get('ctr')
|
||||
analysis_record.gsc_avg_position = gsc_data.get('position')
|
||||
analysis_record.gsc_top_queries = gsc_data.get('top_queries', [])
|
||||
analysis_record.gsc_period_days = gsc_data.get('period_days', 28)
|
||||
db.commit()
|
||||
logger.info(f"GSC data saved for company {company.id}: {gsc_data.get('clicks', 0)} clicks")
|
||||
except ImportError:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.warning(f"GSC enrichment failed for company {company.id}: {e}")
|
||||
|
||||
# Get the updated analysis record to return
|
||||
db.expire_all() # Refresh the session to get updated data
|
||||
analysis = db.query(CompanyWebsiteAnalysis).filter_by(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user