userGrowthAnalytics
Track and analyze user growth patterns and engagement metrics on Twitter by specifying a username, timeframe, and analysis period to gain actionable insights.
Instructions
Analyze user growth patterns and engagement trends over time
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| period | No | Number of periods to analyze (default: 4) | |
| timeframe | No | Analysis timeframe (default: "weekly") | |
| username | Yes | Username to analyze growth patterns for |
Implementation Reference
- Main handler function implementing the userGrowthAnalytics tool. Fetches user profile and recent tweets, computes growth metrics like followers, activity, and engagement.export const handleUserGrowthAnalytics: SocialDataHandler<UserGrowthAnalyticsArgs> = async ( _client: any, { username, timeframe = 'weekly', period = 4 }: UserGrowthAnalyticsArgs ) => { try { const socialClient = getSocialDataClient(); if (!socialClient) { return createMissingApiKeyResponse('User Growth Analytics'); } // Get current profile const currentProfile = await socialClient.getUserProfile({ username, includeMetrics: true }); // Get recent tweets to analyze growth patterns const tweets = await socialClient.getUserTweets({ username, maxResults: 50 }); // Calculate basic growth metrics from available data const analytics = { user: { username: currentProfile.data.username, current_followers: currentProfile.data.public_metrics?.followers_count || 0, current_following: currentProfile.data.public_metrics?.following_count || 0, total_tweets: currentProfile.data.public_metrics?.tweet_count || 0 }, timeframe, period, recent_activity: { recent_tweets_count: tweets.data?.length || 0, avg_engagement: tweets.data ? tweets.data.reduce((sum: number, tweet: any) => sum + (tweet.public_metrics?.like_count || 0) + (tweet.public_metrics?.retweet_count || 0), 0) / tweets.data.length : 0 }, note: 'Growth analytics based on current snapshot and recent activity patterns' }; return createSocialDataResponse( formatAnalytics(analytics, `User Growth Analytics for @${username}`) ); } catch (error) { throw new Error(formatSocialDataError(error as Error, 'user growth analytics')); } };
- src/socialdata-tools.ts:128-151 (schema)Zod input schema and description for the userGrowthAnalytics tool, defining parameters: username (required), timeframe (enum), period.userGrowthAnalytics: { description: 'Analyze user growth patterns and engagement trends over time', inputSchema: { type: 'object', properties: { username: { type: 'string', description: 'Username to analyze growth patterns for' }, timeframe: { type: 'string', enum: ['daily', 'weekly', 'monthly'], description: 'Analysis timeframe (default: "weekly")' }, period: { type: 'number', description: 'Number of periods to analyze (default: 4)', minimum: 1, maximum: 12 } }, required: ['username'] } },
- src/types/socialdata.ts:46-50 (schema)TypeScript interface defining the input arguments for the userGrowthAnalytics handler.export interface UserGrowthAnalyticsArgs { username: string; timeframe: 'daily' | 'weekly' | 'monthly'; period?: number; // number of days/weeks/months }
- src/index.ts:446-449 (registration)Registration and dispatch of the userGrowthAnalytics tool in the main MCP server request handler switch statement.case 'userGrowthAnalytics': { const args = request.params.arguments as any; response = await handleUserGrowthAnalytics(client, args); break;