Add Business Event Tracking to Our Greenflash Integration
You are a coding agent tasked with extending our existing Greenflash TypeScript SDK integration to track business events. We already have message logging working. Your goal is to add event tracking so that Greenflash can connect AI interactions to real business outcomes like conversions, upgrades, and churn.High-Level Objective
Extend the current implementation to:- Track business events that represent meaningful user milestones
- Link events to conversations when the outcome relates to an AI interaction
- Assign influence and value to quantify the business impact
- Use the correct TypeScript SDK syntax
Reference: The full documentation for the Events API is available at: https://docs.greenflash.ai/features/events
Why Track Events?
Events close the loop between AI interactions and business outcomes. While Greenflash already analyzes conversation quality and sentiment, events provide the ground truth:- Attribute Success: Link specific AI responses directly to business outcomes like upgrades or purchases
- Validate Quality: Confirm heuristic signals (like sentiment) with tangible outcome data
- Deepen Insights: Train Greenflash to identify conversation patterns that drive real-world results
When to Send Events
Capture moments that matter. Send an event whenever a user reaches a milestone that represents value creation or loss.Positive Indicators (Success Signals)
signup_completedtrial_startedtask_successupgrade_purchasedmeeting_bookedlead_converted
Negative Indicators (Friction/Churn Signals)
cancellation_requestederror_encounteredworkflow_abandonedrefund_requested
Contextual Indicators (Usage Context)
feature_viewedstep_completedusage_logged
Core Event Fields
| Field | Type | Required | Description |
|---|---|---|---|
eventType | string | Yes | The name of the event (e.g., upgrade, cancellation_requested) |
productId | uuid | Yes | Your Greenflash Product ID |
conversationId | uuid | No | Link to the conversation that influenced this outcome |
influence | enum | No | positive, negative, or neutral (defaults to neutral) |
value | string | Yes | The measurable value (e.g., "149.00") |
valueType | string | No | The type of value (e.g., currency, count) |
properties | object | No | Additional context as key-value pairs |
insertId | string | No | Unique ID for deduplication |
Basic Event Tracking
Fire-and-Forget (Recommended)
With Await (If Needed)
Event Examples by Use Case
Customer Support: Post-Chat Upgrade
Customer Support: Cancellation Request
Sales: Meeting Booked
Workflow: Task Completed Successfully
Workflow: Error Encountered
Linking Events to Conversations
TheconversationId field is crucial for connecting business outcomes to AI interactions. Always include it when:
- The event happened during an AI session
- The event happened shortly after an AI interaction
- There’s a clear causal relationship between the conversation and the outcome
Sampling for High-Volume Events
For high-volume applications, use sampling to control ingestion:Idempotency for Reliable Event Tracking
UseinsertId to prevent duplicate events when retrying failed requests:
Best Practice: For critical events like purchases, generate theinsertIdbefore attempting the request and persist it. If the request fails, retry with the sameinsertIdto guarantee exactly-once delivery.
Fire-and-Forget Pattern
For event tracking, you typically don’t want to block your application flow. Use fire-and-forget by not awaiting the promise:
Note: The .catch() is recommended to prevent unhandled promise rejections from crashing your app, but the event call runs in the background without blocking.
Integration Checklist
Your code should:- Identify key business milestones in our application (upgrades, cancellations, task completions, etc.)
- Add event tracking at each milestone using
client.events.create(...) - Link events to conversations by passing
conversationIdwhen relevant - Set appropriate influence (
positive,negative,neutral) - Include value and valueType for revenue-impacting events
- Add useful properties for deeper analysis
- Use fire-and-forget (no
await) with.catch()to avoid blocking
What You Must Deliver
- Event tracking at key business milestones
- Proper conversation linking where applicable
- Correct influence assignment (positive/negative/neutral)
- Value tracking for revenue-related events
- No disruption to existing message logging behavior

