Skip to content

JavaScript API

Once the widget is on your page, it exposes a small global object, Tracya, that you can call from your own code. Most sites never need more than init, but the other methods let you drive flows programmatically, for example to build a "Replay tutorial" button.

Tracya.init(config)

Starts the widget. You call this once, and it is already in the snippet the dashboard gives you.

Tracya.init({
  projectId: 'YOUR_PROJECT_ID',
  apiUrl: 'https://api.tracya.io'
});

projectId is the project whose flows you want to load. apiUrl is the Tracya API, https://api.tracya.io for the hosted service. Calling init a second time does nothing; the widget warns in the console and keeps the first configuration.

Everything below only works after init has run and the flows have loaded.

Tracya.startFlow(flowId)

Starts a specific flow immediately, from its first step, regardless of its trigger. Use it when you want a flow to run in response to something in your app, like a button click, rather than on a page condition.

document.querySelector('#help-button').addEventListener('click', function() {
  Tracya.startFlow('YOUR_FLOW_ID');
});

If no flow matches the ID, the widget warns in the console and does nothing.

Tracya.show(flowId)

Shows a flow again even if the user has already seen it. It clears that flow's seen state and starts it from the beginning, in one call. This is the method behind a "Replay tutorial" or "Show me again" button.

Tracya.show('YOUR_FLOW_ID');

The difference from startFlow is the reset: startFlow just runs the flow, while show first wipes the record of the user having seen it, so a first-visit flow behaves as if it were new.

Tracya.reset(flowId)

Clears the stored state for one flow, without showing anything. After this, a first-visit flow becomes eligible to appear again on the next page load, and a once-per-session flow can run again this session.

Tracya.reset('YOUR_FLOW_ID');

Use it when you want to make a flow eligible again but let its normal trigger decide when it actually shows, rather than forcing it on screen immediately the way show does.

Tracya.resetAll()

Clears the stored state for every Tracya flow at once, both first-visit and once-per-session records.

Tracya.resetAll();

This is mostly useful in testing, when you want to see your flows fire from a clean slate without clearing your whole browser storage by hand. It does not reset the visitor's first-encounter date, so New users only windows are unaffected.

How flow IDs are found

Every method except init and resetAll takes a flow ID. You find it in the dashboard, on the Flows tab: each flow has a Copy ID button next to it. It is the same ID the flow keeps for its whole life, so a "Replay" button wired to it keeps working across edits and republishes.