Event response in Tracardi refers to the data that is sent back from the server after processing an event. This response typically includes information about the current profile ID and may also contain additional data based on the configurations and logic defined within workflows.
Structure of Event Response
Event responses in Tracardi are structured in JSON format and contain various keys and values. The response typically includes information related to different aspects of the workflow, such as saved events, errors, IDs, and types. For example, in the provided example response:
The above response includes information about segments, profile ID, etc.
Tracardi provides you with the flexibility to configure response data within each event type workflow. This means that
you can define what data should be included in the response generated by a specific workflow, which is bound to a
defined event type and its properties. The response data can be structured and organized using response keys, such as
segments, which are defined fields that contain the data returned by a workflow and can be copied from a profile, for
By configuring response data in your event type workflows, you can specify the data that should be included in the response generated by that particular workflow. This allows you to return and data captured and processed in Tracardi based on your specific requirements and business needs. You can define the response keys that should be included in the response, which can be used in downstream processes for further analysis, actions, and decision-making (e.g. content personalisation).
Capturing Tracker Response
Tracardi allows you to capture the event response, which can be useful for customizing page content based on customer segments or utilizing data returned from workflows. In the provided example, the event response is captured using the window.onTracardiReady event and accessed through the context.response object. For example:
In the above example, the context.response.custom.text value is accessed from the response and used to update the content of an HTML element with the id attribute of 'custom'. This allows you to dynamically change the page content based on the data returned from Tracardi workflows.
Binding Page Elements
You can also bind events to page elements. To do that you will need to be sure that the page loads and every element of the page is accessible.
To do that bind the function to
The whole configuration should look like this.
The above example will run on every page after the events are triggered. It will not run if TRACARDI did not respond.
The function have the following parameters.
- helpers - this is a reference to class that will allow you to raise another events
- context has the response from Tracardi to you initial events. It will have profile data, and if configured debug information.
- config - it is the tracker config as defined in options
- tracker - it is tracker object.
OnTracardiReady triggered on selected page
You can bind functions to
windows.OnTracardiReady on selected pages together with track events. Then it will be
executed only on selected pages.
- Set tracks first. Then bind a function.
Binding events to page elements
Then you can write a code that binds for example onClick event on a button to tracardi event.
This is the example code that you can bind to
It looks for the element with id="button"
Then using helpers binds onClick on that element to function:
Inside the function we send the event to Tracardi:
And on response we make a string from JSON response and bind it as innerText of element with id='response-to-custom-event'
The whole configuration looks like this:
You probably noticed that we use helpers to bind events. We used onClick method to bind to click event. You might need to bind to other than click event. To do that use addEventListener:
Helpers also have track method that let you send custom event to Tracardi at any time.
This is how you can use it: