What is Context?
Context provides three essential data objects that shape your user experience:User Information
Profile data of the person using your app
Client Details
Information about the host platform and device
Location Context
How the user discovered and launched your app
Context is only available within a Farcaster client such as the Base App, not on the web.
If your mini app is accessed via a standard web browser, context data will not be provided. Design your app to gracefully handle the absence of context when running outside the Base App environment.
Why Context Matters
Context enables you to create mini apps that feel native to their social environment and optimize for viral growth:Use Case | Benefit |
---|---|
Personalized UX | Customize interface based on user identity and entry point |
Viral Optimization | Track and optimize discovery paths for growth |
Platform Adaptation | Adjust functionality for different host platforms |
Social Engagement | Leverage social context for community features |
Core Context Structure
User Object
Contains profile information about the person using your mini app:User Object Structure
User Object Properties
User Object Properties
- fid: Unique Farcaster identifier for the user
- username: Handle without @ symbol
- displayName: User’s chosen display name
- pfpUrl: Profile picture URL
Client Object
Information about the host platform and device:Client Object Structure
Client Object Properties
Client Object Properties
- clientFid: Identifies the host app (309857 = Base app)
- added: Whether user has saved your mini app
- platformType: Device type for responsive design
- safeAreaInsets: Safe zones to avoid system UI overlap
Location Object
Describes how the user discovered your mini app - critical for viral optimization:User Journey: Returning user opening from saved apps
Strategy: Focus on retention and progression features
Strategy: Focus on retention and progression features
Implementation Guide
1
Access Context Data
Import and use the
useMiniKit()
hook to access context:Always check for context availability before accessing its properties to avoid runtime errors.
2
Create Context-Driven Experiences
Design different experiences based on entry point:
This approach ensures users get personalized experiences based on how they discovered your app.
3
Implement Safe Area Support
Ensure your UI doesn’t overlap with system elements:
Safe area implementation is crucial for mobile experiences to avoid system UI overlap.
4
Add Social Features
Leverage cast embed data for social engagement:
Analytics and Growth Tracking
Leverage Base.dev provides comprehensive analytics out-of-the-box including user engagement metrics, entry point analysis, and session tracking. Import your mini app to Base.dev to access real-time analytics that complement your context-driven insights.
Viral Attribution
Track how users discover your app to optimize growth:Analytics Implementation
Growth Metrics to Monitor
Metric | Context Source | Optimization Goal |
---|---|---|
Cast Embed Launches | location.type === 'cast_embed' | Maximize viral sharing |
Return User Rate | location.type === 'launcher' | Improve retention |
Share Attribution | cast.author data | Identify top advocates |
Platform Performance | client.platformType | Optimize for mobile/desktop |
Next Steps
Understanding and leveraging context is foundational to creating mini apps that feel native to their social environment and drive sustainable viral growth.
Implement Context Access
Add
useMiniKit()
to your main component and validate context dataCreate Entry Point Flows
Design different experiences for each location type
Add Safe Area Support
Implement responsive padding for mobile experiences
Track Viral Metrics
Set up analytics for growth measurement and optimization