Add Business Event Tracking to Our Greenflash Integration
You are a coding agent tasked with extending our existing Greenflash Python 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 Python 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 |
|---|---|---|---|
event_type | string | Yes | The name of the event (e.g., upgrade, cancellation_requested) |
product_id | uuid | Yes | Your Greenflash Product ID |
conversation_id | 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") |
value_type | string | No | The type of value (e.g., currency, count) |
properties | dict | No | Additional context as key-value pairs |
insert_id | string | No | Unique ID for deduplication |
Basic Event Tracking
Sync Example
Async (Fire-and-Forget) Example
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
Theconversation_id 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
Use \`insert_id\` to prevent duplicate events when retrying failed requests: \`\`\`python import uuidGenerate a unique ID for this event (store it if you need to retry)
event_insert_id = str(uuid.uuid4()) client.events.create( event_type=“upgrade”, product_id=product_id, conversation_id=conversation_id, influence=“positive”, value=“149.00”, value_type=“currency”, insert_id=event_insert_id, # Same ID = same event (no duplicates) ) \`\`\`Best Practice: For critical events like purchases, generate the \`insert_id\` before attempting the request and persist it. If the request fails, retry with the same \`insert_id\` to guarantee exactly-once delivery.
Async vs Sync Considerations
When adding event tracking, match our existing async/sync pattern:- Sync apps: Call
client.events.create(...)directly - Async apps: Use
AsyncGreenflashand wrap calls inasyncio.create_task()for fire-and-forget
Important: In Python, calling an async function withoutawaitreturns a coroutine that never executes. Always useasyncio.create_task()for fire-and-forget patterns in async code.
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
conversation_idwhen relevant - Set appropriate influence (
positive,negative,neutral) - Include value and value_type for revenue-impacting events
- Add useful properties for deeper analysis
- Use fire-and-forget (
asyncio.create_task()) in async code 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

