Skip to main content
Two optional callbacks report what happens in Moss to your own code:
  • onEvent receives usage events, such as a question asked, an answer delivered or a guide finished, for your analytics tool.
  • onError receives every problem the chat shows the user, with who can fix it and a reference for support.
Leaving them unset changes nothing.

Send events to your analytics

Pass onEvent in the AgentProvider config. Each call receives one event, { name, properties }. Names follow Segment’s “Object Action” style, and properties are camelCase, so most analytics tools take them as they are.
For a tool that doesn’t accept spaces in event names, such as Google Analytics 4, convert the name first, for example to moss_question_asked. MossEvent is a union narrowed by name, so TypeScript knows each event’s properties:
With the CDN script, set the same function in window.mossSettings before the script loads:

How events are delivered

  • Each event is delivered from a microtask, after Moss’s own work for it. Your handler never runs inside Moss’s code.
  • If your handler throws, or returns a promise that rejects, Moss logs a warning and carries on. The chat is not affected.
  • Moss reads your handler and eventQueryText when it delivers each event, so a new function you pass takes effect without remounting AgentProvider.
  • With Moss open in several tabs, guide events come from the tab the guide runs in.

Common properties

Every event carries these properties:

Event catalog

MOSS_EVENT_NAMES, exported by the SDK, lists every name. Details for some events:
  • Moss Question Asked: mode is 'guide' while a guide is running. queryText is present only if you opt in; see Question text.
  • Moss Answer Delivered: latencyMs runs from the question being sent to the answer arriving. hasHighlight means the answer points at an element on the page; hasCitation means it cites help articles. messageId is the answer’s message, the one Moss Feedback Given rates. It is absent when the answer adds no message, such as a highlight alone, or when its text waits for the user to take a step.
  • Moss Plan Finished: completed when Moss reports the guide complete or the user finishes it. abandoned when the user exits, the conversation ends (a new chat, including one askMoss() starts or one Moss starts after inactivity), Moss replaces the guide with another, or a support ticket the user files from the guide goes out.
  • Moss Feedback Given: from 0.17.0, with chrome.feedback.askWhatWentWrong, a thumbs-down the user explains is sent again for the same message with its reason: 'steps_mismatch', 'hard_to_follow', 'not_solved', 'wrong_answer', 'not_answered' or 'other'. With it on, a thumbs-down on a finished guide’s “Goal Complete!” card that the user explains also fires this event, with rating: 'down' and the reason, for the guide’s last answer. The user’s comment is never sent to your page, and neither is the session rating.
  • Moss Ticket Submitted: filed means your onSupportTicket confirmed the ticket. failed means your callback reported a failure, or the submit was refused or not sent. unconfirmed means nothing confirmed the outcome, for example because your callback timed out or threw, so the ticket may exist. See Support ticket handoff.

Moss Error types

Question text

What a user types can contain personal or customer data, so Moss Question Asked leaves the text out unless you opt in with eventQueryText:
No other event property carries free text from the user or the model, URLs or page content.

onError

onError is called for every problem the chat tells the user about: a turn that failed, an answer written without one of its tools, a request that never reached the server. It is new in 0.17.0.
onError is delivered like onEvent: from a microtask, with a handler that throws or rejects logged and ignored.

The error object (MossError)

In the chat, the user sees the same problem under the message: what went wrong, “Your admin can fix this in Moss.” or “This is a problem on Moss’s side and has been reported.” when they can’t fix it themselves, and the reference. The chat offers Retry when sending again can help, and Continue when a procedure stopped before it was done. onError isn’t called when the chat can’t connect at all. Listen for Moss Error with a connection_* type for that.

Codes

Service is the name of the connected service, such as your support desk or an API connection. sign_in_failed usually means your page’s token was refused: check getJwt and your token’s claims. See Authentication.

Stability of names

Event names and properties are a public contract. Renames and removals are announced in the release notes ahead of the release that makes them. New events and new optional properties can ship in any release, so a tracking plan should accept events and properties it doesn’t know yet.

Common questions

How do I send Moss usage to Segment, Amplitude or Google Analytics? Pass onEvent and forward each event to your tool’s track call. See Send events to your analytics. Can I see what users asked? Only if you opt in: set eventQueryText to 'include', or to a function that redacts the text first. Does an error in my handler break the chat? No. Moss catches it, logs a warning and carries on. Why do I get no Moss Question Asked for Start guide or Next? They aren’t questions. Guide progress is reported by the Moss Plan events. How do I find out when users hit problems? Pass onError. Each call says what failed, who can fix it and the reference to quote to support. For a chat that can’t connect at all, listen for Moss Error with a connection_* type.