Skip to content

Mixpanel

Open in ChatGPT Open in Claude

The Foldspace SDK forwards agent lifecycle and interaction events to Mixpanel when the Mixpanel SDK is already loaded on the page. Use it to see agent activity alongside the rest of your product analytics.

Forwarding is opt-in: no events are sent until you call enableAnalyticsForwarding. All forwarding is wrapped in try/catch and never blocks or fails the agent.

The Mixpanel SDK must be loaded and accessible as window.mixpanel. If it is not found, a warning is logged and no error is thrown.

Forward all events to Mixpanel:

const agent = foldspace.agent('YOUR-AGENT-KEY');
agent.enableAnalyticsForwarding({
providers: ["mixpanel"]
});

Forward specific events only:

agent.enableAnalyticsForwarding({
providers: ["mixpanel"],
events: ["agent.ready", "conversation.created", "action.called"]
});

Enables forwarding of agent events to analytics providers found on window.

Parameters:

ParameterTypeRequiredDescription
configAnalyticsForwardingConfig | nullNoProvider and event selection. If omitted, all supported providers and all events are enabled by default.

AnalyticsForwardingConfig:

FieldTypeDefaultDescription
providers("mixpanel" | "amplitude" | "segment")[]["mixpanel", "amplitude", "segment"]Which analytics providers to forward events to. Set to ["mixpanel"] to forward to Mixpanel only. The provider must be available on window.
eventsstring[]All eventsWhich events to forward. If omitted, all supported events are forwarded. Invalid event names are silently skipped.

Returns: The agent instance, enabling method chaining.

All forwarded events are prefixed with foldspace. (e.g. foldspace.agent.ready).

EventDescription
agent.readyAgent has initialized and is ready
agent.removedAgent has been removed from the page
agent.openAgent UI was opened
agent.closedAgent UI was closed
conversation.createdA new conversation was started
conversation.historyAn existing conversation was loaded
action.calledAn action was executed
action.responseAn action returned a response

Every event payload is automatically enriched with agentName.

  • If called before the agent is ready, the call is queued and replayed once the agent initializes.
  • Only the payload properties listed above are forwarded per event. No sensitive or unrelated data is sent.
  • To forward to Amplitude or Segment as well, add them to the providers array or see Amplitude and Segment.