Social Commerce Analytics
Relevant source files
The following files were used as context for generating this wiki page:
The Social Commerce Analytics module is a sophisticated tracking and intelligence system within MarketSage designed to analyze user interactions, community engagement, and market influence. It bridges the gap between traditional shopping metrics and social behavior, providing deep insights into how community interactions—such as reviews, deals, and group purchases—drive commerce outcomes.
The system serves as a central engine for calculating engagement scores, identifying viral content, and attributing revenue to specific social touchpoints. By leveraging real-time data collection and historical analysis, it enables the platform to provide personalized recommendations and detect emerging market trends influenced by social dynamics.
Sources: src/core/social/SocialCommerceAnalytics.ts:1-12, src/core/social/SocialShoppingHub.ts:1-12
Core Architecture and Data Flow
The analytics architecture is built around the SocialCommerceAnalytics class, which interacts with the broader AnalyticsService to track events and generate comprehensive reports. The service utilizes RxJS BehaviorSubject patterns to provide real-time streams of analytics data to the user interface.
Analytics Collection Process
The system follows a continuous collection cycle where metrics are gathered across several domains: engagement, influence, community health, commerce, content performance, and trends.
The diagram shows the flow of raw user events through specialized calculation modules to produce a unified metrics stream.
Sources: src/core/social/SocialCommerceAnalytics.ts:250-295, src/core/analytics/analyticsService.ts:45-75
Key Data Structures
The system relies on a strictly typed set of interfaces to represent various facets of social and commercial activity.
| Interface | Purpose | Key Fields |
|---|---|---|
SocialAnalytics | Root container for all metrics. | engagement, influence, community, commerce, content, trends |
EngagementMetrics | Tracks user activity levels. | dailyActiveUsers, shareRate, engagementScore |
InfluenceMetrics | Measures user and content impact. | topInfluencers, viralContent, reachMetrics |
CommerceMetrics | Connects social actions to sales. | socialCommerce, revenueAttribution, conversionFunnels |
CommunityMetrics | Evaluates community health. | groupGrowthRate, collaborativePurchases, healthScore |
TrendMetrics | Predicts future market movements. | emergingTrends, trendPredictions, seasonalPatterns |
Sources: src/core/social/SocialCommerceAnalytics.ts:15-240
Functional Modules
1. Influence and Virality Analysis
The system calculates a UserInfluence score by weighing follower counts (30%), engagement rates (40%), content shares (20%), and community impact (10%). It also monitors content for "virality" by tracking growth rates and reach estimates; content exceeding a threshold (e.g., 0.7) is flagged as viral.
Sources: src/core/social/SocialCommerceAnalytics.ts:354-380, src/core/social/SocialCommerceAnalytics.ts:400-435
2. Revenue Attribution
MarketSage tracks the influence of social touchpoints on purchases through the analyzePurchaseInfluence function. This maps direct social clicks, influencer-driven traffic, and community-driven recommendations to final conversion events.
Sources: src/core/social/SocialCommerceAnalytics.ts:468-475, src/core/social/SocialCommerceAnalytics.ts:605-615
3. Trend Detection and Prediction
The detectEmergingTrends module analyzes recent search data, product movements, and social sentiment to identify momentum in specific categories.
Sources: src/core/social/SocialCommerceAnalytics.ts:480-510
This sequence illustrates how a commerce action in the Social Hub triggers the analytics tracking pipeline.
Sources: src/core/social/SocialCommerceAnalytics.ts:440-465, src/core/social/SocialShoppingHub.ts:440-460
Integration with Security and UI
Social Analytics data is consumed by the security modules to assess risk and by the UI to provide user-facing insights.
- Security Context: The
SecurityAnalyzeruses social data, such as seller ratings and review patterns (detected by theReviewAnalyzer), to calculate overall risk scores. An unusual spike in 5-star reviews can trigger a warning. - UI Display: The
EnhancedInsightSectiondisplays current prices alongside market averages and "Value Scores" derived from the analytics engine.
// Example of weighting health scores for community analysis
private async calculateCommunityHealth(): Promise<number> {
const engagement = await this.getCommunityEngagement();
const contentQuality = await this.getCommunityContentQuality();
const moderation = await this.getModerationEffectiveness();
const growth = await this.getCommunityGrowth();
const satisfaction = await this.getCommunitySatisfaction();
// Weighted health score
const healthScore = (
engagement * 0.25 +
contentQuality * 0.25 +
moderation * 0.2 +
growth * 0.15 +
satisfaction * 0.15
);
return Math.max(0, Math.min(100, healthScore));
}
Sources: src/core/social/SocialCommerceAnalytics.ts:522-540, src/background/services/protect/securityAnalyzer.ts:38-60, src/common/models/scamDetection/reviewAnalyzer.ts:5-20, src/popup/components/insight/EnhancedInsightSection.tsx:140-180
Reporting and Insights
The system generates AnalyticsReport objects (Daily, Weekly, Monthly) that include:
- Insights: AI-driven observations regarding increasing or decreasing trends with specific impact levels.
- Recommendations: Actionable steps with implementation effort and expected timeline.
- Accuracy Metrics: A confidence level based on data quality (e.g., 0.95).
Sources: src/core/social/SocialCommerceAnalytics.ts:210-245, src/core/social/SocialCommerceAnalytics.ts:310-345
Conclusion
The Social Commerce Analytics module is critical for MarketSage's ability to interpret complex social signals as actionable shopping intelligence. By quantifying influence, tracking community health, and attributing revenue to social interactions, the system provides a data-driven foundation for both user-facing recommendations and backend security analysis.
Sources: src/core/social/SocialCommerceAnalytics.ts:5-10, src/core/social/SocialShoppingHub.ts:1-10